107k views
2 votes
Design and implement a program (name it GradeReport) that uses a switch statement to print out a message that reflect the student grade on a test. The messages are as follows:

For a grade of 100 or higher, the message is ("That grade is a perfect score. Well done.")
For a grade 90 to 99, the message is ("That grade is well above average. Excellent work.")
For a grade 80 to 89, the message is ("That grade is above average. Nice job.")
For a grade 70 to 79, the message is ("That grade is average work.")
For a grade 60 to 69, the message is ("That grade is not good, you should seek help!")
For a grade below 60, the message is ("That grade is not passing.")

User MoveFast
by
7.8k points

1 Answer

5 votes

Answer:

#include <iostream>

using namespace std;

int main()

{

int grade;

cout << "Enter student's grade: ";

cin >> grade;

switch (grade)

{

case 100 ... 1000:

cout << "That grade is a perfect score. Well done.";

break;

case 90 ... 99:

cout << "That grade is well above average. Excellent work.";

break;

case 80 ... 89:

cout << "That grade is above average. Nice job.";

break;

case 70 ... 79:

cout << "That grade is average work.";

break;

case 60 ... 69:

cout << "That grade is not good, you should seek help!";

break;

default:

cout << "That grade is not passing.";

break;

}

return 0;

}

Step-by-step explanation:

*The code is in C++

First, ask the user to enter a grade

Then, check the grade to print the correct message. Since you need to check the ranges using switch statement, you need to write the minimum value, maximum value and three dots between them. For example, 70 ... 79 corresponds the range between 70 and 79 both inclusive.

Finally, print the appropriate message for each range.

Note: I assumed the maximum grade is 1000, which should more than enough for a maximum grade value, for the first case.

User Aram Boyajyan
by
7.1k points