1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
const int numberOfstudents = 8;
const int numberOfgrades = 3;
double total;
double average;
string name[numberOfstudents] = {"Isabel", "Steve", "Michael",
"James", "Jennifer", "Billy",
"Brenda", "Jesus"};
double grades[numberOfstudents][numberOfgrades] = {{92,95,94},
{99,76,68},
{89,70,85},
{80,75,71},
{78,77,93},
{93,91,89},
{82,95,71},
{98,82,84}};
cout << "Student Name Grade\n";
cout << "------------" << setw(14) << "-------\n";
for (int student = 0; student < numberOfstudents; student ++)
{
total = 0;
for (int col = 0; col < numberOfgrades; col++)
total += grades[student][col];
average = total / numberOfgrades;
cout << setw(9) << left << name[student];
cout << setw(14) << right << average << endl;
}
double highest = grades[numberOfstudents][numberOfgrades];
for(int i = 0; i < numberOfstudents; i++)
{
for(int j = 0; j < numberOfgrades; j++)
{
if(grades[i][j] > highest)
{
highest = grades[i][j];
}
}
}
cout << "The student with the highest average is" << (need help getting the name here)
<< "and the average is" << highest << endl;
return 0;
}
|