Question
---For the below code when asked to enter the radius and height for the cylinder enter 2 and 10. The program will then output the
---For the below code when asked to enter the radius and height for the cylinder enter 2 and 10. The program will then output the answers 3.89556 inch-sqr for the area of the cross section and 49.4738 inch-sqr for the side area. The cross section area is the correct answer, but the side area should be 19.474819. Please modify the code so that it outputs this correct answer.
In C++
#include
#include
using namespace std;
double PI = 3.14159; // This variable is defined globally, known to all functions in this program as PI
double cross_area(double r); // Function prototype for function cross_area
double side_area(double r, double h); // Function prototype for function Side_area
int main(void)
{
double h, r; //variables local to the main function
cout << "Enter the radius and the height of the cylinder in Cm
cin >> r >> h;
cout << endl;
cout << "Before I do any computation or call any function, I want to let you know that ";
cout << "you have entered r = " << r << " and h = " << h << "." << endl;
cout << "I am planning to use inch, thus in the first function, I will convert r, and " << endl;
cout << "in the second one I will convert h ";
cout << "The cross section area of the cylinder is " << cross_area(r) << " inch-sqr"<< endl;
cout << "The side area of the cylinder is " << side_area(r,h) << " inch-sqr ";
return 0;
}
double cross_area(double r)
{
//Cross secion area includes the disks at the bottom and the top
r = r * 0.3937; // converting r to inch
return 2*PI*pow(r,2);
}
double side_area(double r, double h)
{
double area; //variable local to Side_area function
h = h * 0.3937; // converting h to inch
area = 2*PI*r*h;
return area;
}
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