C++ Program: 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. Buy2. Sell3. 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 \n characters.I.E.    char menu[] = "1. Buy\n2. Sell\n3. Convert\nX. 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. CPP program only.

Programming Logic & Design Comprehensive
9th Edition
ISBN:9781337669405
Author:FARRELL
Publisher:FARRELL
Chapter8: Advanced Data Handling Concepts
Section: Chapter Questions
Problem 1GZ
icon
Related questions
Question

C++ Program:

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. Buy2. Sell3. 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 \n characters.I.E.    char menu[] = "1. Buy\n2. Sell\n3. Convert\nX. 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 <cstring>
#include <string>
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.
CPP program only.

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Mathematical functions
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage