Question

Question 2 Use a switch statement to write the following program: Using C++ The program prompts...

Question 2

Use a

switch statement

to write the following program: Using C++

The program prompts the user for a letter grade (of type char). The list of valid letter grades

is:

A

B

C

D

E

F

The program should consider both lower and upper case

The program will then display the following messages:

For grade ‘A’: display “Excellent”

For grade ‘B’: display “Good”

For Grade ‘C’: display “Average”

For grade ‘D’ or ‘E’: display “Below Average”

For Grade ‘F’: display “Fail”

For any other letter grade entered by users: display “Invalid Grade”

Your test plan should include tests for each possible output, invalid input, and lowercase

letters.

Provide a total of 4 test cases:

-

You can choose a mix of test cases with uppercase inputs A, B, C, D, E, F or

lowercase inputs a, b, c, d, e, f.

-

1 invalid test case (provide a letter that is not within [A,F] or [a,f])

Test #

Valid / Invalid Data

Description of test

Input Value

Actual Output

Test Pass / Fail

1

Valid

Pass

2

Valid

Pass

3

Valid

Pass

4

Invalid

Pass

0 0
Add a comment Improve this question Transcribed image text
Answer #1

CODE IN C++:


#include <iostream>

using namespace std;

int main()
{
// declaring variable
char grade ;
//taking input from the user
cout << "Enter the grade (A/B/C/D/E/F) : ";
cin >> grade;
switch(grade){
case 'A':
case 'a':
cout << "Excellent" << endl ;
break;
case 'B':
case 'b':
cout << "Good" << endl ;
break;
case 'C':
case 'c':
cout << "Average" << endl ;
break;
case 'D':
case 'd':
case 'E':
case 'e':
cout << "Below Average" << endl ;
break;
case 'F':
case 'f':
cout << "Fail" << endl ;
break;
default:
cout << "Invalid Grade" << endl;
}
  
return 0;
}


OUTPUT:

input Enter the grade (A/B/C/D/E/F) : A Excellent ... Program finished with exit code o Press ENTER to exit console.

Add a comment
Know the answer?
Add Answer to:
Question 2 Use a switch statement to write the following program: Using C++ The program prompts...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Question 1 The following program asks the user for the current temperature (in Fahrenheit). Provide a...

    Question 1 The following program asks the user for the current temperature (in Fahrenheit). Provide a total of 7 valid test cases (one for each message). Do not provide invalid test cases. Add a series of if statements (if with multiple alternatives i.e. if/else if/else) so that one of the following messages is printed based on the temperature value: Temperature (F) Message >90 “Go swimming.” <=90, >80 “Turn on air conditioning.” <=80, >70 “Do nothing.” <=70, >55 “Turn on heat.”...

  • Using C++. Please Provide 4 Test Cases. Test # Valid / Invalid Data Description of test...

    Using C++. Please Provide 4 Test Cases. Test # Valid / Invalid Data Description of test Input Value Actual Output Test Pass / Fail 1 Valid Pass 2 Valid Pass 3 Valid Pass 4 Valid Pass Question 2 Consider a file with the following student information: John Smith 99 Sarah Johnson 85 Jim Robinson 70 Mary Anderson 100 Michael Jackson 92 Each line in the file contains the first name, last name, and test score of a student. Write a...

  • Using basic c++ write 2 separate codes for this assignment. Program #1 Write a program that...

    Using basic c++ write 2 separate codes for this assignment. Program #1 Write a program that calculates the average of a group of test scores, where the lowest score in the group is dropped. It should use the following functions. • void getScore() should ask the user for a test score, store it in the reference parameter variable, and validate it. This function should be called by the main once for each of the five scores to be entered. •...

  • C Programming QUESTION 9 Write a program that prompts for and reads four integer input values,...

    C Programming QUESTION 9 Write a program that prompts for and reads four integer input values, then a single character command. Submit your program as a .c file named midterm_prog2.c. Note that, similarly to your programming assignments, some percentage of your grade will depend on proper programming style. Your program will calculate and print a new value based on the command that's entered, as follows: 'A' or 'a': Calculate the average of the four input values 'S' or 's': Calculate...

  • Q3). Write a C program to compute and display maximum of three numbers using a function...

    Q3). Write a C program to compute and display maximum of three numbers using a function for maximum of two numbers. Sample Output: Input: 5153 Maximum = 15 Q4). Write a C program to input a lowercase alphabet character then display it as uppercase character. SAMPLE OUTPUT: Enter any a lowercase character: a Uppercase: A

  • Write a C++ program that will provide a user with a grade range if they enter...

    Write a C++ program that will provide a user with a grade range if they enter a letter grade. Your program should contain one function. Your function will accept one argument of type char and will not return anything (the return type will be void), but rather print statements to the console. Your main function will contain code to prompt the user to enter a letter grade. It will pass the letter grade entered by the user to your function....

  • In this program, you will be using C++ programming constructs, such as overloaded functions. Write a...

    In this program, you will be using C++ programming constructs, such as overloaded functions. Write a program that requests 3 integers from the user and displays the largest one entered. Your program will then request 3 characters from the user and display the largest character entered. If the user enters a non-alphabetic character, your program will display an error message. You must fill in the body of main() to prompt the user for input, and call the overloaded function showBiggest()...

  • The switch Statement C++program This lab work with the switch statement. • Remove the break statements...

    The switch Statement C++program This lab work with the switch statement. • Remove the break statements from each of the cases. What is the effect on the execution of the program? • Add an additional switch statement that allows for a Passing option for a grade of D or better. Use the sample run given below to model your output. Sample Run: What grade did you earn in Programming I? YOU PASSED! An A - excellent work! The following is...

  • Find the errors in following program. //This program uses a switch statement to assign a //...

    Find the errors in following program. //This program uses a switch statement to assign a // letter grade (A, B, C, D, or F) to numeric test score. #include <iostream> uisng namespace std; int main() { int testScore; cout<<"Enter your test score and I will tell you\n"; cout<<"the letter grade you earned: "; cin>>testScore; switch (testScore) { case (testScore < 60) cout<<"Your grade is F.\n"; break; case (testScore <70) cout<<"Your grade is D.\n" break; case (testScore <80) cout<<"Your grade is...

  • Find the errors in following program.   //This program uses a switch statement to assign a...

    Find the errors in following program.   //This program uses a switch statement to assign a // letter grade (A, B, C, D, or F) to numeric test score.     #include <iostream> uisng  namespace std;   int main() {                         int testScore;                         cout<<"Enter your test score and  I will tell you\n";             cout<<"the letter grade you earned: ";             cin>>testScore;               switch (testScore)             {                         case  (testScore < 60)                                     cout<<"Your grade is F.\n";...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT