Please send questions to st10@humboldt.edu .

/*-------------------------------------------------- File: maxGrade.cpp Name: Sharon M. Tuttle last modified: 5-3-05 Contract: maxGrade : double[] int -> double Purpose: return the largest grade amongst the first size grades in array grades. (return 0 if size is 0 or less!) Examples: for double grades[10] = {76.5, 88.0, 99.6, 66, 43.0, 93.2, 73.0, 72.0, 74.0, 95}; maxGrade(grades, 10) == 99.6 --------------------------------------------------*/ #include <iostream> #include <cmath> using namespace std; double maxGrade(const double grades[], int size) { double maxGradeSoFar; // for array size of 0 or less, just stop now! if (size == 0) { return 0.0; } // IF reach here, then, there ARE some grades to // check; // first is largest seen so far... maxGradeSoFar = grades[0]; // ...now compare the REST in grades, to see if // any other is larger: for (int i=1; i < size; i++) { if (grades[i] > maxGradeSoFar) { maxGradeSoFar = grades[i]; } } return maxGradeSoFar; }