| 1. |
Write a menu driven program using functions to calculate the volume of a cube,sphere and cylinder. Use separate functions |
|
Answer» Write a menu driven PROGRAM using functions to calculate the VOLUME of a cube,sphere and cylinder. Use separate functions Explanation: #include using NAMESPACE std; float vol(float); int vol(int); float vol(int,int);
int main( ) { int r,h,a; float r1; cout << “Menu” < cout << “1-->Volume of Cylinder” < cout << “2-->Volume of Cube” < cout << “3-->Volume of Sphere” < cout << “ENTER the operation you want: ” < cin>>choice; switch(choice) { case 1: cout<<"Enter radius and height of the cylinder to calculate volume:"; cin>>r>>h; cout<<"Volume of cylinder is"< break; case 2: cout<<"Enter the side to calculate volume of a cube:"; cin>>a; cout<<"\nVolume of cube is"< break; case 3: cout<<"Enter the radius of sphere to calculate its volume:"; cin>>r1; cout<<"\nVolume of sphere is"< } return 0; } float volofCylinder(int *r,int *h) { return(3.14*(*r)*(*r)*(*h)); } float volofCube(float * r1) { return((4*3.14*(*r1)*(*r1)*(*r1)/3); } int volofSphere(int a) { return(a*a*a); } |
|