Write a program that reads students\' names followed by their test scores. The p
ID: 3856552 • Letter: W
Question
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. 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 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. PLEASE C++ ONLYExplanation / Answer
#include <iostream>
using namespace std;
struct student
{
int score;
char grade;
char fname[15],lname[15];
};
char gradecal(int s)
{
char s1;
if((s>=100)&&(s<90))
{
s1='A';
}
else if((s<=90)&&(s>80))
{
s1='B';
}
else if((s<=80)&&(s>70))
{
s1='C';
}
else if((s<=70)&&(s>60))
{
s1='D';
}
else if((s<=60)&&s>50)
{
s1='E';
}
else if(s<=50)
{
s1='F';
}
return s1;
}
int main() {
student s[50];
int i,max=0,n;
cout<<"Enter the number of Student in the Class";
cin>>n;
for(i=0;i<n;i++)
{
cout<<" Enter the Firstname:";
cin>>s[i].fname;
cout<<" Enter the Lastname:";
cin>>s[i].lname;
cout<<" Enter the Test Score";
cin>>s[i].score;
if(max<s[i].score)
{
max=s[i].score;
}
s[i].grade=gradecal(s[i].score);
}
for(i=0;i<n;i++)
{
cout<<" ";
cout<<s[i].lname<<", "<<s[i].fname;
cout<<" ";
cout<<s[i].score;
cout<<" ";
cout<<s[i].grade;
cout<<" ";
}
cout<<"Highestscore:"<<max;
// your code goes here
return 0;
}
output:
Enter the number of Student in the Class
Enter the Firstname:John
Enter the Lastname:David
Enter the Test Score60
Enter the Firstname:Sheela
Enter the Lastname:Kiran
Enter the Test Score:80
David, John
60
E
Kiran, Sheela
80
C
Highestscore:80
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.