Question
The included program found in main.cpp is designed to find the area of a rectangle, the area of a circle, or the volume of a
The included program found in main.cpp is designed to find the area of a rectangle, the area of a circle, or the volume of a cylinder.
However:
- the statements are in the incorrect order;
- the function calls are incorrect;
- the logical expression in the while loop is incorrect;
- the function definitions are incorrect;
- You may assume that the value of π = 3.14159.
Rewrite the program so that it works correctly. Your program must be properly indented. (Note that the program is menu driven and allows the user to run the program as long as the user wishes.)
Format your output with set precision (2) to ensure the proper number of decimals for testing!
using namespace std;
#include
int main()
{
string shape;
double height;
#include
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
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
}
Step by Step Solution
3.42 Rating (155 Votes )
There are 3 Steps involved in it
Step: 1
cpp code include include include using namespace std int main int ch infinity loop for keep asking t...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