#include <iostream>
#include <iomanip>
using namespace std;
const int NAME_SIZE = 25;
struct Student
{
char name[NAME_SIZE];
int idNum;
int *tests;
double average;
char grade;
};
void getData(Student *, int, int);
void getAverage(Student *, int, int);
void assignGrade(Student *, int);
void displayData(Student *, int, int);
int main()
{
int people,
numTests;
Student *students;
cout << "This program will gather names, ID numbers, and test scores, of students\n"
<< "and display the averages and grades of those students in\n"
<< "a handy table\n\n";
do{
cout << "How many students are there?(positive values only): ";
cin >> people;
}while (people <= 0);
do{
cout << "How many test scores per student?(positive values only): ";
cin >> numTests;
} while (numTests <= 0);
cout << endl;
students = new Student[people];
for (int i = 0; i < people; i++)
{
students[i].tests = new int[numTests];
}
getData(students, people, numTests);
cout << fixed << setprecision(2);
displayData(students, people, numTests);
delete [] students;
students = 0;
return 0;
}
void getData(Student *s, int people, int numTests)
{
for (int i = 0; i < people; i++)
{
cout << "What is the name of student " << (i + 1) << "?: ";
cin.ignore();
cin.getline(s[i].name, NAME_SIZE);
cout << "What is " << s[i].name << "\'s ID Number? (4 digits)?: ";
cin >> setw(4) >> s[i].idNum;
do{
cout << "What is " << s[i].name << "'s score on test #"
<< (numTests - (numTests - 1)) << "(positive values only): ";
cin >> s[i].tests[0];
}while (s[i].tests[0] < 0);
for (int count = 1; count < numTests; count++)
{
do{
cout << "Test #" << (count + 1) << "? (positive values only): ";
cin >> s[i].tests[count];
}while (s[i].tests[count] < 0);
}
}
}
void displayData(Student *s, int people, int numTests)
{
for (int i = 0; i < people; i++)
{
cout << endl;
cout << s[i].name << endl
<< setw(4) << s[i].idNum << endl;
for (int count = 0; count < numTests; count++)
{
cout << s[i].tests[count] << endl;
}
cout << "Average is " << s[i].average << "%\n";
}
}
void getAverage(Student *s, int people, int numTests) //something wrong in here?
{
for (int i = 0; i < people; i++)
{
int total = 0;
for (int count = 0; i < numTests; count++)
{
total += s[i].tests[count];
}
s[i].average = total / numTests;
}
}