#include using namespace std; void computeMaxAndMin(double data[], int size, double & max, double & min); void computeAverage(double data[], int size, double & average); void computeMaxAndMin(double data[], int size, double & max, double & min) { int index; max = data[0]; min = data[0]; for (index = 1; index < size; index = index + 1) { if (data[index] > max) max = data[index]; else if (data[index] < min) min = data[index]; } } void computeAverage(double data[], int size, double & average) { int index; double sum; for (index = 0; index < size; index = index + 1) { sum = sum + data[index]; } average = sum / size; } int main(int argc, char* argv[]) { const int CAPACITY = 1000; double testGrades[CAPACITY]; int size; int index; double grade; double testMaxScore, testMinScore; double testAverageScore; cout << "Test Grade Analysis Program" << endl; cout << "Please enter the test grades, separated by spaces (maximum of " << CAPACITY << " can be entered). " << endl; cout << "Enter a value less than 0 to quit" << endl; // a value less than 0 is a SENTINEL (tells you when to quit, is not a legal value for grades) size = 0; cin >> grade; while ((grade > 0) && (size < CAPACITY)) { testGrades[size] = grade; size = size + 1; // you may have just filled up the array; if so, get out; if not, read the next grade if (size < CAPACITY) cin >> grade; } // at this point, the grade last entered was < 0 and was not written into the array // every time anything was actually written into the array, the size was incremented, so size is correct // pass size, not CAPACITY, to array functions // a size of 0 is possible, so handle those (averages, min, max undefined in such as case) if (size > 0) { computeMaxAndMin(testGrades, size, testMaxScore, testMinScore); cout << "Max grade was " << testMaxScore << " and min grade was " << testMinScore << endl; computeAverage(testGrades, size, testAverageScore); cout << "Average was: " << testAverageScore << endl; } else cout << "No scores were entered, so no max, min, or average score could be computed." << endl; }