#include <iostream>
using namespace std;
// function declarations
void getStudents(string names[], int noOfStuds);
void getGrades(int** grade, int noOfStuds, int noOfTests);
void calcGrades(char gradeletter[], int** grade, int noOfStuds, int noOfTests);
void printStudents(string names[], int noOfStuds);
void printGrades(int** grade, int noOfStuds, int noOfTests);
void printFinalGrades(char gradeletter[], int noOfStuds);
int main()
{
// declaring variables
int noOfStuds, noOfTests;
// getting the inputs entered by the user
cout << “How many students :”;
cin >> noOfStuds;
cout << “How many assignments :”;
cin >> noOfTests;
// creating two dimensional array which stores grades
int** grade;
grade = new int*[noOfStuds];
for (int i = 0; i < noOfStuds; i++)
grade[i] = new int[noOfTests];
// creating array which stores student names
string names[noOfStuds];
// creating array which stores student grade letters
char gradeletter[noOfStuds];
// calling the functions
getStudents(names, noOfStuds);
getGrades(grade, noOfStuds, noOfTests);
calcGrades(gradeletter, grade, noOfStuds, noOfTests);
printStudents(names, noOfStuds);
printGrades(grade, noOfStuds, noOfTests);
printFinalGrades(gradeletter, noOfStuds);
return 0;
}
// This function will get the student names entered by the user
void getStudents(string names[], int noOfStuds)
{
for (int i = 0; i < noOfStuds; i++)
{
cout << “Enter name of student#” << i + 1 << “:”;
cin >> names[i];
}
}
// This function will get the student grades entered by the user
void getGrades(int** grade, int noOfStuds, int noOfTests)
{
for (int i = 0; i < noOfStuds; i++)
{
cout << “Student #” << i + 1 << “:” << endl;
for (int j = 0; j < noOfTests; j++)
{
cout << “Enter score of student” << j + 1 << “:”;
cin >> grade[i][j];
}
}
}
// This function will calculate the grade letter
void calcGrades(char gradeletter[], int** grade, int noOfStuds, int noOfTests)
{
double tot = 0.0, avg = 0.0;
for (int i = 0; i < noOfStuds; i++)
{
for (int j = 0; j < noOfTests; j++)
{
tot += grade[i][j];
}
avg = tot / noOfTests;
if (avg >= 90)
{
gradeletter[i] = ‘A’;
}
else if (avg >= 80 && avg < 90)
{
gradeletter[i] = ‘B’;
}
else if (avg >= 70 && avg < 80)
{
gradeletter[i] = ‘C’;
}
else if (avg >= 60 && avg < 70)
{
gradeletter[i] = ‘D’;
}
else if (avg >= 0 && avg < 60)
{
gradeletter[i] = ‘F’;
}
tot = 0.0;
}
}
// This function will display student names
void printStudents(string names[], int noOfStuds)
{
for (int i = 0; i < noOfStuds; i++)
{
cout << names[i] << “t”;
}
cout << endl;
}
// This function will display student grades
void printGrades(int** grade, int noOfStuds, int noOfTests)
{
for (int i = 0; i < noOfTests; i++)
{
for (int j = 0; j < noOfStuds; j++)
{
cout << grade[j][i] << “t”;
}
cout << endl;
}
}
// This function will display student grade letters
void printFinalGrades(char gradeletter[], int noOfStuds)
{
for (int i = 0; i < noOfStuds; i++)
{
cout << gradeletter[i] << “t”;
}
cout << endl;
}
____________________
Output:
