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.
#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];
}
Comments
Leave a comment