Question
** Using C++ ** To do this, we will augment the shapes lab with input validation, and add features along the way. TASK 0 In
** Using C++ **
To do this, we will augment the shapes lab with input validation, and add features along the way.
TASK 0
In the shapes lab, you drew a number of shapes, all in the main function. Rewrite the code into 5 separate functions that take appropriate arguments. These functions will only have side effects, returning void. 'Side effects' refer to a change in state. Here, we are referring to the state of the console (i.e., you will print something). Then, write a function that does the following:
Present a menu: "Enter (R)ectangle, (L)owerTriangle, (T)rapezoid, C(ircle), or (E)nd"
Input a character corresponding to the menu choice
Depending on whether the character is R, L, T, or C, input appropriate parameters
Call the appropriate drawing function
The function will do these steps repetitively until "E" is input.
For this task you only need to validate values (not types)
TASK 1
Run your above program, typing in a non-numeric value at a parameter prompt. State what happens in comments. Also state what happens if you enter a number causing overflow. You may need to terminate the program. In Linux this is done by typing
The >> function returns false when an input failure occurs. One possible cause of input failure is a type error.
Since the input stream library maintains an internal state, it needs to be reset after an error. This is done by calling cin.clear().
Since there may have been additional data typed on the error line (e.g., "foo 17" on a line expecting 2 integers), the rest of the line needs to be cleared before retrying. The cin.ignore() function indicates that the rest of the input line already read should be ignored.
Although we won't use it in this program, recall that the cin.fail() and cin.eof() functions can also be a major component of input validation.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started