Answer to Question #290959 in C++ for DANISH

Question #290959

Implement this program by using User-defined functions and Structures


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:

1. A function to read the students’ data into the array.

2. A function to assign the relevant grade to each student.

3. A function to find the highest test score.

4. A function to print the names of the students having the highest test score.


1
Expert's answer
2022-01-26T17:49:09-0500
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
#include <iostream>
using namespace std;


#define NO_OF_STUDENTS	5


struct Student
{
	string Name;
	int TestScore;
	char Grade;
};
struct Student S[NO_OF_STUDENTS];


void GetStudent(int n)
{
	int t=-1;
	cout<<"\n\tEnter Student's Name         : "; cin>>S[n].Name;
	while(t<0 || t>100)
	{
		cout<<"\n\tEnter Student's Score (0-100): "; cin>>t;
		S[n].TestScore = t;
	}
}


void AssignGrade(int n)
{
	int m;
	for(m=0;m<n;m++)
	{
		if(S[m].TestScore>80)
		{
			S[m].Grade = 'A';
		}
		else if(S[m].TestScore>70 && S[m].TestScore<=80)
		{
			S[m].Grade = 'B';
		}
		else if(S[m].TestScore>60 && S[m].TestScore<=70)
		{
			S[m].Grade = 'C';
		}
		else if(S[m].TestScore>50 && S[m].TestScore<=60)
		{
			S[m].Grade = 'D';
		}
		else
		{
			S[m].Grade ='E';
		}
	}
	cout<<"\n\n\tStudent's Record";
	for(m=0;m<n;m++)
	{
		cout<<"\n\tName: "<<S[m].Name<<"\tScore: "<<S[m].TestScore<<"\tGrade: "<<S[m].Grade;
	}
}


void HighestScore(int n)
{
	int m,Max,ind;
	Max  = S[0].TestScore;
	ind=0;
	for(m=0;m<n;m++)
	{
		if(Max<=S[m].TestScore) 
		{
			Max = S[m].TestScore; ind = m;
		}
	}
	cout<<"\n\tStudent with Highest Score: "<<S[ind].Name<<"\tScore: "<<S[ind].TestScore<<"\tGrade: "<<S[ind].Grade;
}


int main()
{
	int n=0,Flag=1;
	
	while(Flag)
	{
		cout<<"\n\tPress-1 to add new student's record";
		cout<<"\n\tPress-0 to Quit";
		Flag=-1;
		while(Flag<0 || Flag>1)
		{
			cout<<"\n\tEnter Option 0 or 1: "; cin>>Flag;
		}
		if(Flag==1) 
		{
			if(n<NO_OF_STUDENTS) {GetStudent(n); n++;}		
			else
			cout<<"\n\tNo more students addition allowed.";
		}
	}
	AssignGrade(n);
	HighestScore(n);
	return(0);	
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment