#include<iostream> #include<string> #include<fstream> #include<iomanip> using na
ID: 3611344 • Letter: #
Question
#include<iostream>
#include<string>
#include<fstream>
#include<iomanip>
using namespace std;
struct studentType
{ string studentFname;
string studentLname;
int testScore;
char grade;
};
void getData(ifstream & , studentTypesList[], int size);
void calGrade(studentType sList[], intsize);
int highScore (const studentType sList[], intsize);
void printOut(ofstream & , const studentTypesList[],int size, int high);
int main()
{
int size = 20;
int high;
ifstream inData;
ofstream outData;
studentType studentList[20];
inData.open("F:\Ch11_Data.txt");
if (!inData)
{
cout << "~ Check your input file ~"<< endl;
}
outData.open("F:\Ch11_Out.txt");
if (!outData)
{
cout << "~ File does not exist~" <<endl;
}
getData(inData, studentList, 20);
calGrade(studentList, 20);
high = highScore (studentList, size);
printOut(outData, studentList, size,high);
inData.close();
outData.close();
return 0;
}
void getData(ifstream& inFile, studentTypesList[], int size)
{ int x;
for(x=0;x<size;x++)
{
inFile >> sList[x].studentFname
>> sList[x].studentLname
>> sList[x].testScore;
}
}
void calGrade(studentType sList[], intsize)
{
int x;
for(x=0;x<size;x++)
{
if (sList[x].testScore >= 90)
sList[x].grade = 'A';
else if (sList[x].testScore >= 80)
sList[x].grade = 'B';
else if (sList[x].testScore >= 70)
sList[x].grade = 'C';
else if (sList[x].testScore >= 60)
sList[x].grade = 'D';
else if (sList[x].testScore >= 50)
sList[x].grade = 'F';
}
highScore(sList,size);
}
int highScore (const studentType sList[], intsize)
{
int x;
int high= 0;
for(x=0;x<size;x++)
{
sList[x].testScore;
if(sList[x].testScore > high)
high = sList[x].testScore;
}
return high;}
void printOut(ofstream & outFile , conststudentType sList[],int size, int high)
{
int x;
outFile << " Student Name TestScore FinalGrade"
<<"--------------------------------------------------" <<endl;
for(x=0;x<size;x++)
{
outFile << setw(10) <<sList[x].studentFname <<setw(10) <<sList[x].studentLname << setw(10)
<< sList[x].testScore << setw(14)<< sList[x].grade << endl;
}
outFile << "Highest Score of the Class is:" << high << endl;
}
Explanation / Answer
#include #include #include #include using namespace std; class studentType { private: string studentFName; string studentLName; int testScore; char grade; public: void getData ( ifstream &inFile, studentType sList [ ], int size ){ int x; for(x=0;x> sList[x].studentFName >> sList[x].studentLName >> sList[x].testScore; } } void calcGrade ( studentType sList [ ],int size ){ int x; for(x=0;x= 90) sList[x].grade = 'A'; else if (sList[x].testScore >= 80) sList[x].grade = 'B'; else if (sList[x].testScore >= 70) sList[x].grade = 'C'; else if (sList[x].testScore >= 60) sList[x].grade = 'D'; else if (sList[x].testScore >= 50) sList[x].grade = 'F'; } highScore(sList,size); } int highScore ( const studentType sList [], int size ){ int x; int high= 0; for(x=0;x high) high = sList[x].testScore; } return high;} void printOut (ofstream & outFile ,const studentType sList[],int size, int high){ int x; outFileRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.