Question: C++ program A C-String is defined as a char array with a terminating null character. Assignment Background: A menu is a list of options for

C++ program

A C-String is defined as a char array with a terminating null character.

Assignment Background:

A menu is a list of options for a user to select. The selection is the single character chosen for a menu item. An example menu is below:

1. Buy
2. Sell
3. Convert X. Exit

Assignment:

Write a method called "promptForInput" that will help you write user menus. You should be able to use this in future programs if wanted. The purpose for this method is to be the "end all of methods" that you could reuse in other situations.

The code should pass an C-String of valid characters to select to the promptForInput method as the 1st parameter. See "C-Strings Stored in Arrays" on page 556 8th ed. or 566 9th ed. In the example above, the C-String would be "123X".

The code should pass a C-String that is the menu to display as the 2nd parameter. It may help your display to have embedded characters.
I.E.
 char menu[] = "1. Buy 2. Sell 3. Convert X. Exit"; Example pseudo code: define c-string char array of valid input characters define menu loop until X input char input = promptForInput( myValidCharArray, menu); ..... Your method needs to handle upper and lower case input as the same values, but returning the value in the case as given in the valid character list. Using the data above, if I entered 'x', it should return 'X. If a character is entered that is not in your list of valid characters - display and indicate that the input was invalid and redisplay the menu. This processing needs to be part of the promprForInput() method. The main method must call the promptForInput method and display the char returned from the promptForInput method. That is all that main() needs to do. The promptForInput() method menu needs to be able to process any number of characters. 
The promptForInput() method should not have hard coded processing - i.e. if == 'X' ... Depending on your compiler, you may or may not need one or both of the following: #include  #include  
The assignment needs to call this method and report what valid character was given. The program should loop until the Exit option is selected. Deliverable - Write a program that displays the multi-choice menu (shown above in bold) that uses your new method to validate input.

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!