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.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education