GradeOutput::GradeOutput (string, const int gradesArray[][tests])
{
for (int student = 0; student < students; student++)
for (int test = 0; test < tests; test++)
grades[students][tests] = gradesArray[students][tests];
}
double GradeOutput::getAverage (const int gradesSet[], const int grades)
{
int total = 0;
for (int grade = 0; grade < grades; grade++)
total += gradesSet[grade];
return static_cast<double>(total)/grades;
}
void GradeOutput::outputGrades()
{
cout << "\nThe grades are:\n\n";
cout << " ";
for (int test = 0; test < tests; ++test)
cout << "Test" << test + 1 << " ";
cout << "Average" << endl;
for (int student = 0; student < students; ++student)
{
cout << "Student" << setw(2) << student + 1;
for (int test = 0; test < tests; ++test)
cout << setw(8) << grades[student][test];
double average = getAverage(grades[student], tests);
cout << setw(9) << setprecision(2) << fixed << average << endl;
}
}
int main()
{
const int students = 10;
string student[students];
const int tests = 3;
int test[tests];
for (int i = 0; i <=9; i++)
{
cout << "Please enter the name of student " << i+1 << ": ";;
cin >> student[i];
for (int j = 0; j <= 2; j++)
{
cout << "Please enter grade " << j+1 << " of this student: ";
cin >> test[j];
}