Write a two dimensional array program that reads student scores and then assigns grades based on the following scheme:
Grade is A if score is > = 90;
Grade is B if score is > = 80;
Grade is C if score is > = 70;
Grade is D if score is > = 60;
Grade is F otherwise.
The program prompts the user to enter the total number of students, then prompts the user to enter all of the scores, and concludes by displaying the grades.
#include <iostream>
using namespace std;
int main()
{
int numStd;
cout << "Please, enter the total number of students: ";
cin >> numStd;
int** scores = new int*[numStd];
for (int i = 0; i < numStd; i++)
scores[i] = new int[2];
for (int i = 0; i < numStd; i++)
{
cout << "Please, enter scores of student "<<i+1<<": ";
cin >> scores[i][0];
if (scores[i][0] >= 90)
scores[i][1] = 65;
else if(scores[i][0] >= 80)
scores[i][1] = 66;
else if (scores[i][0] >= 70)
scores[i][1] = 67;
else if (scores[i][0] >= 60)
scores[i][1] = 68;
else
scores[i][1] = 69;
}
cout << "The grades of students:\n";
cout << "\t\tScores\tGrades\n";
for (int i = 0; i < numStd; i++)
{
cout << "Student " << i+1 <<"\t"<< scores[i][0] << "\t" << char(scores[i][1]) << endl;
}
}
Comments
Leave a comment