78.3k views
4 votes
Write a program that reads students’ names followed by their test scores. 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. Student data should be stored in a struct variable of type studentType, which has four components: studentFName and studentLName of type string, testScore of type int (testScore is between 0 and 100), and grade of type char. Suppose that the class has 20 students. Use an array of 20 components of type studentType. Your program must contain at least the following functions: A function to read the students’ data into the array. A function to assign the relevant grade to each student. A function to find the highest test score. A function to print the names of the students having the highest test score. Your program must output each student’s name in this form: last name followed by a comma, followed by a space, followed by the first name; the name must be left justified. Moreover, other than declaring the variables and opening the input and output files, the function main should only be a collection of function calls.

User Durkee
by
5.5k points

1 Answer

3 votes

Answer:

See explaination

Step-by-step explanation:

#include <iostream>

#include <iomanip>

#include <fstream>

#include <string>

using namespace std;

void readStudentsData();

void levels(int&,int&,int&);

int main()

{

string studentsName[50];

int grade[50];

int highestScore = 0;

int belowAverage = 50;

int countStudents = 0;

int sum = 0;

int score[5]=

double average = 0;

ifstream infile;

ofstream outfile;

void readStudentsData();

infile.open("c:\\Data.txt");

int numOfStudents = 0;

infile >> studentsName[numOfStudents] >> grade[numOfStudents];

While (infile && numOfstudents < 50)

{

numOfStudents++;

infile >> studentsName[numOfStudents] >> grade[numOfStudents};

}

if (!infile)

{

cout << "File does not open." << endl;

return 1;

}

outfile.open("c:\\average.out");

outfile << fixed << showpoint;

outfile << setprecision(2);

infile >> studentsName;

infile >> score1 >> score2 >> score3 >> score4 >> score5 >>;

outfile << left << setw(20) << "Students Name"

<< setw(5) << "Score 1" << setw(5) << "Score 2"

<< setw(5) << "Score 3" << setw(5) << "Score 4"

<< setw(5) << "Score 5" << setw(5) << "Grade"

<< setw(5) << "Average" << setw(5) << "Below average"

<< setw(5) << "Highest" << endl;

if (average >= 90)

cout << "A" << endl;

else if (average >= 80)

cout << "B" << endl;

else if (average >= 70)

cout << "C" << endl;

else if (average >= 60)

cout << "D" << endl;

else

cout << "F" << endl;

}

average = static_cast<double>(score1+score2+score3+score4+score5) /5;

void level(int &highestScore,int &belowAverage,int &sum);

{

int level,high = 0,low = 17;

infile >> level;

while(level!=-1)

{

sum = sum + level;

if (level > high)

{

high = level;

infile >> level;

}

else

if (level < low)

{

low = level;

infile >> level;

}

else

if infile >> level;

}

outfile << ' ' << high;

else

if (high > highestScore)

highestScore=high;

else

if (low < belowAverage)

belowAverage=low;

}

do

{

cout << "Students Name: ";

cin >> name

cout << "Input score: " << endl;

cin >> score1>> score2>> score3>> score4>> score5;

cout << Students Name << Highest score);

}

While (highest score !=0);

infile.close();

outfile.close();

return 0;

}

User Anuja Joshi
by
5.9k points