Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1 // This program usus a switch statement to determine 2 // the item selected fr

ID: 3673271 • Letter: 1

Question

1 // This program usus a switch statement to determine
2 // the item selected from a menu.
3 #include <iostream>
4 #incude <iomanip>
5 using namespace std;
6
7 int main ()
8 {
9      int choice;               // To hold a menu choice
10     int months;              // To hold the number of months
11     double charges;       // To hold the monthly charges
12
13     // Constants for membership rates
14     const double ADULT = 40.0,
15                          CHILD = 20.0,
16                          SENIOR = 30.0;
17                          
18     // Constants for menu choices
19     cons int ADULT_CHOICE = 1,
20                  CHILD_CHOICE = 2,
21                  SENIOR_CHOICE = 3,
22                  QUIT_CHOICE = 4;
23
24     // Display the menu and get a choice.
25     count << " Health Club Membership Menu "
26              << "1. Standard Adult Membership "
27              << "2. Child Membership "
28              << "3. Senior Citizen Membership "
29              << "4. Quit the Program "
30              << "Enter your choice: ";
31     cin >> choice;
32
33     // Set the numeric output formatting.
34     cout << fixed << showpoint << setprecision(2);
35
36     // Respond to the user's menu selection.
37     switch (choice)
38     {
39            case ADULT_CHOICE:
40                     cout << "for how many months? ";
41                     cin >> months;
42                     charges = months * ADULT;
43                     cout << "The total charges are $" << charges << endl;
44                     break;
45            
46            case CHILD_CHOICE:
47                     cout << "for how many months? ";
48                     cin >> months;
49                     charges = months * CHILD;
50                     cout << "The total charges are $" << charges << endl;
51                     break;
52
53            case SENIOR_CHOICE:
54                     cout << "for how many months? ";
55                     cin >> months;
56                     charges = months * SENIOR;
57                     cout << "The total charges are $" << charges << endl;
58                     break;
59
60            case QUIT_CHOICE
61                    cout << "Program ending. ";
62                    break
63
64            default:
65                     cout << "The valid choices are 1 through 4. Run the "
66                             << "program again and select one of those. ";
67       }
68
69 return 0;
70 }

***In addition to code listing, include a question to the user***add to code listing.
    a. Did you enjoy this program (y/n)?
    b. If the user enters y, output: That is nice!
    c. If the user enters n, output: Maybe next time.

Explanation / Answer

// This program usus a switch statement to determine
// the item selected from a menu.
#include <iostream>
#include <iomanip>

using namespace std;

int main ()
{
    int choice;               // To hold a menu choice
   int months;              // To hold the number of months
double charges;       // To hold the monthly charges

   // Constants for membership rates

const double ADULT = 40.0,CHILD = 20.0,SENIOR = 30.0;
// Constants for menu choices
const int ADULT_CHOICE = 1,CHILD_CHOICE = 2,SENIOR_CHOICE = 3,QUIT_CHOICE = 4;

// Display the menu and get a choice.
cout << " Health Club Membership Menu "<< "1. Standard Adult Membership "<< "2. Child Membership "<< "3. Senior Citizen Membership "<<"4. Quit the Program "<< "Enter your choice: ";
cin >> choice;

   // Set the numeric output formatting.
   cout << fixed << showpoint << setprecision(2);

   // Respond to the user's menu selection.
   switch (choice)
   {
          case ADULT_CHOICE:
                   cout << "for how many months? ";
                   cin >> months;
                   charges = months * ADULT;
                   cout << "The total charges are $" << charges << endl;
                   break;
        
          case CHILD_CHOICE:
                   cout << "for how many months? ";
                   cin >> months;
                   charges = months * CHILD;
                   cout << "The total charges are $" << charges << endl;
                   break;
          case SENIOR_CHOICE:
                   cout << "for how many months? ";
                   cin >> months;
                   charges = months * SENIOR;
                   cout << "The total charges are $" << charges << endl;
                   break;

          case QUIT_CHOICE:
                  cout << "Program ending. ";
                  break;

          default:
                   cout << "The valid choices are 1 through 4. Run the "<< "program again and select one of those. ";
     }
   
     //additonal codes for the question
     char ch;
     cout<<"Did you enjoy this program (y/n)?: ";
     cin>>ch;
     if(ch=='y')
      cout<<"That is nice! ";
    else
      cout<<"Maybe next time. ";

return 0;
}