Question: c++ A common programming task is to get numerical input from the user. Write a single function that will: 1) Display a prompt 2) Get
c++
A common programming task is to get numerical input from the user.
Write a single function that will:
1) Display a prompt
2) Get user's input (from keyboard)
3) Verify that the input is valid (within a range, inclusive)
4) If the input is valid, accept it and return
5) If the input is invalid, display an error message and try again
Create a new function that performs the steps above. Use the following:
1) Function name: get_input
2) Parameter: prompt (pass by constant reference)
3) Parameter: error_msg (pass by constant reference)
4) Parameter: min_value (pass by value)
5) Parameter: max_value; (pass by value)
6) Parameter: range_check (true or false) (pass by value)
7) return: value
Function get_input() should provide error checking that detects non-numeric input.
If parameter range_check is true, display the valid range as part of the prompt so the
user knows what range of values is acceptable and provide range checking; otherwise,
don't provide range checking. Usually range checking is desired; provide a default.
Hints: 1) if (cin>>value) { } else { }; 2) cin.clear(); 3) cin.ignore();
Step 2. (10 points)
Test the function get_input() by asking the user for their birthday. Call it
3 times to get: month, day, year. Provide a valid range for each. Assume a
valid day is 1 to 31, month is 1 to 12, year is from 1900 to 2020. For now,
don't worry about the number of days each month has; that comes later.
Step 3. (10 points)
Despite input validation, it is possible the user entered the wrong information.
Give the user an opportunity to verify and correct invalid input. Create a loop
that displays the person's birthday as entered in MM/DD/YYYY format. Example: 7/4/1776
On ONE line, display the entered date, followed by a menu of options:
birthday is 7/4/1776 Options: CHANGE: m)onth, d)ay, y)ear; OR a)ccept, r)efuse?
The options should do this:
m)onth : reenter the month;
d)ay : reenter the day;
y)ear : reenter the year;
a)ccept : user claims data is correct, accept date as entered and exit loop
r)efuse : user does NOT want to enter a birthday. Set date to 0/0/0000, exit loop
In main, get the user's birthday. Loop as described above to accept changes.
Accept upper and lower case. Use an enum and a switch statement for the options.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
