// Chris Alvin // CS110 // Program 1 // The program simulates a simple grading program. // Limitations: integer input expected. #include #include // function to print the menu void printMenu() { cout << "Please select the operation which you would like to perform?" << endl; cout << "1) Enter scores." << endl; cout << "2) Query the current average." << endl; cout << "3) Query the current high score." << endl; cout << "4) Query the current low score." << endl; cout << "5) Clear all data." << endl; cout << "6) Exit." << endl; return; } float average(unsigned int t, unsigned int c) { return (float)(t) / c; } void printAverage(unsigned int t, unsigned int c) { cout << "The current average is "; if (c == 0) cout << 0 << endl; else if (t % c == 0) cout << (int)(average(t, c)) << endl; else cout << average(t, c) << endl; return; } int main() { cout << setiosflags (ios::showpoint | ios::fixed) << setprecision(2); int choice = 1; // user-input menu int num = 0; // input number int high = -1, low = 101; // init to values out of range unsigned int count = 0; unsigned int total = 0; // 6 is the only value that will quit; all other ints acceptable while (choice != 6) { // call function to print the menu printMenu(); cin >> choice; // switch on menu user input switch (choice) { case 1: cout << "Enter first score." << endl; cin >> num; while (num >= 0 && num <= 100) { if (high < num) high = num; if (low > num) low = num; count++; total += num; cout << "Enter another score (negative number to stop)." << endl; cin >> num; } break; case 2: printAverage(total, count); break; case 3: cout << "The current high score is "; if (high == -1) cout << "UNKNOWN" << endl; else cout << high << endl; break; case 4: cout << "The current low score is "; if (low == 101) cout << "UNKNOWN" << endl; else cout << low << endl; break; case 5: high = -1; low = 101; count = 0; total = 0; cout << "Data cleared." << endl; break; case 6: break; default: cout << "ERROR: invalid entry." << endl; } cout << endl; } return 0; }