Question
THERE ARE 2 QUESTIONS, AND PLEASE READ THEM CAREFULLY. I NEED BOTH QUESTIONS TO BE SOLVED. IF YOU ARE NOT SURE WHAT TO DO, PLEASE,
THERE ARE 2 QUESTIONS, AND PLEASE READ THEM CAREFULLY. I NEED BOTH QUESTIONS TO BE SOLVED. IF YOU ARE NOT SURE WHAT TO DO, PLEASE, PLEASE, SKIP MY QUESTION. I WILL GIVE NEGATIVE RATING FOR WRONG OR INCOMPLETE ANSWER.
THANK YOU.
Question:
The code below draws 4 different shapes.
1- Add a Switch Statement to the ACTUAL CODE. Menu should look like this;
Menu should look like this:
Press 1 for Rectangle:
Press 2 for Triangle (North to West):
Press 3 for Triangle (South to EasT):
Press 4 for Circle:
Press 5 to end this program:
2- Validate the input values for Menu Choice by using cin.clear() and cin.ignore(), and they must be used like in given example below;
EXAMPLE:
int main() {
int choice = -1;
// function ( cin >> choice) will return false, if choice is not a type of int.
while (!(cin >> choice)) {
cout << "input again!" << endl;
cin.clear();
cin.ignore();
}
cout << "choice is a int = " << choice << endl;
}
// THE ACTUAL CODE STARTS HERE
#include
#include
#include
using namespace std;
int main()
{
// Task 1 : Draw a w-wide h-high rectangular frame, using asterisks.
int width, height, length;
cout<< "Task 1: Rectangular Frame"< cout<< "Enter width: "; cin>>width; cout<< "Enter height: "; cin>>height; 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 << endl; // Task 2: Draw the triangle constituting the northwestern half of a square, given the side length. cout<< "Task 2 North to West"< cout<< "Enter length: "; cin>>length; for(int i=length; i >= 1; i--) { for(int j=1; j<=i; j++) { cout<< "*"; } cout<< " "; } cout< // Task 3: Draw the triangle constituting the southeastern half of a square, given the side length. cout<< "Task 3: South to East"< cout<< "Enter length: "; cin>>length; 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< // Task: 4 Given a radius, draw a circle with that radius. 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; } return 0; }
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