/**************************************************/ /* */ /* This program will calculate a student's test */ /* average for three test scores. It will do */ /* this for students until there are no more */ /* students to enter. */ /* */ /**************************************************/ #include #include #include #define NUMTESTS 3 using namespace std; /**************************/ /* Function Prototypes */ /**************************/ // Get the student's SSN string getSSN(); // Get each test score float getTestScore(); // Calculate the average of the three test scores float calcAvg(float score1, float score2, float score3); // Print student's SSN and test average void printStuInfo(string ssn, float testAvg); int main() { float test1, test2, test3; float avg; string ssn; ssn = getSSN(); while (ssn != "0") { test1 = getTestScore(); test2 = getTestScore(); test3 = getTestScore(); avg = calcAvg(test1, test2, test3); printStuInfo(ssn, avg); ssn = getSSN(); } return 0; } // end main string getSSN() { string socialNum; cout << "Enter student's SSN (0 to end program): "; cin >> socialNum; return socialNum; } // end function getSSN float getTestScore() { float score; cout << "Enter a test score for a student: "; cin >> score; return score; } // end function getTestScore float calcAvg(float score1, float score2, float score3) { float sum; float ave; sum = score1 + score2 + score3; ave = sum / NUMTESTS; return ave; } // end function calcAvg void printStuInfo(string ssn, float testAvg) { cout << fixed << showpoint << setprecision(2); cout << endl << endl; cout << "Test average for " << ssn << " is " << testAvg << endl << endl; return; } // end function printStuInfo