Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

#include<iostream> #include<fstream> #include<iomanip> using namespace std; int

ID: 3642365 • Letter: #

Question

#include<iostream>
#include<fstream>
#include<iomanip>

using namespace std;

int const SIZE = 15;

struct studentType
{
string studentFname;
string studentLname;
int testScore;
char grade;
};

//prototypes
void readData(studentType students[], unsigned int &numStudents);
void printData(studentType students[], unsigned int numStudents, int highest);
void assignGrade(studentType students[], unsigned int numStudents);
void findHighest(studentType students[], unsigned int numStudents, int &highest);
void printHighStudents(studentType students[], unsigned int numStudents, int highest);

int main()
{
int highest;
studentType students[SIZE];
unsigned int numStudents;

readData(students, numStudents);
assignGrade(students, numStudents);
findHighest(students, numStudents, highest);
printData(students, numStudents, highest);
printHighStudents(students, numStudents, highest);

system("pause");
return 0;
}

//This function reads the data
void readData(studentType students[], unsigned int &numStudents)
{
ifstream infile;

infile.open("students.txt");

numStudents = 0;

while (!infile.eof())
{
infile >> students[numStudents].studentFname >>
students[numStudents].studentLname >>
students[numStudents].testScore;
cout << students[numStudents].studentFname << endl;
numStudents++;
}

cout << endl;

return;
}

//This function prints the data
void printData(studentType students[], unsigned int numStudents, int highest)
{
cout << fixed << showpoint << setprecision(2);

for (unsigned int t = 0; t < numStudents; t++)
{
cout.setf(ios::left); //align left
cout << setw(12) << students[t].studentFname <<
setw(12) << students[t].studentLname <<
setw(10) << students[t].testScore <<
setw(10) << students[t].grade << endl;
}

cout << endl << "Highest score = " << highest << endl;

return;
}

//This function assigns a letter grade to each student
void assignGrade(studentType students[], unsigned int numStudents)
{
for (int i = 0; i < numStudents; i++)
{
if (students[i].testScore >= 90)
students[i].grade = 'A';
else
if (students[i].testScore >= 80)
students[i].grade = 'B';
else
if (students[i].testScore >= 70)
students[i].grade = 'C';
else
if (students[i].testScore >= 60)
students[i].grade = 'D';
else
students[i].grade = 'F';
}

return;
}

//This function finds the highest test score
void findHighest(studentType students[], unsigned int numStudents, int &highest)
{
highest = students[0].testScore;

for (int i = 1; i < numStudents; i++)
if (students[i].testScore > highest)
highest = students[i].testScore;

return;
}

//This function prints students with the highest test score
void printHighStudents(studentType students[], unsigned int numStudents, int highest)
{
cout << endl << "Students with the highest test scores: " << endl;

for (int i = 0; i < numStudents; i++)
if (students[i].testScore == highest)
cout << students[i].studentFname << " " << students[i].studentLname << endl;

return;
}

Explanation / Answer

I gave you the previous answer. You need to change students[i].testScore = total_scores; to students[i].testScore += total_scores;