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

C++ use the following code and follow instructions (tasks) to create he expected

ID: 3726823 • Letter: C

Question

C++ use the following code and follow instructions (tasks) to create he expected output:

#include <iostream>
#include <string>
using namespace std;

int main()
{
char menuT;

do {
cout << "==== Menu Top ==== ";
cout << "A GoTo Menu A ";
cout << "B GoTo Menu B ";
cout << "E Exit: ";
cin >> menuT;
while (1) {
switch (menuT) {
case 'A':
cout << "==== Menu A ==== ";
cout << "A Do Action A ";
cout << "B Do Action B ";
cout << "E Exit: ";
cin >> menuT;
break;
case 'B':
cout << "==== Menu B ==== ";
cout << "A << Do Action A ";
cout << "B << Do Action B ";
cout << "E Exit: ";
cin >> menuT;
break;
case 'E':
return 0;
default:
cout << "Bad input" << endl;
}
if (menuT != 'A' || menuT != 'B') {
break;
}
}
} while (1);
}

Tasks 1 Make sure your code from lab 04 is functioning properly. Create the callMenu function wrapper in your code before main(). We talked about this in class and I demoed these steps on the big screen. 3 Cut out the menuA code and paste it into your callMenu function 4 Remove the menuB code. 5 At the place where menuA was located in main(), code a cto calMenu with the correct menuA arguments 6 Do the same for menuB with the menuB arguments. 7 Your code should now be ready for testing and debugging. 8 Get ride of any unnecessary stuff floating around from lab 04. 9 Now that it's working, make sure the output matches what is expected for lab 04 Test it thoroughly, again 10

Explanation / Answer

PROGRAM

#include<iostream>

#include<ctype.h>

using namespace std;

void menuA(); // Prototype Declare menuA() function

void menuB(); // Prototype Declare menuB() function

void callMenu()

{

char ch; // Declare character variable ch

while(1) // create inifinity while loop until choice "E"

{

// Display Main Menu

cout<<" ==== Menu Top ===== ";

cout<<"A GoTo Menu A"<<endl;

cout<<"B GoTo Menu B"<<endl;

cout<<"E Exit: ";

cin>>ch; // read choice

switch(ch) // Declare multiconditional statement

{

case 'A':

case 'a': menuA(); break; // check condition 'A' or 'a' then call menuA() function

case 'B':

case 'b': menuB(); break; // check condition 'B' or 'b' then call menuB() function

case 'E':

case 'e': cout<<"Exit Menu";exit(0); // Display "Exit Menu" and terminate entire program

default: cout<<"Bad Input"; // display "Bad Input"

}

}

}

int main()

{

callMenu(); // call callMenu() function

return 0;

}

void menuA() // implement menuA() function

{

char ch; // Declare character variable ch

while(1) // create infinity while loop until choice "E"

{

// Display Menu A

cout<<" ==== Menu A ==== ";

cout<<" A Do Action A"<<endl;

cout<<" B Do Action B"<<endl;

cout<<" E Exit: ";

cin>>ch; // Read Option character

switch(ch) // Declare multiconditional statement

{

case 'A':

case 'a': cout<<" Did A"; break; // check condition 'A' or 'a' then display 'Did A'

case 'B':

case 'b': cout<<" Did B"; break; // check condition 'B' or 'b' then display 'Did B'

case 'E':

case 'e': cout<<" Exit Menu";callMenu(); break; // Display "Exit Menu" and goto callMenu()

default: cout<<" Bad Input"; // display "Bad Input"

}

}

}

void menuB() // implement menuB()

{

char ch; // Declare Character variable ch

while(1) // create inifinity while loop until choice "E"

{

// Display Menu B

cout<<" ==== Menu B ===== ";

cout<<" A Do Action A"<<endl;

cout<<" B Do Action B"<<endl;

cout<<" E Exit: ";

cin>>ch; // Read choice

switch(ch) // Declare multiconditional statement

{

case 'A':

case 'a': cout<<" Did A"; break; // check condition 'A' or 'a' then display 'Did A'

case 'B':

case 'b': cout<<" Did B"; break; // check condition 'B' or 'b' then display 'Did B'

case 'E':

case 'e': cout<<" Exit Menu";callMenu(); break; // Display "Exit Menu" and goto callMenu()

default: cout<<" Bad Input"; // display "Bad Input"

}

}

}

OUTPUT:

==== Menu Top =====
A GoTo Menu A
B GoTo Menu B
E Exit: 2
Bad Input

==== Menu Top =====
A GoTo Menu A
B GoTo Menu B
E Exit: a

==== Menu A ====
A Do Action A
B Do Action B
E Exit: 2
Bad Input
==== Menu A ====
A Do Action A
B Do Action B
E Exit: e
Exit Menu

==== Menu Top =====
A GoTo Menu A
B GoTo Menu B
E Exit: b

==== Menu B =====
A Do Action A
B Do Action B
E Exit: 2
Bad Input
==== Menu B =====
A Do Action A
B Do Action B
E Exit: a
Did A
==== Menu B =====
A Do Action A
B Do Action B
E Exit: b
Did B
==== Menu B =====
A Do Action A
B Do Action B
E Exit: e
Exit Menu

==== Menu Top =====
A GoTo Menu A
B GoTo Menu B
E Exit: e
Exit Menu

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote