In: Computer Science
Write a C++ program to run a menu driven program with the following choices:
1) Display the grades
2) Adjust grade
3) Display Average for each student
4) Display number of student with at least a B
5) Quit
requirements:
1. Write a function called getValidGrade that allows a user to enter in an integer and loops until a valid number that is >= 0 and <= 100 is entered. It returns the valid value.
2. Write a function called getValidStudentNumber that allows a user to enter in an integer and loops until a valid number that is >= 0 and < NUM_STUDENTS is entered. It returns the valid value.
3. Write a function called getValidAssignmentNumber that allows a user to enter in an integer and loops until a valid number that is >= 0 and < NUM_GRADES is entered. It returns the valid value.
4. Write a function called displayGrades that takes the student and grade arrays as parameters and displays the grades in the format in the sample run below.
5. Write a function called displayAverageForEachStudent that takes the student and grade arrays as parameters, computes the average grade for each student, and displays the grades in the format in the sample run below.
6. Write a function called displayNumStudentsAtLeastBForSelectedAssignment that takes the student and grade arrays as parameters, allows the user to select a valid assignment and locates and displays the number of the student with at least a grade >= 80 for that assignment in the format in the sample run below.
7. Write a function called AdjustGrade that takes grade arrays as a pass by reference parameter, allows the user to select a valid student, a valid assignment, and a valid grade and changes the student assignment grade to the value entered.
8. Add comments wherever necessary.
Sample run:
Welcome to the help with the grading program!
1) Display the grades
2) Adjust grade
3) Display Average for each student
4) Display number of student with at least a B
5) Quit
Select an option (1..5)..1
Name Assign. 1 Assign. 2 Assign. 3 Assign. 4 Assign. 5
Tom 78 98 88 99 77
Jane 62 99 94 85 93
Jo 73 82 88 85 78
1) Display the grades
2) Adjust grade
3) Display Average for each student
4) Display number of student with at least a B
5) Quit
Select an option (1..5)..2
Adjust Grade
Please enter in the student number...
1
Please enter in an assignment number...
0
Please enter in the grade...
98
Grade changed
1) Display the grades
2) Adjust grade
3) Display Average for each student
4) Display number of student with at least a B
5) Quit
Select an option (1..5)..1
Name Assign. 1 Assign. 2 Assign. 3 Assign. 4 Assign. 5
Tom 78 98 88 99 77
Jane 62 99 94 85 93
Jo 98 82 88 85 78
1) Display the grades
2) Adjust grade
3) Display Average for each student
4) Display number of student with at least a B
5) Quit
Select an option (1..5)..0
Select an option (1..5)..9
Select an option (1..5)..3
Average grade for each student
Average Student 1: 88
Average Student 2: 86.6
Average Student 3: 86.2
1) Display the grades
2) Adjust grade
3) Display Average for each student
4) Display number of student with at least a B
5) Quit
Select an option (1..5)..4
Number of students with at least B
Please enter in an assignment number...
-9
Please enter in a valid assignment number...
1
Number of students with at least B on assignment 1 :1
1) Display the grades
2) Adjust grade
3) Display Average for each student
4) Display number of student with at least a B
5) Quit
Select an option (1..5)..2
Adjust Grade
Please enter in the student number...
2
Please enter in an assignment number...
1
Please enter in the grade...
-9
Please enter in a valid grade...
8888
Please enter in a valid grade...
55
Grade changed
1) Display the grades
2) Adjust grade
3) Display Average for each student
4) Display number of student with at least a B
5) Quit
Select an option (1..5)..1
Name Assign. 1 Assign. 2 Assign. 3 Assign. 4 Assign. 5
Tom 78 98 88 99 77
Jane 62 99 94 85 93
Jo 98 55 88 85 78
1) Display the grades
2) Adjust grade
3) Display Average for each student
4) Display number of student with at least a B
5) Quit
Select an option (1..5)..5
Process finished with exit code 0
#include<iostream>
using namespace std;
#define NUM_STUDENT 3
#define NUM_GRADES 5
/*Function definitions*/
int getValidGrade(){
int grade;
while(1){
cout<<"Please
enter a valid grade..."<<endl;
cin>>grade;
if(grade>=0
&& grade<=100)
//Validation
break;
}
return grade;
}
int getValidStudentNumber(){
int sNo;
while(1){
cout<<"Please
enter a valid student number..."<<endl;
cin>>sNo;
if(sNo>=0 &&
sNo<=NUM_STUDENT)
//Validation
break;
}
return sNo;
}
int getValidAssignmentNumber(){
int asNo;
while(1){
cout<<"Please
enter a valid assignment number..."<<endl;
cin>>asNo;
if(asNo>=0 &&
asNo<=NUM_GRADES)
//Validation
break;
}
return asNo;
}
void displayGrades(string st[],int gd[][5]){
cout<<"Name Assign.0 Assign.1 Assign.2
Assign.3 Assign.4"<<endl;
for(int i=0;i<NUM_STUDENT;i++){
cout<<st[i]<<" ";
for(int
j=0;j<NUM_GRADES;j++){
cout<<gd[i][j]<<" ";
}
cout<<endl;
}
}
void displayAverageForEachStudent(string st[],int gd[][5]){
for(int i =0 ;i<NUM_STUDENT;i++){
double sum=0;
for(int
j=0;j<NUM_GRADES;j++){
sum += gd[i][j];
}
cout<<"Average
Student 1: "<<sum/NUM_GRADES<<endl;
}
}
void displayNumStudentsAtLeastBForSelectedAssignment(int
gd[][5]){
int count=0;
int num = getValidAssignmentNumber();
for(int i=0;i<NUM_STUDENT;i++){
if(gd[i][num]>=80){
count++;
}
}
cout<<"Number of students with at least B
on assignment
"<<num<<":"<<count<<endl;
}
void adjustGrade(int (&gd)[3][5]){
cout<<"Adjust grade"<<endl;
int stNum = getValidStudentNumber();
int asNum = getValidAssignmentNumber();
int grade = getValidGrade();
gd[stNum][asNum]=grade;
cout<<"Grade Changed"<<endl;
}
int main(){
int
ch,gd[NUM_STUDENT][NUM_GRADES]={{78,98,88,99,77},{62,99,94,85,93},{73,82,88,85,78}};
string st[NUM_STUDENT] =
{"Tom","Jen","Jo"};
cout<<"Welcome to the help with the
grading program!"<<endl;
while(1){
cout<<"1) Display
the grades\n2) Adjust grade\n3) Display average for each
student\n4) Display number of student with atleast B\n5)
Quit"<<endl;
cout<<"Select an
option(1..5)..";
cin>>ch;
switch(ch){
case 1:
displayGrades(st,gd);
break;
case 2:
adjustGrade(gd);
break;
case 3:
displayAverageForEachStudent(st,gd);
break;
case 4:
displayNumStudentsAtLeastBForSelectedAssignment(gd);
break;
case 5:
cout<<"Process finished with exit code 0"<<endl;
exit(0);
}
}
return 0;
}
Screen-Shots: