In C : Write a program that assigns test score grades. The program\'s input shou
ID: 3864823 • Letter: I
Question
In C :
Write a program that assigns test score grades. The program's input should be a series of test scores of type int. Have the program read each score and print either the corresponding grade or an appropriate error message. The program is to continue until end-of-file. If invalid character data is entered, you will need to flush the invalid characters so that test scores can continue to be entered until end-of-file.
Assume the following grading scale:
9 - 10 A
8 B
7 C
6 D
0 - 5 F
Use a switch statement to assign or print the appropriate grade.
Run your program using the following input:
1. All of the values between 0 and 10, inclusive
2. A negative value
3. A value greater than 10
4. A character value
Run the program with a valid value after all of these error cases to verify that the bad data was flushed correctly.
Turn in printouts of your program listing and the output. Make sure that your full name is on all of your printouts. Staple the assignment sheet to the top of your program.
As before, part of your grade will be based on the proper use of:
1. meaningful variable names
2. indentation
3. blank lines and spacing
4. comments on the following:
- program description
- function descriptions
- all variable and constant declarations
- ambiguous or complex sections of code
5. the correct use of local variables, local prototypes, and parameter passing
6. format and appearance of output
7. structured code
Explanation / Answer
Answer:
#include<iostream.h>
using namespace std;
main()
{
int input;
char rank;
cout<<" Enter marks value ";
cin>>input;
switch(input/100)
{
case 9 : rank='A';
break;
case 8 : rank='A';
break;
case 7 : rank='B';
break;
case 6 : rank='C';
break;
case 5 : rank='D';
break;
default : rank='F';
}
cout<<" Grade rated is :"<<rank<<endl;
return 0;
}