Write a full C++ program that computes the volume of a cylinder of radius, r, an
ID: 3806417 • Letter: W
Question
Write a full C++ program that computes the volume of a cylinder of radius, r, and length L (V_cyl = pi r^2 L) and part of the Area of a Cylinder (A_cyl = 2 pi r L/h) where h is some division(a section of the area). It starts by asking the user for a value of r and L; if r > 0 but 200 cm than the program calculates the area of a cylinder but it must ask for the h value or the division (or part of the area) wanted of the cylinder in that case. It outputs the area of the cylinder along with the h value. The program continues (it asks for another value of r then returns) until r = 0 which causes it to terminate. If r is out of the range then your program should produce a message to the user stating that fact. Extra credit Flow chart last programExplanation / Answer
#include <iostream>
#include <cmath>
long double calculateCylinderVolume(long double radius, long double L)
{
return 3.14 * radius * radius * L;
}
long double calculateCylinderArea(long double radius,long double L, long double height)
{
return ((2*3.14 * radius * L)/height);
}
int main()
{
do
{
std::cout << "Please enter the cylinder's radius: ";
long double radius;
std::cin >> radius;
std::cout << " Please enter the cylinder's L: ";
long double L;
std::cin >> L;
std::cout.precision(1000);
if(r >0 && r <=75)
{
std::cout << " The cylinder's volume is "
<< calculateCylinderVolume(radius, L) << ". ";
}else if(r <= 200)
{
long double height;
std::cin >> height;
std::cout << " The cylinder's area is "
<< calculateCylinderArea(radius, L,height) << ". ";
std::cout<< height;
}
else
{
std::cout<<" Invalid ";
}
}while (radius!=0)
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.