Question

In: Computer Science

In C++ and input code using the template below Get a copy of the caseswitch.cpp. The...

In C++ and input code using the template below

  • Get a copy of the caseswitch.cpp.

    The purpose of the program is to demonstrate how to use Switch statement.

  • Complete the for loop so that the program will ask the user for 6 input grades.
  • Compile and run this C++ program. Use input value 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 for all unrecognized grades that prints grade << " is not a legal grade.".
/************************************************************
 *
 *       FileName: caseswitch.cpp
 *       Author:   Guili Liu
 *       Purpose:  Demonstrate how to use Switch Statemenet.
 *
 **************************************************************/
#include <iostream>
using namespace std;
int main()
{
   char grade;

   //Fill in this for loop so it will repeat six times
   for (  ;  ;  )
   {
      cout << "Please enter a character grade (A, B, C, D, or F): ";
      cin >> grade;

      switch (grade)
      {
         case 'A': cout << "Great work. " << endl;
                   break;

         // Add a case for 'B' that prints "Good work."

         case 'C': cout << "Passing work. " << endl;
                   break;
         case 'D': 
         case 'F': cout << "Unsatisfictory work. " << endl;
                   cout << "See your instructor." << endl;
                   break;

         // Add a default that prints
         //          grade << " is not a legal grade."

      } //end of switch statement

   } //end of for loop
   return 0;
}
// end program

Solutions

Expert Solution

Code:

#include <iostream>
using namespace std;
int main()
{
char grade;

for (int i=1;i<=6;i++)
{
cout << "Please enter a character grade (A, B, C, D, or F): ";
cin >> grade;

switch (grade)
{
case 'A': cout << "Great work. " << endl;
break;

case 'B': cout << "Good work. " << endl;
break;

case 'C': cout << "Passing work. " << endl;
break;
case 'D':
case 'F': cout << "Unsatisfictory work. " << endl;
cout << "See your instructor." << endl;
break;

default:
cout << grade << " is not a legal grade." << endl;

} //end of switch statement

} //end of for loop
return 0;
}
// end program

Please refer to the screenshot of the code to understand the indentation of the code:

Output:

For any doubts or questions comment below.


Related Solutions

Using the following code perform ALL of the tasks below in C++: ------------------------------------------------------------------------------------------------------------------------------------------- Implementation: Overload input...
Using the following code perform ALL of the tasks below in C++: ------------------------------------------------------------------------------------------------------------------------------------------- Implementation: Overload input operator>> a bigint in the following manner: Read in any number of digits [0-9] until a semi colon ";" is encountered. The number may span over multiple lines. You can assume the input is valid. Overload the operator+ so that it adds two bigint together. Overload the subscript operator[]. It should return the i-th digit, where i is the 10^i position. So the first...
Can someone make this code work without using template? C++ using namespace std; template < typename...
Can someone make this code work without using template? C++ using namespace std; template < typename T>    void print_array(T arr[], int size)    {        ofstream outfile;        outfile.open("/Users/android/Desktop/outfile.txt");        cout << "Printing Array: " << endl;        for (int i = 0; i < size; i++)        {            cout << arr[i] << endl;            outfile << arr[i] << endl;        }    } template < typename T>...
C++ Hello .I need to convert this code into template and then test the template with...
C++ Hello .I need to convert this code into template and then test the template with dynamic array of strings also if you can help me move the function out of the class that would be great.also There is a bug where the memory was being freed without using new operator. I cant seem to find it thanks in advance #include using namespace std; class DynamicStringArray {    private:        string *dynamicArray;        int size;    public:   ...
in C++ use loopDW.cpp below Do While Loop Exercise Get a copy of the loopDW.cpp. Add...
in C++ use loopDW.cpp below Do While Loop Exercise Get a copy of the loopDW.cpp. Add a do-while loop to complete the program. The do-while loop will make sure that a valid mark will be obtained before further process. (hint: a event-controlled do-while loop is needed.) Compile and run the program. Use input values: -10, 30, 59, 70, 75, 96, and 108. Show the output to your lab instructor. #include <iostream> using namespace std; int main() { int mark; char...
Answer IN R CODE to get the following. Using the data below, Create a scatterplot of...
Answer IN R CODE to get the following. Using the data below, Create a scatterplot of y vs x Fit a simple linear regression model using y as the response and plot the regression line (with the data) Test whether x is a significant predictor and create a 95% CI around the slope coefficient. Report and interpret the coefficient of determination. For x=20, create a CI for E(Y|X=20). For x=150, can you use the model to estimate E(Y|X=150)? Discuss. Does...
what is the calculated the average code using C++ Having a hard time trying to get...
what is the calculated the average code using C++ Having a hard time trying to get the float average.
In Coral Code Please!!!! The assignment is to get an integer from input, and output that...
In Coral Code Please!!!! The assignment is to get an integer from input, and output that integer squared, ending with newline. (Note: This assignment is configured to have students programming directly in the zyBook. Instructors may instead require students to upload a file). Below is a program that's been nearly completed for you. Click "Run program". The output is wrong. Sometimes a program lacking input will produce wrong output (as in this case), or no output. Remember to always pre-enter...
Windows Interprocess communication. WM_CopyData IPC (data copy) - source code (c++) windows data copy IPC code
Windows Interprocess communication. WM_CopyData IPC (data copy) - source code (c++) windows data copy IPC code
in python Using this baseline template, write a program to input a choice from a menu...
in python Using this baseline template, write a program to input a choice from a menu def calcArea(length, width):    pass    def CalcVolumeSa(length, width, height):    pass def menu():    pass        def getValuesArea(): pass    def getValuesVolSa(): pass       def main():    menu() if __name__ == "__main__":    main() [1] - Calculate Area of rectangle [2] - calculate Volume and Surface area of Rectangle [x} - Exit Please select Option: input the appropriate values and calculate...
Pythons code using idle Write an input function. Then use it to supply the input to...
Pythons code using idle Write an input function. Then use it to supply the input to following additional functions: i) Print multiplication table of the number from 1 to 12. ii) Print the sum of all the numbers from 1 to up the number given. iii) Print if the number supplied is odd or even.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT