#include <iostream>
#include <iomanip>
using namespace std;
const int NUM_TESTS = 4, STU_NUM = 5, STU_LENGTH = 20;
void getNames(char [][STU_LENGTH]);
void getScores(char [][STU_LENGTH], char [], double [][NUM_TESTS]);
void calcAverages(double tests[][NUM_TESTS]);
//void display();
int main()
{
char names[STU_NUM][STU_LENGTH];
double tests[STU_NUM][NUM_TESTS];
char gradeLetter[STU_NUM];
getNames(names);
getScores(names,gradeLetter,tests);
calcAverages(tests);
cout << "\n";
system("PAUSE");
return 0;
}
// Function that will ask for and store names
void getNames(char names[][STU_LENGTH])
{
for(int i=0;i < STU_NUM;i++)
{
cout << "Please enter student " << i+1 << " name : ";
cin.getline(names[i],STU_LENGTH);
}
}
// Function that will ask for and store scores for each student
void getScores(char names[][STU_LENGTH], char gradeLetter[], double tests[][NUM_TESTS])
{
for(int i = 0; i < STU_NUM; i++)
{
for(int j = 0; j < NUM_TESTS; j++)
{
cout << "Please enter " << names[i] << " grades";
cout << (j+1) << ": ";
cin >> tests[i][j];
}
}
}
void calcAverages(double tests[][NUM_TESTS])
{
double averages[STU_NUM];
double tempSum[STU_NUM];
cout << "The test scores are: ";
for(int i=0;i < STU_NUM;i++)
{
for(int j=0;j < NUM_TESTS;j++)
{
tempSum[i] += tests[i][j];
cout << tempSum[i] <<" ";
}
}
cout << "The sums are: ";
for(int p=0;p < STU_NUM;p++)
{
cout << tempSum[p] << " ";
}
}