//#include #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. } } /* const string *const p {find(a, a + n, s)}; if (p != a + n) { i = p - a; //All done. We found what we were looking for. return; } */ //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; } istream& operator>>(istream& ist, grade& g) { string s; ist >> s; if (!ist) { return ist; //Could not input any characters. } for (int i {0}; i < grade::n; ++i) { if (s == grade::a[i]) { g.i = i; //We found what we were looking for. return ist; } } //Hope we never arrive here. //We were able to input characters, but they were the wrong characters. ist.setstate(ios_base::failbit); return ist; }