#ifndef GRADE_H #define GRADE_H #include //for class ostream #include //for class string using namespace std; class grade { int i; //in range 0 to n-1 inclusive; 0 means F, 13 means A static const int n {14}; //the number of possible grades static const string a[n]; //names of the grades: "F", "F+", ..., "A+" public: grade(): i {0} {} //Constructor with no arguments. grade(const string& s); grade& operator+=(int inc); //too big to be inline; see grade.C operator int() const {return i;} friend int operator-(const grade& g1, const grade& g2) { return g1.i - g2.i; } friend bool operator==(const grade& g1, const grade& g2) { return g1.i == g2.i; } friend bool operator<(const grade& g1, const grade& g2) { return g1.i < g2.i; } friend ostream& operator<<(ostream& ost, const grade& g) { return ost << grade::a[g.i]; } friend istream& operator>>(istream& ist, grade& g); }; inline grade& operator-=(grade& g, int i) {return g += -i;} inline grade operator-(grade g, int i) {return g -= i;} inline grade operator+(grade g, int i) {return g += i;} inline grade operator+(int i, grade g) {return g += i;} inline grade& operator++(grade& g) {return g += 1;} //prefix inline grade& operator--(grade& g) {return g -= 1;} //prefix inline const grade operator++(grade g, int) { //postfix const grade old {g}; ++g; return old; } inline const grade operator--(grade g, int) { //postfix const grade old {g}; --g; return old; } inline bool operator<=(const grade& g1, const grade& g2) { return g1 == g2 || g1 < g2; } inline bool operator!=(const grade& g1, const grade& g2) {return !(g1 == g2);} inline bool operator>=(const grade& g1, const grade& g2) {return !(g1 < g2);} inline bool operator> (const grade& g1, const grade& g2) {return !(g1 <= g2);} #endif