In: Computer Science
Write a program that uses the defined structure and all the above functions. Suppose that the class has 20 students. Use an array of 20 components of type studentType. Other than declaring the variables and opening the input and output files, the function main should only be a collection of function calls. The program should output each student’s name followed by the test scores and the relevant grade. It should also find and print the highest test score and the name of the students having the highest test score.
Note: Could you plz go through this code and let me
know if u need any changes in this.Thank You
_________________
// Ch9_Ex2Data.txt
Duckey Donald 85
Goof Goofy 89
Brave Balto 93
Snow Smitn 93
Alice Wonderful 89
Samina Akthar 85
Simba Green 95
Donald Egger 90
Brown Deer 86
Johny Jackson 95
Greg Gupta 75
Samuel Happy 80
Danny Arora 80
Sleepy June 70
Amy Cheng 83
Shelly Malik 95
Chelsea Tomek 95
Angela Clodfelter 95
Allison Nields 95
Lance Norman 88
_______________________________
#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>
using namespace std;
const int NO_OR_STUDENTS = 20;
// declare studentType struct
struct studentType
{
// variables
string studentFName;
string studentLName;
int testScore;
char grade;
};
// part a
inline void getData(ifstream& inFile, studentType sList[], int
listSize)
{
// function code
string fname, lname;
int score;
int i = 0;
// Reading data from file
while (i < listSize)
{
inFile >> fname >> lname >> score;
sList[i].studentFName = fname;
sList[i].studentLName = lname;
sList[i].testScore = score;
i++;
}
inFile.close();
}
// part b
inline void calculateGrade(studentType sList[], int listSize)
{
// function code
for (int i = 0; i < listSize; i++)
{
if (sList[i].testScore >= 90)
sList[i].grade = 'A';
else if (sList[i].testScore >= 80 && sList[i].testScore
< 90)
sList[i].grade = 'B';
else if (sList[i].testScore >= 70 && sList[i].testScore
< 80)
sList[i].grade = 'C';
else if (sList[i].testScore >= 60 && sList[i].testScore
< 70)
sList[i].grade = 'D';
else if (sList[i].testScore < 60)
sList[i].grade = 'F';
}
}
// part c
inline int highestScore(const studentType sList[], int
listSize)
{
// function code
int max = sList[0].testScore;
for (int i = 0; i < listSize; i++)
{
if (max < sList[i].testScore)
{
max = sList[i].testScore;
}
}
return max;
}
// part d
inline void printResult(ofstream& outFile, const studentType
sList[], int listSize)
{
// function code
for (int i = 0; i < listSize; i++)
{
outFile << sList[i].studentLName << ", " <<
sList[i].studentFName << " "
<< sList[i].testScore << " " << sList[i].grade
<< endl;
}
int max = highestScore(sList, listSize);
outFile<<"\nThe Highest Test Score
:"<<max<<endl;
outFile<<"\nStudents Who got highest
score:"<<endl;
// Writing data to the output file
for (int i = 0; i < listSize; i++)
{
if (max == sList[i].testScore)
outFile << sList[i].studentLName << ", " <<
sList[i].studentFName << " "
<< sList[i].testScore << " " << sList[i].grade
<< endl;
}
}
int main()
{
ifstream inData;
ofstream outData;
studentType studentList[NO_OR_STUDENTS];
inData.open("Ch9_Ex2Data.txt");
if (!inData)
{
cout << "The input file does not exist. Program
terminates!"
<< endl;
return 1;
}
outData.open("out.txt");
if (!outData)
{
cout << "Cannot open the output file. Program
terminates!"
<< endl;
return 1;
}
getData(inData,studentList,NO_OR_STUDENTS);
// call calculateGrade
calculateGrade(studentList,NO_OR_STUDENTS);
// call printResult
printResult(outData,studentList,NO_OR_STUDENTS);
return 0;
}
_________________________
Output:
_______________Could you plz rate me well.Thank You