Question

In: Computer Science

Write a C++ program to run a menu driven program with the following choices: 1) Display...

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

Solutions

Expert Solution

#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:


Related Solutions

The Menu-driven Program: Write a menu-driven program to implement a roomsboard for a classroom reservations system....
The Menu-driven Program: Write a menu-driven program to implement a roomsboard for a classroom reservations system. The menu includes the following options: Add new room. The program will prompt the user to enter the roomID, courseID and time of the new reserved room, then will call the add() method from the RoomsBoard class. Remove all occurrences of a room. The program will prompt the user to input the room ID to be removed, then call the remove() method from the...
C++ ^ ^ Write a menu driven program to perform following operations using a map container...
C++ ^ ^ Write a menu driven program to perform following operations using a map container that stores the information about USA Population (In Million). @@@Menu@@@ 1. Add Information 2. Display Information 3. Update Information 4. Erase Information 5. Clear Information For example, Suppose the map initially contains following information (Use emplace() function to store the information) 2010, 309.33 2011, 311.58 2012, 313.87 2015, 320.74 2016, 323.07 The program should produce the desired output when a valid input is provided,...
C++ PLEASE Write a program to prompt the user to display the following menu: Guess-Number                       ...
C++ PLEASE Write a program to prompt the user to display the following menu: Guess-Number                        Concat-names             Quit If the user selects Guess-number, your program needs to call a user-defined function called int guess-number ( ). Use random number generator to generate a number between 1 – 100. Prompt the user to guess the generated number and print the following messages. Print the guessed number in main (): Guess a number: 76 96: Too large 10 Too small 70 Close...
C++ 14.11 Lab # Map Write a menu driven program to perform following operations using a...
C++ 14.11 Lab # Map Write a menu driven program to perform following operations using a map container that stores the information about USA Population (In Million). @@@Menu@@@ 1. Add Information 2. Display Information 3. Update Information 4. Erase Information 5. Clear Information For example, Suppose the map initially contains following information (Use emplace() function to store the information) 2010, 309.33 2011, 311.58 2012, 313.87 2015, 320.74 2016, 323.07 The program should produce the desired output when a valid input...
Write a menu-driven C++ program with two options: 1) Is it odd or even? 2) End...
Write a menu-driven C++ program with two options: 1) Is it odd or even? 2) End Program.The user can only input a positive integer (0 does not count) and if the input is not a positive integer the program must state "Invalid Input." The program must determine whether the input is even or odd. The program must use functions and can only use the iostream and iomanip libraries. Note: The program must loop until the 2nd menu option is chosen.
Write a menu driven C++ program that prints the day number of the year , given...
Write a menu driven C++ program that prints the day number of the year , given the date in the form of month-day-year. For example , if the input is 1-1-2006 , then the day number is 1. If the input is 12-25- 2006 , the day number is 359. The program should check for a leap year. A year is leap if it is divisible by 4 but not divisible by 100. For example , 1992 , and 2008...
Write a python program to display a menu with the following options: (1) add, (2) subtract,...
Write a python program to display a menu with the following options: (1) add, (2) subtract, (3) multiply, (4) divide (5) mod, and (6) do nothing. I f the user enters something else (except 1-6), the program should display an error message. Otherwise, it should ask the user for two numbers, perform the calculation, and display the result.
Write a java program that will first display the following menu: Choose one of the following...
Write a java program that will first display the following menu: Choose one of the following 1- To add 2 double integers 2- To add 2 integer numbers 3- To add 3 double numbers 4- To add 3 integer numbers After reading user’s choice, use a switch case statement to call the corresponding method Void add 1 (double n1, double n2) Void add2() Double add3 (double n1, double n2, double n3) Double add4 ()
Write a simple airline ticket reservation program. The program should display a menu with the following...
Write a simple airline ticket reservation program. The program should display a menu with the following options: reserve a ticket, cancel a reservation, check whether a ticket is reserved for a particular person, and display the passengers. The information is maintained on an alphabetized linked list of names. In a simpler version of the program, assume that tickets are reserved for only one flight. In a fuller version, place no limit on the number of flights. Create a linked list...
Write a program names EncryptDecrypt.java that has the following menu choices: Print menu and allow user...
Write a program names EncryptDecrypt.java that has the following menu choices: Print menu and allow user to choose options. The program must have a file dialogue box for text file. Output should be based on user choices. Read in a file Print the file to the console Encrypt the file and write it to the console Write out the encrypted file to a text file Clear the data in memory Read in an encrypted file Decrypt the file Write out...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT