#include <iostream>
#include <iomanip>
using namespace std;
//function prototypes
void get_sentinel (char code);
void volume(float radius, float height,float& answer);
void surface_area (float radius, float height, float& answer);
void cross_area (float radius, float height, float& answer);
int main()
{
char code;
cout<<" WELCOME! Please enter in CAPITAL letters.\n"
" Enter V for volume, A for surface area, X for cross-sectional area,\n"" or Q to quit.\n";
cin>>code;
get_sentinel (code);
return 0;
}
void get_sentinel(char code)
{
float radius;
float height;
float answer;
while (code!= 'Q')
{
if(code == 'V')
{
cout<<" Please enter RADIUS and HEIGHT of the cylinder.\n"<<"*NOTE* Please enter in that order. (radius,height)"<<endl;
cin>>radius>>height;
volume(radius, height, answer);
cout<<" The VOLUME of the cylinder is\n"<<answer;
}
else if( code == 'A')
{
cout<<" Please enter RADIUS and HEIGHT of the cylinder.\n"<<"*NOTE* Please enter in that order. (radius,height)"<<endl;
cin>>radius>>height;
surface_area(radius, height, answer);
cout<<" The SURFACE AREA of the cylinder is\n"<<answer;
}
else if(code == 'X')
{
cout<<" Please enter RADIUS and HEIGHT of the cylinder.\n"<<"*NOTE* Please enter in that order. (radius,height)"<<endl;
cin>>radius>>height;
cross_area(radius, height, answer);
cout<<" The CROSS-SECTIONAL AREA of the cylinder is\n"<<answer;
}
cout<<"\n Please enter in CAPITAL letters.\n"
" Enter V for volume, A for surface area, X for cross-sectional area,\n"" or Q to quit. "<<endl;
cin>> code;
}
}
void volume(float radius, float height,float& answer)
{
const float PI=3.14159;
answer=height * (PI*(radius*radius)) ;
}
void surface_area (float radius, float height, float& answer)
{
const float PI=3.14159;
answer=((2 * (PI * (radius * radius))) + ((2 * PI * radius) * height));
}
void cross_area (float radius, float height, float& answer)
{
const float PI=3.14159;
answer=PI * (radius*radius);
}
|