Colour Theme Font Size Options
 
 
 
Exercise 1

For Loop and Switch-Case Exercise

Create a C++ program ex1_caseswitch.cpp with the following code in the Visual Studio project or copy the following code into your other IDE:


The purpose of this program is to demonstrate how to use switch-case statements, and to help you practice writing for loops.

The completed program will use a for loop to ask for 6 letter grades. A switch case statement will give an appropriate message for any letter typed, including error messages for incorrect letters.

Instructions:

  • Complete the for loop so that the program will ask the user for 6 input grades.
  • Compile and run this C++ program. Use these input values: A, B, C, D, E, and F.
  • Notice there is no output for B and E. Add cases for them.
    • B is "Good Work." Add a case for 'B'.
    • E is not a legal grade. Add a default: case to handle any unrecognized grades. It should print an error message that includes the invalid grade letter. For example:
      Please enter a character grade (A, B, C, D, or F): E E is not a legal grade. Please enter a character grade (A, B, C, D, or F): Z Z is not a legal grade. Please enter a character grade (A, B, C, D, or F): B Good Work. Please enter a character grade (A, B, C, D, or F):
      etc.

When you are done:

  • Take a screenshot that demonstrates all 5 legal grades and an illegal grade in any order to URCourses.
  • For this exercise, you will have: ex1_caseswitch.cpp.
  • Complete all the exercises in this option and upload the .cpp files and the screenshots in the URCourses.