Question: C++- Please solve TODO sections and match sample output. TODO: (1) Demonstrate using a Do-While loop in place of a While loop. (2) Use a

C++- Please solve TODO sections and match sample output.

TODO:

(1) Demonstrate using a Do-While loop in place of a While loop.

(2) Use a Switch statement in place of If-Else-If-Else.

*/

#include

#include

using namespace std;

const char ANIMAL_KINGDOM = 'A'; // constants for menu options

const char EPCOT = 'E';

const char HOLLYWOOD_STUDIOS = 'H';

const char MAGIC_KINGDOM = 'M';

const char QUIT = 'Q';

int main()

{

char option; // input for menu choice

bool done; // flag for loop control

done = false;

// TODO: Convert this to a do-while loop

while (!done)

{

// display menu

cout << endl

<< setw(25) << " Program Menu " << endl

<< setw(25) << "---------------------" << endl

<< setw(5) << ANIMAL_KINGDOM << " ...... Animal Kingdom" << endl

<< setw(5) << EPCOT << " ...... EPCOT" << endl

<< setw(5) << HOLLYWOOD_STUDIOS << " ...... Hollywood Studios" << endl

<< setw(5) << MAGIC_KINGDOM << " ...... Magic Kingdom" << endl

<< setw(5) << QUIT << " ...... Quit Program" << endl

<< setw(25) << "---------------------" << endl;

// get user response

cout << setw(20) << "Enter your selection: ";

cin >> option;

option = toupper(option);

// TODO: convert this entire if...else if... to a switch statement

if (option == ANIMAL_KINGDOM) // option A

{

cout << " You are going to Animal Kingdom. Experience the \"Kilamanjaro Safari\"! ";

}

else if (option == EPCOT) // option E

{

cout << " You are going to EPCOT. \"Try Fast Track\" while you are there! ";

}

else if (option == HOLLYWOOD_STUDIOS) // option H

{

cout << " You are going to Hollywood Studios. \"Rock and Roller Coaster\" is awesome! ";

}

else if (option == MAGIC_KINGDOM) // option M

{

cout << " You are going to Magic Kingdom. Try the newest attraction, \"7 Dwarves Mine Train Ride\". ";

}

else if (option == QUIT) // option Q, set loop exit condition

{

done = true;

}

else // invalid menu response

{

cout << " Invalid selection, please try again. ";

}

} // end program loop

cout << " End Program - ";

}

/* Sample Output

Program Menu

---------------------

A ...... Animal Kingdom

E ...... EPCOT

H ...... Hollywood Studios

M ...... Magic Kingdom

Q ...... Quit Program

---------------------

Enter your selection: a

You are going to Animal Kingdom. Experience the "Kilamanjaro Safari"!

Program Menu

---------------------

A ...... Animal Kingdom

E ...... EPCOT

H ...... Hollywood Studios

M ...... Magic Kingdom

Q ...... Quit Program

---------------------

Enter your selection: E

You are going to EPCOT. "Try Fast Track" while you are there!

Program Menu

---------------------

A ...... Animal Kingdom

E ...... EPCOT

H ...... Hollywood Studios

M ...... Magic Kingdom

Q ...... Quit Program

---------------------

Enter your selection: h

You are going to Hollywood Studios. "Rock and Roller Coaster" is awesome!

Program Menu

---------------------

A ...... Animal Kingdom

E ...... EPCOT

H ...... Hollywood Studios

M ...... Magic Kingdom

Q ...... Quit Program

---------------------

Enter your selection: 3

Invalid selection, please try again.

Program Menu

---------------------

A ...... Animal Kingdom

E ...... EPCOT

H ...... Hollywood Studios

M ...... Magic Kingdom

Q ...... Quit Program

---------------------

Enter your selection: q

End Program - Press any key to continue . . .

*/

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!