#include //for the objects cin and cout #include //for the macro EXIT_SUCCESS; #include "grade.h" //for class grade using namespace std; //You can make this program more robust by having it catch the exceptions that //might be thrown by the constructor and operator+= of class date. int main() { const grade lowest {"F"}; //the lowest possible grade const grade highest {"A"}; //the highest possible grade //Loop through all possible grades. for (grade g {lowest}; g <= highest; ++g) { cout << g << "\n"; } const int distance = highest - lowest; cout << "There are " << distance + 1 << " possible grades.\n"; cout << "The one in the middle is " << lowest + distance/2 << ".\n"; const grade a[] { {"C"}, //Call constructor to construct a grade object. {"B+"}, {"B"}, {"B-"}, {"A"} }; const int n {size(a)}; //the number of elements in the array int sum {0}; for (int i {0}; i < n; ++i) { sum += a[i]; //sum += a[i].operator int(); } //const int sum {accumulate(a, a+n, 0)}; //#include cout << "The average grade was " << lowest + sum/n << ".\n"; cout << "Please type a grade and press RETURN.\n"; grade g; cin >> g; if (!cin) { cerr << "Unable to read the grade.\n"; return EXIT_FAILURE; } cout << "The grade you typed was " << g << ".\n"; return EXIT_SUCCESS; }