17.5k views
2 votes
Write a C++ program that reads students' names followed by their test scores. The program should output each students' name followed by the test scores and 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 stores 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 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.

1 Answer

4 votes

Answer:

#include<iostream>

#include<conio.h>

using namespace std;

struct studentdata{

char Fname[50];

char Lname[50];

int marks;

char grade;

};

main()

{

studentdata s[20];

for (int i=0; i<20;i++)

{

cout<<"\\enter the First name of student";

cin>>s[i].Fname;

cout<<"\\enter the Last name of student";

cin>>s[i].Lname;

cout<<"\\enter the marks of student";

cin>>s[i].marks;

}

for (int j=0;j<20;j++)

{

if (s[j].marks>90)

{

s[j].grade ='A';

}

else if (s[j].marks>75 && s[j].marks<90)

{

s[j].grade ='B';

}

else if (s[j].marks>60 && s[j].marks<75)

{

s[j].grade ='C';

}

else

{

s[j].grade ='F';

}

}

int highest=0;

int z=0;

for (int k=0;k<20; k++)

{

if (highest<s[k].marks)

{

highest = s[k].marks;

z=k;

}

}

cout<<"\\Students having highest marks"<<endl;

cout<<"Student Name"<< s[z].Fname<<s[z].Lname<<endl;

cout<<"Marks"<<s[z].marks<<endl;

cout<<"Grade"<<s[z].grade;

getch();

}

Step-by-step explanation:

This program is used to enter the information of 20 students that includes, their first name, last name and marks obtained out of 100.

The program will compute the grades of the students that may be A,B, C, and F. If marks are greater than 90, grade is A, If marks are greater than 75 and less than 90, grade is B. For Mark from 60 to 75 the grade is C and below 60 grade is F.

The program will further found the highest marks and than display the First name, last name, marks and grade of student who have highest marks.

User Hgcummings
by
5.1k points