Question
PLEASE READ THE QUESTION CAREFULLY. I NEED THE FULL TASK. IF YOU ARE NOT SURE WHAT TO DO, PLEASE SKIP MY QUESTION. I WILL GIVE
PLEASE READ THE QUESTION CAREFULLY. I NEED THE FULL TASK. IF YOU ARE NOT SURE WHAT TO DO, PLEASE SKIP MY QUESTION. I WILL GIVE NEGATIVE RATING FOR WRONG OR INCOMPLETE ANSWER.
THANK YOU.
QUESTION:
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
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.
Identify places in your Task 0 code that need additional input validation, and rewrite the code to handle this. For example, you may write something like the following pseudocode:
output prompt while input n is false reset/clear system output an error message output prompt // assert n contains valid input
// CODE STARTS HERE
#include
#include
#include
using namespace std;
//These 4 functions are from the given code
void Task1()
{
int width, height;
cout<< "Task 1: Rectangular Frame"< cout<< "Enter width: "; cin>>width; cout<< "Enter height: "; cin>>height; cout< for(int i = 0; i < height; ++i) { for(int j = 0; j < width; ++j) { if(i == 0 || j == 0 || i == height - 1 || j == width - 1) { cout << "*"; } else{ cout << " "; } } cout << endl; } cout< } void Task2() { int length; cout<< "Task 2 North to West"< cout<< "Enter length: "; cin>>length; cout< for(int i=length; i >= 1; i--) { for(int j=1; j<=i; j++) { cout<< "*"; } cout<< " "; } cout< } void Task3() { int length; cout<< "Task 3: South to East"< cout<< "Enter length: "; cin>>length; cout< for(int i=length; i >= 1; i--) { for(int j=1; j <=i; j++) { cout<< " "; } for(int k=length;k>=i;k--) { cout << "*"; } cout<<" "; } cout< } void Task4() { cout << "Task 4: Circle"< float r; cout<<"Enter radius: " ; cin>>r; float pr = 2; // pixel ratio for (int i = -r; i <= r; i++) { for (int j = -r; j <= r; j++) { float d = ((i*pr)/r)*((i*pr)/r) + (j/r)*(j/r); if (d >0.95 && d<1.08) { cout << "*"; } else { cout << " "; } } cout << endl; } } //this is menu function //it will take choice from user //based on choice user entered, corresponding function will called void Menu() { char choice; //iterate till user enter E to end do{ //getting choice from user cout<<"Enter Your choice: "; cout<<"(R)ectange (T)riangle (C)ircle (E)end "; cin>>choice; //if choice is R if(choice=='R') { Task1(); } //if choice is T else if(choice=='T') { Task2(); Task3(); } //if choice is C else if(choice=='C') { Task4(); } }while(choice!='E');//terminate when E entered } //Main method int main() { //calling Menu function Menu(); }
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