#include #include #include #include using namespace std; /* Name: Cameron Alston Section: CISP 400 - Wei Title: Test Score Calculator w/ Vectors!! SCR: 9/10/07 Began Coding Alston 9/20/07 Added vector functions Alston 9/21/07 Fixed sort and reverse Alston */ #define TRUE 1 #define FALSE 0 #define MAX 9 #define REPORTHEADING "\n\nTest Scores\n-----------" #define AVERAGEHEADING "\nAverage Score\n-------------" void EnterScores(int &numTests, vector &testScores, int count); float AverageScores(vector &testScores, int numTests, int count); void ShowScores(vector &testScores, int numTests, float averageScore, int count); int main() { int numTests = 0, count = 0, pause = 0; vector testScores; float averageScore = 0; EnterScores(numTests, testScores, count); sort(testScores.begin(), testScores.end()); reverse(testScores.begin(), testScores.end()); averageScore = AverageScores(testScores, numTests, count); ShowScores(testScores, numTests, averageScore, count); cin >> pause; return 0; } void EnterScores(int &numTests, vector &testScores, int count) { int tempTest = 0; cout << "How many test scores are there? "; cin >> numTests; while(numTests >= MAX + 1 || numTests < 1) { cout << endl << "Bad input..." << endl; cout << "How many test scores are there? "; cin >> numTests; } for(count = 0; count < numTests; count++) { cout << endl << "Enter the score for test #" << count + 1 << " "; cin >> tempTest; testScores.push_back(tempTest); if(testScores[count] < 0) { cout << endl << "That's an invalid score..." << endl; cout << endl << "Enter the score for test #" << count + 1 << " "; cin >> tempTest; testScores.push_back(tempTest); } fflush(stdin); } } float AverageScores(vector &testScores, int numTests, int count) { int totalScores = 0; float averageScore = 0; totalScores = accumulate(testScores.begin(), testScores.end(), 0); averageScore = (float)totalScores / (float)numTests; return averageScore; } void ShowScores(vector &testScores, int numTests, float averageScore, int count) { cout << REPORTHEADING << endl; for(count = 0; count < numTests; count++) { cout << testScores[count] << endl; } cout << endl << AVERAGEHEADING << endl << averageScore; }