Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

** 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 + 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 ". 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.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Excel As Your Database

Authors: Paul Cornell

1st Edition

1590597516, 978-1590597514

More Books

Students also viewed these Databases questions

Question

How many three-digit numbers are divisible by 7?

Answered: 1 week ago

Question

What is Indian Polity and Governance ?

Answered: 1 week ago