// assn2.cpp // This program is intended to read in student grade data and calculate final // grades according to the syllabus for the class. // This implementation uses global variables to keep track of the main // parameters that have to be calculated for the entire class. #include #include // Declare the global variables to accumulate values. int As=0; int Bs=0; int Cs=0; int Ds=0; int Fs=0; double gradeSum=0.0; // Declare the functions I'm going to be using. double min(double n1,double n2); int recursiveRead(); void main() { int numStudents=recursiveRead(); // Do final output. cout << "There were " << numStudents << " students in the class.\n"; if(numStudents>0) { cout << "The average grade was " << gradeSum/numStudents << ".\n"; cout << "There were " << As << " students with As.\n"; cout << "There were " << Bs << " students with Bs.\n"; cout << "There were " << Cs << " students with Cs.\n"; cout << "There were " << Ds << " students with Ds.\n"; cout << "There were " << Fs << " students with Fs.\n"; } else { cout << "With no students there was no average and no grades of any type.\n"; } } double min(double n1,double n2) { return(n1> firstName; if(firstName=="quit") return 0; cin >> lastName; // Variables for storing the assignment grades. double assn1; double assn2; double assn3; double assn4; double assn5; double assn6; double assn7; double assn8; // Variables for storing the quiz grades. double quiz1; double quiz2; double quiz3; double quiz4; double quiz5; double quiz6; // Variables for storing the test grades. double test1; double test2; double classParticip; // Read all the data in. cin >> assn1 >> assn2 >> assn3 >> assn4 >> assn5 >> assn6 >> assn7 >> assn8; cin >> quiz1 >> quiz2 >> quiz3 >> quiz4 >> quiz5 >> quiz6; cin >> test1 >> test2; cin >> classParticip; // Calculate assignment average. double assnAverage=(assn1+assn2+assn3+assn4+assn5+assn6+assn7+assn8)/8.0; // Calculate quiz average. double quizMin=min(quiz1,min(quiz2,min(quiz3,min(quiz4,min(quiz5,quiz6))))); double quizAverage=(quiz1+quiz2+quiz3+quiz4+quiz5+quiz6-quizMin)/5.0; // Calculate test average. double testAverage=(test1+test2)/2.0; // Calculate final average. double finalAverage=0.5*assnAverage+0.3*testAverage+0.1*quizAverage+0.1*classParticip; // Output line for student. cout << firstName << " " << lastName << " " << finalAverage << endl; // Increment the sum of the grades. gradeSum+=finalAverage; // Decide grade type and increment. if(finalAverage>=90.0) { As++; } else if(finalAverage>=80.0) { Bs++; } else if(finalAverage>=70.0) { Cs++; } else if(finalAverage>=60.0) { Ds++; } else { Fs++; } return recursiveRead()+1; }