Answer to Question #328552 in C++ for naqib ullah

Question #328552

Write a program that uses two parallel arrays to store student names and their grades. It should use an array of character that hold the names and array of character that hold the grades. The program should produce a report that displays list of student’s names and grades, and the name of the student that has the highest grade. The names and grades should be stored using an initialization list at the time the arrays are created. Use a loop and conditional statement to determine which student has the highest grade.

1
Expert's answer
2022-04-14T06:16:16-0400
#include <iostream>
#include <string>

using namespace std;

void main()
{
	const int N = 8;
	string names[] = {"Jack","John","Mary","Mike","Helen","Phill","Sew","Elis"};
	char grades[] = {'B','E','A','D','C','F','E','B'};
	cout << "Table with grades of students:\n";
	for (int i = 0; i < N; i++)
	{
		cout << names[i] << "\t" << grades[i] << endl;
	}
	char maxgrade = grades[0];
	int n = 0;
	for (int i = 0; i < N; i++)
	{
		 if(grades[i]<maxgrade)
		 {
			 maxgrade = grades[i];
			 n = i;
		 }
	}
	cout << "The best grade is " << grades[n]
		<< "\nIt has " << names[n];
}

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

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS