Question: Modify the code from last week's Gradebook assignment with Arrays and Functions, to include a two - dimensional array for 3 students and 5 test

Modify the code from last week's Gradebook assignment with Arrays and Functions, to include a two-dimensional array for 3 students and 5 test scores per student.
Adjust the logic to drop the high score and the low score and average the remaining three scores for each student. The grade is based on the average of the 3 middle scores.
All data is read in from the keyboard.
Two global constants may be utilized: one for number of students and one for number of tests.
Display in a table format the student's name, 5 test scores, average, and grade. Include a header in the table to label each column respectively.
Use iomanip and setw() to format the output.
Main should consist of variable declarations and function calls. This means the for loops to process the arrays resides in the functions, not in main.
Here is my initial code, having issues trying to implement the bool validation.
#include
#include
#include
using namespace std;
void getStudentInfo(string& name, int& t1, int& t2, int& t3);
void displayResults(string name, float avg, char grade);
int getTestScore();
float calcAvg(int t1, int t2, int t3);
bool isValid(int num, int min, int max);
string getName();
char assignGrade(float avg);
int main()
{
char choice, finalGrade;
string fullName;
int test1, test2, test3;
float average;
do
{
getStudentInfo(fullName, test1, test2, test3); // replaces the four following lines of code
//fullName = getName();
//test1= getTestScore();
//test2= getTestScore();
//test3= getTestScore();
average = calcAvg(test1, test2, test3);
finalGrade = assignGrade(average);
displayResults(fullName, average, finalGrade);
cout <<"
\t Do you wish to restart the program? (Y/N)
";
cin >> choice;
cout << endl;
cin.ignore();
while (choice !='Y' && choice !='y' && choice !='N' && choice !='n')
{
cout <<" Invalid choice, please enter Y,y / N,n"<< endl;
cin >> choice;
}
} while (choice =='Y'|| choice =='y');
cout <<" You have quit the program
Thank you and come again!
";
return 0;
}
void getStudentInfo(string& name, int& t1, int& t2, int& t3)
{
name = getName();
t1= getTestScore();
t2= getTestScore();
t3= getTestScore();
}
void displayResults(string name, float avg, char grade)
{
cout << setw(35)<< setfill('-')<<""<< endl;
cout <<" Norco College "<< endl;
cout <<" CIS-5: Intro to Programming with C++
";
cout <<" Student Averages "<< endl;
cout << setw(35)<< setfill('-')<<""<< endl;
cout << showpoint << fixed << setprecision(2);
cout <<""<< name <<": "<< avg <<"; Grade: "<< grade << endl;
}
int getTestScore()
{
int score,
min =0,
max =100;
cout <<" Enter a test score:\t ";
cin >> score;
while (!isValid(score, min, max))// validation while loop
{
cout <<" Try again, please enter a valid test score (0-100)\t";
cin >> score;
}
return score; // returns an integer score for test scores
}
float calcAvg(int t1, int t2, int t3)
{
float avg;
avg =(static_cast(t1+ t2+ t3))/3.0;
return avg;
}
bool isValid(int num, int min, int max)
{
if (num< min || num > max)
{
return false;
}
else
{
return true;
}
}
string getName()
{
string name;
cout <<" Input the student name: ";
getline(cin, name);
return name;
}
char assignGrade(float avg)
{
const float A_GRADE =90.00;
const float B_GRADE =80.00;
const float C_GRADE =70.00;
const float D_GRADE =60.00;
const float F_GRADE =00.00;
char grade;
if (avg >= A_GRADE)
{
grade ='A';
cout <<" Excellent! You earned an "<< grade << endl;
}
else if (avg >= B_GRADE)
{
grade ='B';
cout <<" Good job! You earned a "<< grade << endl;
}
else if (avg >= C_GRADE)
{
grade ='C';
cout <<" Nice Work. You earned a "<< grade << endl;
}
else if (avg >= D_GRADE)
{
grade ='D';
cout <<" Below average work. You earned a "<< grade << endl;
}
else if (avg >= F_GRADE)
{
grade ='F';
cout <<" You failed the course, You earned a "<< grade << endl;
}
return grade;
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!