The statement in the following program are in incorrect order. Rearrange the sta
ID: 3685149 • Letter: T
Question
The statement in the following program are in incorrect order. Rearrange the statements so that they prompt the user to input the shape type (rectangle, circle, or cylinder) and the appropriate dimension of the shape. The program then outputs the following information about the shape: For a rectangle, it outputs the area and perimeter, for a circle, it outputs the area and circumference; and for a cylinder, it output the volume and surface area. After rearranging the statements, your program should be properly indented.
using namespace std;
#include <iostream>
int main()
{
string shape;
double height;
#include <string>
cout << "Enter the shape type: (rectangle, circle, cylinder) ";
cin >> shape;
cout << end1;
if (shape == "rectangle")
{
cout << "Area of the circle = "
<< PI * pow(radius, 2.0) << end1;
cout << "Circumference of the circle: "
<< 2 * PI * radius << end1;
cout << "Enter the height of the cylinder: ";
cin >> height;
cout << end1;
cout << "Enter the width of the rectangle; ";
cin >> width;
cout << end1;
cout << "Perimeter of the rectangle = "
<< 2 * (length + width) << end1;
double width;
}
cout << "Surface area of the cylinder: "
<< 2 * PI * radius * height + 2 * PI * pow(radius, 2.0)
<< end1;
}
else if (shape == "circle")
{
cout << "Enter the radius of the circle; ';
cin >> radius;
cout << end1;
cout << "Volume of the cylinder = "
<< PI * pow(radius, 2.0)* height << end1;
double length;
}
return 0;
else if (shape == "cyclinder")
{
double radius;
cout << "Enter the length of the rectangle: ";
cin >> length;
cout << end1;
#include <iomanip>
cout << "Enter the radius of the base of the cylinder: ";
cin >> radius;
cout << end1;
const double PI = 3.1416;
cout << "Area of the rectangle = "
<< length * width << end1;
else
cout << "The program does not handle " << shape << end1;
cout << fixed << showpoint << setprecision(2) ;
#include <cmath>
}
Explanation / Answer
#include <iostream>
#include <iomanip>
#include <iomanip>
#include <cmath>
using namespace std;
const double PI = 3.1416;
int main()
{
string shape;
double height;
double width,length;
double radius;
#include <string>
cout << "Enter the shape type: (rectangle, circle, cylinder) ";
cin >> shape;
if (shape == "rectangle")
{
cout << "Enter the width of the rectangle; ";
cin >> width;
cout << "Enter the length of the rectangle: ";
cin >> length;
cout << "Area of the rectangle = " << length * width << endl;
cout << "Perimeter of the rectangle = " << 2 * (length + width) << endl;
}else if (shape == "circle")
{
cout << "Enter the radius of the circle; " ;
cin >> radius;
cout << "Area of the circle = " << PI * pow(radius, 2.0) << endl;
cout << "Circumference of the circle: " << 2 * PI * radius << endl;
} else if (shape == "cyclinder")
{
cout << "Enter the radius of the base of the cylinder: ";
cin >> radius;
cout << "Volume of the cylinder = " << PI * pow(radius, 2.0)* height << endl;
cout << "Surface area of the cylinder: "
<< 2 * PI * radius * height + 2 * PI * pow(radius, 2.0)
<< endl;
}else
cout << "The program does not handle " << shape << endl;
cout << fixed << showpoint << setprecision(2) ;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.