Hi ya all,
I've got a HW and I'm so stuck.
Okay, so here's what my prof wants us to do, "Write a program that prompts to read students' names followed by their test scores (1 test score for every student). The program should output to the screen, the student's name followed by the test score, and the relevant grade. At the end, it should also find and print the highest test score and the name of the student with the highest test score, the lowest test score and the name of the student with the lowest test score, and the average of the test scores."
for example,
John Smith 75 C
Sue Jones 90 A
Ray Adams 85 B
I should use a struct variable type as well as an array of structs. The input data should be read either from a file or from a user. Also I need to use at least 2 functions and pass by array to the functions as parameters.
const int maxStudents = 5;
int loadData(istream& input, StudentType students[], int maxStudents);
int findHighest(StudentType students[], int nStudents);
int findLowest(StudentType students[], int nStudents);
char letGrades(char grade);
void calGrades(StudentType students[], int nStudents);
void topScores(int highestScore, StudentType students[], int nStudents);
int main()
{
int numOfStudents = 0;
ifstream inFile;
cout << "Enter the student's first name, last name, and test score. " << endl;
inFile.open("studentTestScores.txt");
if (!inFile)
{
cout << "Cannot open the input file." << endl;
cout << "Program terminated." << endl;
system("pause");
return 0;
}
else if (numOfStudents >= 5)
{
cout << "Sorry, you can't put any more students." << endl;
}
else if (inFile)
{
//I need to call all the functions as well as the struct type.
}
}
int loadData(StudentType students[])
{
int student = 0;
ifstream inputFile;
while (!inputFile.eof() && student < maxStudents)
{
// What should I put here?
}
return student;
}
void calGrades(StudentType students[], const int nStudents)
{
int i;
for (i = 0; i < nStudents; i++)
{
students[i].grade = letGrades(students[i].testScore);
}
}
int findHighest(StudentType students[], const int nStudents)
{
int i;
for (i = 0; i < nStudents; i++)
{
students[i].grade = letGrades(students[i].testScore);
}
return i;
}
void topScores(int highestScore, StudentType students[], const int nStudents)
{
int i;
cout << highestScore << letGrades << " is the highest score within a group of " << nStudents << " students." << endl;
for (i = 0; i < nStudents; i++)
{
if (students[i].testScore == highestScore)
{
cout << students[i].studentLName << ", " << students[i].studentFName << endl;
}
}
}