1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
|
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iterator>
#include <iomanip>
using namespace std;
/* -------------------------------------------------------- */
/* ---------------------- Grading Class ------------------- */
/* -------------------------------------------------------- */
class Grading
{
public:
string name;
int percentage;
virtual ~Grading() {}
virtual void* get_raw_score(){return 0;}
void* get_adj_score(){return 0;}
};
/* -------------------------------------------------------- */
/* ---------------------- Assignment Class ---------------- */
/* -------------------------------------------------------- */
class Assignment : public Grading
{
protected:
int score;
virtual void* get_raw_score() {return &score;}
};
/* -------------------------------------------------------- */
/* ---------------------- Exam Class ---------------------- */
/* -------------------------------------------------------- */
class Exam : public Grading
{
public:
int score;
Exam(string n, int g, int s) {
name = n;
percentage = g;
score = s;
}
virtual void* get_raw_score() {return &score;} // is implicitly virtual
};
/* -------------------------------------------------------- */
/* ------------------- Project Class ---------------------- */
/* -------------------------------------------------------- */
class Project : public Assignment
{
public:
string letter_grade;
Project(string n, int g, string l_g) {
name = n;
percentage = g;
letter_grade = l_g;
}
virtual void* get_raw_score(){return &letter_grade;}
};
/* -------------------------------------------------------- */
/* ---------------------- Quiz Class ---------------------- */
/* -------------------------------------------------------- */
class Quiz : public Grading
{
public:
string letter_grade;
Quiz(string n, int g, string l_g)
{
name = n;
percentage = g;
letter_grade = l_g;
}
virtual void* get_raw_score(){return &letter_grade;}
};
/* -------------------------------------------------------- */
/* ---------------------- CourseWork class ---------------- */
/* -------------------------------------------------------- */
class CourseWork {
public:
CourseWork() {}
void push_back( Grading* a )
{
work.push_back(a);
}
// print the data and sort by name
void sort_name() {}
void sort_score() {}
friend ostream& operator<<(ostream& os, const CourseWork dt) {
os << dt.work.at(0)->name << dt.work.at(0)->percentage << dt.work.at(0)->get_raw_score() << endl;
return os;
}
private:
vector<Grading*> work;
};
/* -------------------------------------------------------- */
/* ---------------------- MAIN ---------------------------- */
/* -------------------------------------------------------- */
int main () {
CourseWork c;
c.push_back(new Quiz("Quiz", 5, "B-"));
c.push_back(new Quiz("Quiz", 5, "C+"));
c.push_back(new Quiz("Quiz", 5, "A"));
c.push_back(new Exam("Midterm", 10, 50));
c.push_back(new Exam("Final", 30, 85.5));
c.push_back(new Project("Project", 5, "A-"));
c.push_back(new Project("Project", 15, "B-"));
c.push_back(new Project("Project", 15, "B-"));
c.push_back(new Project("Demo", 10, "C"));
cout << "** Showing populated data..." << endl;
cout << c << endl << endl;;
c.sort_name();
cout << "** Showing sorted by name..." << endl;
cout << c << endl << endl;
c.sort_score();
cout << "** Showing sorted by score..." << endl;
cout << c << endl;
return 0;
}
|