Write a program which prompts the user for a measurement for radius and height a
ID: 3553671 • Letter: W
Question
Write a program which prompts the user for a measurement for radius and height and the uses six functions to compute the volume and surface areas for a sphere, cylinder, and cone. The output should be the results (with appropriate labels) for the six values along with the original radius and height.
Your program should also allow the programmer to perform the calculations for different values of the radius and height if desired. This means your program should ask if they want to continue after the first round of calculations.
The names of your functions should be:
sphere_volume
sphere_surface
cylinder_volume
cylinder_surface
cone_volume
cone_surface
Your program should be well documented with good variable names and good use of white space to enhance readability.
You should use five decimal places to approximate ?.
Explanation / Answer
#include <iostream>
#include <stdlib.h>
using namespace std;
void cone_surface()
{
cout<<"This program calculates the SA of a cone."<<endl;
float pi=3.14159;
float r;
cout<< "Enter the radius of the base of the cone?"<<endl;
cin>> r;
float basearea;
basearea= (r*r*pi);
float height;
cout<<"Enter the height of the cone?"<<endl;
cin>> height;
float SA;
SA= (basearea)+(pi*r*height);
cout<<endl;
cout<<"The answer is: "<<SA<<endl;
}
void cylinder_surface()
{
float pi=3.14159,r,SA,height;
cout<<"This program calculates the surface area of a cylinder,"<<endl;
cout<<"Enter the radius of the base"<<endl;
cin>> r;
cout<<"Enter the height of the cylinder"<<endl;
cin>>height;
float circumfrence=r*2*pi;
SA= 2*(3.14159)*(r*r)+2*(3.14159)*(r)*(height);
cout<<"The compute result is approximately: "<<SA<<endl;
}
void cylinder_volume()
{
float pi=3.14159,r,volume,height;
cout<<"This program calculates the volume of a cylinder,"<<endl;
cout<<"Enter the radius of the base?"<<endl;
cin>> r;
cout<<"Enter the height of the cylinder?"<<endl;
cin>>height;
float basearea=pi*r*r;
volume= (basearea)*(height);
cout<<"The compute result is approximately: "<<volume<<endl;
}
void sphere_surface()
{
float pi=3.14159,r,SA;
cout<<"This program calculates the surface area of a sphere"<<endl;
cout<<"Enter the radius of the sphere?"<<endl;
cin>> r;
float basearea=pi*r*r;
SA= basearea*4.0;
cout<<"The compute result is approximately: "<<SA<<endl;
}
void sphere_volume()
{
float pi=3.14159,r,volume;
cout<<"This program calculates the volume of sphere,"<<endl;
cout<<"Enter the radius of the sphere?"<<endl;
cin>> r;
volume=(4.0/3.0)*pi*r*r*r;
cout<<"The compute result is approximately: "<<volume<<endl;
}
void cone_volume()
{
cout<<"This program calculates the volume of a cone."<<endl;
cout<<""<<endl;
float pi=3.14159,pirsq,height,r,volume;
cout<<" Enter the radius of the base?"<<endl;
cin>> r;
cout<<"Enter the height of the cone?"<<endl;
cin>> height;
pirsq= pi*r;
volume= (.333333)*(pi)*(r*r)*(height);
cout<<"Enter the volume of the cone is approxmately:";
cout<< volume;
cout<<""<<endl;
}
int main(void)
{
while(1){
cout<<"------------------------------------------ ";
cout<<"------------**OPTIONS** ------------------ ";
cout<<"------1. find the SA of a sphere---------- ";
cout<<"------2. find the SA of a cone------------ ";
cout<<"------3. find the SA of a cylinder-------- ";
cout<<"------4. find the volume of a sphere------ ";
cout<<"------5. find the volume of a cone-------- ";
cout<<"------6. find the volume of a cylinder---- ";
cout<<"------------------------------------------ ";
cout<<"----- 7. Exit----------------------------- ";
int choice = 0;
cin>> choice;
if (choice == 1)
sphere_surface();
if (choice == 2)
cone_surface();
if (choice == 3)
cylinder_surface();
if (choice == 4)
sphere_volume();
if (choice == 5)
cone_volume();
if (choice == 6)
cylinder_volume();
if(choice==7)
break;
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.