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:
The code below draws 4 different shapes. Rewrite the code into 4 separate functions that take appropriate arguments. These functions will only have side effects, returning void. Then, write a function that does the following:
Present a menu: "Enter (R)ectangle, (T)Triangle, 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)
// 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