#include <iostream>
usingnamespace std;
// PrintClassGrades.cpp
int main()
{
// prototypes
void printStudentGrade(double average, int studentNumber);
void printClassGrade(double average);
constint NUMBER_OF_GRADES = 2;
constint NUMBER_OF_STUDENTS = 4;
double grade = 0.0;
double studentTotal = 0.0;
double studentAverage = 0.0;
double classTotal = 0.0;
double classAverage = 0.0;
for (int i = 0; i < NUMBER_OF_STUDENTS; i++) // start of outer loop
{
studentTotal = 0; // clear the total for this student
for (int j = 0; j < NUMBER_OF_GRADES; j++) // start of inner loop
{
cout << "Student #"<< (i + 1) << " "
<< "Enter examination score #" << (j + 1) << ": ";
cin >> grade;
// student total
studentTotal = studentTotal + grade;
} // end of the inner for loop
// calculate student average
studentAverage = studentTotal / NUMBER_OF_GRADES;
// print student average
printStudentGrade(studentAverage, (i + 1));
// add student total to class total
classTotal = classTotal + studentTotal;
} // end of the outer for loop
// compute class average
classAverage = classTotal / (NUMBER_OF_STUDENTS * NUMBER_OF_GRADES);
// function call: class average
printClassGrade(classAverage);
cin.get();
return 0;
}
/* Sample Output (from PrintClassGrades.cpp)
Student #1 Enter examination score #1: 77
Student #1 Enter examination score #2: 88
The average for student #1 is 82.5
Student #2 Enter examination score #1: 77
Student #2 Enter examination score #2: 99
The average for student #2 is 88
Student #3 Enter examination score #1: 77
Student #3 Enter examination score #2: 66
The average for student #3 is 71.5
Student #4 Enter examination score #1: 87
Student #4 Enter examination score #2: 86
The average for student #4 is 86.5
The average for class is 82.125
Press any key to continue . . .
*/
//-------------------------------------------------------------------
// Code the following two output functions
//-------------------------------------------------------------------
// Output Function - code the printStudentGrade() function below
// parameters: studentAverage : double
// studentNumber : int
// returns: none
// Output Function - code the printClassGrade() function below
// parameters: classAverage : double
// returns: none
//-------------------------------------------------------------------
The output statement that's already in your main function is an example of combining text output and variable content in one line. Straight text is put between double quotes, the variable name is as is without quotes (e.g. i or j).
I guess my whole issue really is that I dont understand really what it is Im trying to code in the output function like something is frickin not triggering my lightbulb on what it is exactly is steps and detail and clear easy breakdown of how to accomplish this task.../:
printStudentGrade (double studentAverage, int studentNumber)
{
cout << " The average for student # " << studentAverage << endl;
}
Ok this is what I come up for the first function now..is this improvement..?? Anyone..??