C++ Include Comments Write a program that reads students names followed by their
ID: 3674058 • Letter: C
Question
C++
Include Comments
Write a program that reads students names followed by their test scores. The program should output each student's name followed by die 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.Explanation / Answer
Please find the required code below :
#include <iostream>
#include <string>
using namespace std;
struct studentType
{
string studentFName;
string studentLName;
char grade;
int testScore;
};
char getGrade(int score){
char g;
if(score > 80)
g = 'A';
else if(score > 60)
g = 'B';
else if(score > 50)
g = 'C';
else if(score > 40)
g = 'D';
else
g = 'F';
return g;
}
studentType * readData(){
studentType students[20];
for(int i=0; i<2; i++){
struct studentType s;
cout << "Enter student's firstname, lastname, testscore in order :" << endl;
cin >> s.studentFName;
cin >> s.studentLName;
cin >> s.testScore;
s.grade = getGrade(s.testScore);
students[i] = s;
}
return students;
}
studentType findHighestScore(studentType * students){
studentType t ;
int h = 0;
cout << "hi";
for(int i=0; i<2; i++){
studentType s = students[i];
if(s.testScore > h){
h = s.testScore;
t = s;
}
}
return t;
}
void highestScore(studentType s){
cout << "Highest score :" << s.testScore << endl;
}
void highestScoreStudent(studentType s){
cout << "Highest score students name :" << s.studentLName << endl;
}
int main( )
{
studentType * students;/
students = readData();
studentType s = findHighestScore(students);
highestScore(s);
highestScoreStudent(s);
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.