Write teh progrsm in c Write a program that reads students n

Write teh progrsm in c++

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 student Type, which has four components: student F Name and student L Name of type string, test Score of type int (test Score 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 student Type. 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.

Solution

#include <iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

using namespace std;


// struct for studentType
struct StudentType
{
string studentFName;
string studentLName;
int testScore; // 0-100
char grade;

};

//function to find highestScore and print student name have highest score

StudentType highestScore(struct StudentType *st)
{
int i=0;
int k;
int high=0;
while(i<20)
{
int h=st[i].testScore;
if(h >= high)
{
high=h;
k=i;
}
i++;
}

cout<<\" High Score is : \"<< high <<endl;
cout<<\"The name of student have highest score is : \"<<st[k].studentLName <<\", \"<<st[k].studentFName<<endl ;
return *st;

}

// function to display information
StudentType display(struct StudentType *st)
{
int i=0;
cout<<\"------student information------\"<<endl;
cout<< \"Last Name , First Name \"<<endl;
while(i<20)
{
cout<<st[i].studentLName <<\", \"<<st[i].studentFName<<endl;
i++;

}
return *st;

}

//function to assign grade
StudentType assignGrade(struct StudentType *st)
{
int i=0;
while(i<20)
{
cout<<\"Test score of student \"<<i+1<< \" is : \"<<st[i].testScore;
if(st[i].testScore>=90)
{
st[i].grade=\'A\';
cout<<\" & Grade is :\"<<st[i].grade<<endl;
}

if((st[i].testScore >=80) && (st[i].testScore< 90))
{
st[i].grade=\'B\';
cout<<\" & Grade is :\"<<st[i].grade<<endl;

}
if((st[i].testScore >=70) && (st[i].testScore< 80))
{
st[i].grade=\'C\';
cout<<\" & Grade is :\"<<st[i].grade<<endl;

}
if((st[i].testScore >=60) && (st[i].testScore< 70))
{
st[i].grade=\'D\';
cout<<\" & Grade is :\"<<st[i].grade<<endl;

}
if((st[i].testScore >=50) && (st[i].testScore< 60))
{
st[i].grade=\'E\';
cout<<\" & Grade is :\"<<st[i].grade<<endl;

}
if((st[i].testScore <50))
{
st[i].grade=\'F\';
cout<<\" & Grade is :\"<<st[i].grade<<endl;

}


i++;

}

return *st;

}

// main function
int main()
{
int i=0;

//st is array of 20
StudentType st[20];
while(i<20)
{
cout<<\"Enter First Name of Student \" << i+1 <<\" : \";
cin>>st[i].studentFName;

cout<<\"Enter Last Name of Student \" << i+1 <<\" : \";
cin>>st[i].studentLName;

cout<<\"Enter the testScore of Student \" << i+1 <<\" : \";
cin>>st[i].testScore;

i++;
}

//calling assignGrade function
assignGrade(st);

//calling highestScore function
highestScore(st);

//calling display function
display(st);

return 0;
}

=========================================================

Out sample of 5 student is:-

Enter First Name of Student 1 : rah
Enter Last Name of Student 1 : fdgsdf
Enter the testScore of Student 1 : 56
Enter First Name of Student 2 : gbfg
Enter Last Name of Student 2 : fhjfh
Enter the testScore of Student 2 : 87
Enter First Name of Student 3 : gnfg
Enter Last Name of Student 3 : dhdg
Enter the testScore of Student 3 : 67
Enter First Name of Student 4 : hfg
Enter Last Name of Student 4 : dhgfg
Enter the testScore of Student 4 : 69
Enter First Name of Student 5 : gfj
Enter Last Name of Student 5 : dhfg
Enter the testScore of Student 5 : 88
Test score of student 1 is : 56 & Grade is :E
Test score of student 2 is : 87 & Grade is :B
Test score of student 3 is : 67 & Grade is :D
Test score of student 4 is : 69 & Grade is :D
Test score of student 5 is : 88 & Grade is :B
High Score is : 88
The name of student have highest score is : dhfg, gfj
------student information------
Last Name , First Name
fdgsdf, rah
fhjfh, gbfg
dhdg, gnfg
dhgfg, hfg
dhfg, gfj

---------------------------------------------------------------------------------------------

If you have any query, please feel free to ask.

Thanks a lot.

Write teh progrsm in c++ Write a program that reads students\' names followed by their test scores. the program should output each student\'s name followed by t
Write teh progrsm in c++ Write a program that reads students\' names followed by their test scores. the program should output each student\'s name followed by t
Write teh progrsm in c++ Write a program that reads students\' names followed by their test scores. the program should output each student\'s name followed by t
Write teh progrsm in c++ Write a program that reads students\' names followed by their test scores. the program should output each student\'s name followed by t

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site