Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

** Using C++ ** To do this, we will augment the shapes lab with input validation

ID: 3862213 • Letter: #

Question

** 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 <CTRL> + C. Alternatively, you can open another window, list all processes by typing "ps -e" (grepping the output), and killing the appropriate process by typing "kill -9 <pid>".

Now we wish to validate the input for types as well as values to avoid this problem. There are 3 major concepts to be aware of:

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.

Explanation / Answer

Hi,

Below is the code for your problem:

Like this you can draw the other shapes and add the if condition accordingly.

I hope this will solve your problem.