Script
#include <iostream>
using namespace std;
#include <string>
#include <cmath>
const double PI=3.14159;
double getPositiveValueRadius(string message1)
{
double number=0;
do
{
cout << message1 << endl;
cin >> number;
}
while (number <= 0);
return number;
}
double getPositiveValueHeight(string message2)
{
double number=0;
do
{
cout << message2 << endl;
cin >> number;
}
while (number <= 0);
return number;
}
double areaOfCircle(double center_to_end)
{
return PI*pow(center_to_end,2);
}
double volOfCylinder(double rad,double hght)
{
return PI*pow(rad,2)*hght;
}
int main()
{
double radius = getPositiveValueRadius("Enter the radius of the circle/cylinder: ");
double height = getPositiveValueHeight("Enter the height of the cylinder: ");
double aCircle = areaOfCircle(radius);
double vCylinder = volOfCylinder(radius,height);
cout << "The area of the circle that has a radius of " << radius << " inches is " << aCircle << " square inches." << endl;
cout << "The volume of the cylinder that has a radius of " << radius << " inches and ";
cout << "height of " << height << " inches is " << vCylinder << " cubic inches." << endl;
}
Execution
Enter the radius of the circle/cylinder:
5
Enter the height of the cylinder:
10
The area of the circle that has a radius of 5 inches is 78.5397 square inches.
The volume of the cylinder that has a radius of 5 inches and height of 10 inches is 785.398 cubic inches.
Enter the radius of the circle/cylinder:
7.87
Enter the height of the cylinder:
21.39
The area of the circle that has a radius of 7.87 inches is 194.58 square inches.
The volume of the cylinder that has a radius of 7.87 inches and height of 21.39 inches is 4162.07 cubic inches.
No comments:
Post a Comment