#include //for classes invalid_argument and range_error #include "grade.h" using namespace std; const string grade::a[] { "F", // 0 "F+", // 1 "D-", // 2 "D", // 3 "D+", // 4 "C-", // 5 "C", // 6 "C+", // 7 "B-", // 8 "B", // 9 "B+", //10 "A-", //11 "A", //12 "A+" //13 }; //Extra credit: instead of writing the for loop and the if statement in the //constructor, can you figure out how to call the standard library function //"find" instead? Hint: you will have to #include . grade::grade(const string& s) { //Let the data member i be the index of the string s in the array a. for (i = 0; i < n; ++i) { if (s == a[i]) { return; //All done. We found what we were looking for. } } //Hope we never arrive here. throw invalid_argument("Bad argument \"" + s + "\" for constructor"); } grade& grade::operator+=(int inc) { const int sum {i + inc}; if (sum < 0 || sum >= n) { throw range_error("grade out of range"); } i = sum; return *this; } //operator<< has to call the array a by its full name grade::a, because //operator<< is not a member function of class grade. Note that the constructor //did not have to call the array by its full name, because the constructor is a //member function of class grade. //operator<< is small enough to be inline, if you want to do that. ostream& operator<<(ostream& ost, const grade& g) { return ost << grade::a[g.i]; }