Question

EX 8.1Implementing a Menu Class Problem StatementIn this Worked Example, our task is to write a...

EX 8.1Implementing a Menu Class

Problem StatementIn this Worked Example, our task is to write a class for displaying a menu. An object of this class can display a menu such as

1) Open new account
2) Log into existing account
3) Help
4) Quit

Reimplement the Menu class of Worked Example 8.1 so that it stores all menu items in one long string. Hint: Keep a separate counter for the number of options. When a new option is added, append the option count, the option, and a newline character.

Homework Answers

Answer #1

Programming Language C++ Program which will display the list of Menu Option.

#include <iostream>
#include<string>
using namespace std;
class Menu
{
string option;
int counter;
public:
Menu()
{
counter = 0;
}
Menu(string item, int count) // parameterize constructor
{
option = option + "\n " + to_string(count) + " " + item;
}
void addOption(string item, int count) //method to add new option
{
option = option + "\n" + to_string(count) + " " + item;
}
string display() //method to display the list of option
{
return option;
}
};

int main()
{

int counter;
string check, option;
Menu m;
m.addOption("Open new account", 1);
m.addOption("Log in to an existing account", 2);
m.addOption("Help", 3);
m.addOption("Quit", 4);
counter = 4;
cout<<m.display()<<endl; //display the list
while(true)
{
cout<<endl<<"Add more options (Yes/No): ";
cin>>check;
if(check == "Yes" || check == "yes")
{
counter++;
cout<<"What is the option name: ";
cin>>option;
m.addOption(option, counter);
}
else
{
break;
}
}
cout<<m.display(); //display the list
return 0;
}

OUTPUT:

1 Open new account                                                                                                              

2 Log in to an existing account                                                                                                     

3 Help                                                                                                                          

4 Quit                                                                                                                          

                                                                                                                                

Add more options (Yes/No): Yes                                                                                                    

What is the option name: Display                                                                                                

                                                                                                                                

Add more options (Yes/No): No                                                                                                     

                                                                                                                                

1 Open new account                                                                                                              

2 Log in to an existing account                                                                                                     

3 Help                                                                                                                          

4 Quit                                                                                                                          

5 Display

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
JAVA !!! EX 8.1Implementing a Menu Class Problem StatementIn this Worked Example, our task is to...
JAVA !!! EX 8.1Implementing a Menu Class Problem StatementIn this Worked Example, our task is to write a class for displaying a menu. An object of this class can display a menu such as 1) Open new account 2) Log into existing account 3) Help 4) Quit Reimplement the Menu class of Worked Example 8.1 so that it stores all menu items in one long string. Hint: Keep a separate counter for the number of options. When a new option...
Task #4 Calculating the Mean Now we need to add lines to allow us to read...
Task #4 Calculating the Mean Now we need to add lines to allow us to read from the input file and calculate the mean. Create a FileReader object passing it the filename. Create a BufferedReader object passing it the FileReader object. Write a priming read to read the first line of the file. Write a loop that continues until you are at the end of the file. The body of the loop will: convert the line into a double value...
This program extends the earlier "Online shopping cart" program. (Consider first saving your earlier program). Extend...
This program extends the earlier "Online shopping cart" program. (Consider first saving your earlier program). Extend the ItemToPurchase class per the following specifications              Private fields string itemDescription - Initialized in default constructor to "none" Parameterized constructor to assign item name, item description, item price, and itemquantity (default values of 0).             Public instance member methods setDescription() mutator & getDescription() accessor (2 pts) printItemCost() - Outputs the item name followed by the quantity, price, and subtotal printItemDescription() - Outputs the...
Part A. Input Validation (Name your C program yourLastName_yourFirstName_Lab4a.c) 1. Place the code you developed in...
Part A. Input Validation (Name your C program yourLastName_yourFirstName_Lab4a.c) 1. Place the code you developed in Lab 2 to obtain a diameter value from the user and compute the volume of a sphere (we assumed that to be the shape of a balloon) in a new program, and implement the following restriction on the user’s input: the user should enter a value for the diameter which is at least 8 inches but not larger than 60 inches. Using an if-else...
Task 1: You will modify the add method in the LinkedBag class.Add a second parameter to...
Task 1: You will modify the add method in the LinkedBag class.Add a second parameter to the method header that will be a boolean variable: public boolean add(T newEntry, boolean sorted) The modification to the add method will makeit possible toadd new entriesto the beginning of the list, as it does now, but also to add new entries in sorted order. The sorted parameter if set to false will result in the existing functionality being executed (it will add the...
C++ Problem. You are coding a simple game called Pig. Players take turns rolling a die....
C++ Problem. You are coding a simple game called Pig. Players take turns rolling a die. The die determines how many points they get. You may get points each turn your roll (turn points), you also have points for the entire game (grand points). The first player with 100 grand points is the winner. The rules are as follows: Each turn, the active player faces a decision (roll or hold): Roll the die. If it’s is a: 1: You lose...
Objective The Final Project aims to demonstrate your ability to analyze data from a big database,...
Objective The Final Project aims to demonstrate your ability to analyze data from a big database, exercise use of arrays of objects, external classes, processing files and user interaction. For this project, you will design and implement a program that analyzes baby name popularities in data provided by the Social Security Administration. Every 10 years, the data gives the 1,000 most popular boy and girl names for kids born in the United States. The data can be boiled down to...
Complete a Java program named ARMgr that maintains customer accounts receivable in a database. The code...
Complete a Java program named ARMgr that maintains customer accounts receivable in a database. The code to initialize the CustomerAccountsDB database table and add a set of customer accounts is provided. Finish the code in these 3 methods in CustomerAccountDB.java to update or query the database: -purchase(double amountOfPurchase) -payment(double amountOfPayment) -getCustomerName() Hint: For getCustomerName(), look at the getAccountBalance() method to see an example of querying data from the database. For the purchase() and payment() methods, look at the addCustomerAccount() method...
For a C program hangman game: Create the function int setup_game [int setup_game ( Game *g,...
For a C program hangman game: Create the function int setup_game [int setup_game ( Game *g, char wordlist[][MAX_WORD_LENGTH], int numwords)] for a C program hangman game. (The existing code for other functions and the program is below, along with what the function needs to do) What int setup_game needs to do setup_game() does exactly what the name suggests. It sets up a new game of hangman. This means that it picks a random word from the supplied wordlist array and...
What tools could AA leaders have used to increase their awareness of internal and external issues?...
What tools could AA leaders have used to increase their awareness of internal and external issues? ???ALASKA AIRLINES: NAVIGATING CHANGE In the autumn of 2007, Alaska Airlines executives adjourned at the end of a long and stressful day in the midst of a multi-day strategic planning session. Most headed outside to relax, unwind and enjoy a bonfire on the shore of Semiahmoo Spit, outside the meeting venue in Blaine, a seaport town in northwest Washington state. Meanwhile, several members of...