Write a program that reads students names followed by their test scores. The pro
ID: 3697036 • Letter: W
Question
Write a program that reads students names followed by their test scores. The program should output each students’ 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 the 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. A function to read the students data into the array.
b. A function to assign the relevant grade to each student.
c. A function to find the highest test score.
d. A function to print the name of the students having the highest test score
Your program must output each students name in the form: last name followed by the 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.
20 students
Marcos Cavazos 89
Marina Flores 93
Mia Garica 90
Brandon Garza 98
Nehemiah Hayden 84
Nathaniel King 87
Emmannel Guevara 78
Julian Rodriguez 90
Danica Ianna 95
David Garcia 91
Daniel Quintin 88
Jeremiah Jude 70
Kingston Sir 73
Krystal Loya 93
Elijah Dominque 72
Hakeem Hayden 93
Jenny Espinoza 91
Vianca Jimenez 75
Claudia Rodriguez 79
German Rodriguez 80
Explanation / Answer
Hi I have written code. Please test it.
#include<iostream>
#include<cstdlib>
using namespace std;
struct studentType{
string studentFName ;
string studentLName;
double testScore;
char grade;
};
void readData(studentType students[], int size);
double higestScore(studentType students[], int size);
void higestScoreName(studentType students[], int size);
void assignGrade(studentType students[], int size);
int main(){
// declaring Student array of size 20
studentType students[20];
// assigning id and numbers for each student
readData(students, 20);
//assigning grade to each student
assignGrade(students, 20);
//printing is, score and grade of each student
for(int i=0; i<20; i++){
cout<<students[i].studentLName<<", "<<students[i].studentFName<<"Score: "
<<students[i].testScore<<", Grade: "<<students[i].grade<<endl;
}
return 0;
}
void assignGrade(studentType students[], int size){
for(int index=0; index<size; index++){
double score = students[index].testScore;
if(score >= 90){
students[index].grade = 'A';
}
else if(score >= 80){
students[index].grade = 'B';
}
else if(score >= 70){
students[index].grade = 'C';
}
else if(score >= 60){
students[index].grade = 'D';
}
else{
students[index].grade = 'F';
}
}
}
void readData(studentType students[], int size){
for(int i=0; i<size; i++){
cout<<"Enter first name, last and score of "<<(i+1)<<" student ";
cin>>students[i].studentFName;
cin>>students[i].studentLName;
cin>>students[i].testScore;
}
}
double higestScore(studentType students[], int size){
double max = students[0].testScore;
for(int i=1; i<size; i++){
if(max < students[i].testScore)
max = students[i].testScore;
}
return max;
}
void higestScoreName(studentType students[], int size){
double max = higestScore(students, size);
cout<<" Higest Score: "<<max<<endl;
cout<<" Name of student with higest score: "<<endl;
for(int i=0; i<size; i++){
if(students[i].testScore == max)
cout<<students[i].studentLName<<", "<<students[i].studentFName<<endl;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.