Using SWITCH statement structure i. Bases on the Marks and Grades table as in pr
ID: 3857446 • Letter: U
Question
Using SWITCH statement structure i. Bases on the Marks and Grades table as in program P1 above, write a program accept an alphabet, and output the mark's range for the grade inserted. ii. Enhance the program so that the user only can enter either small letter or capital letter for a, b, c, d, e or f, other than that it will display "invalid alphabet entered!" Example sample run: Small letter b Please enter the grade: b You got a B! Your mark is between 70-79 Press any key to continue - - - Capital letter b Please enter the grade: B You got a B! Your mark is between 70-79 Press any key to continue - - - - Special Character Please enter the grade: & Invalid alphabet entered! Press any key to continue - - - Number Please enter the grade: 3 Invalid alphabet entered! Press any key to continue - - -Explanation / Answer
H, Below is your program. I was not having P2, so I have added as per the arbitary grades. Let me know if you have any concern in this: -
#include<iostream>
using namespace std;
int main() {
char option;
cout<<"Please enter the grade: ";
cin>>option;
switch(option) {
case 'A':
case 'a':
cout<<"You got a A! Your mark is between 80 - 100";
break;
case 'B':
case 'b':
cout<<"You got a B! Your mark is between 70 - 79";
break;
case 'C':
case 'c':
cout<<"You got a C! Your mark is between 60 - 69";
break;
case 'D':
case 'd':
cout<<"You got a D! Your mark is between 50 - 59";
break;
case 'E':
case 'e':
cout<<"You got a E! Your mark is between 0 - 49";
break;
default:
cout<<"Invalid alphabet entered!";
}
}
Sample Output: -
Please enter the grade: A
You got a A! Your mark is between 80 - 100
--------------------------------
Process exited after 2.571 seconds with return value 0
Press any key to continue . . .
Please enter the grade: a
You got a A! Your mark is between 80 - 100
--------------------------------
Process exited after 1.105 seconds with return value 0
Press any key to continue . . .
Please enter the grade: c
You got a C! Your mark is between 60 - 69
--------------------------------
Process exited after 0.8047 seconds with return value 0
Press any key to continue . . .
Please enter the grade: #
Invalid alphabet entered!
--------------------------------
Process exited after 1.208 seconds with return value 0
Press any key to continue . . .
Please enter the grade: 86
Invalid alphabet entered!
--------------------------------
Process exited after 0.7866 seconds with return value 0
Press any key to continue . . .
Please enter the grade: 1
Invalid alphabet entered!
--------------------------------
Process exited after 0.8894 seconds with return value 0
Press any key to continue . . .
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.