Write a menu driven program using functions to calculate the volume of a cube,sphere and cylinder. Use separate functions
Answers
Write a menu driven program using functions to calculate the volume of a cube,sphere and cylinder. Use separate functions
Explanation:
#include<iostream>
using namespace std;
float vol(float);
int vol(int);
float vol(int,int);
int main( )
{
int r,h,a;
float r1;
cout << “Menu” <<endl;
cout << “1-->Volume of Cylinder” <<endl;
cout << “2-->Volume of Cube” <<endl;
cout << “3-->Volume of Sphere” <<endl;
cout << “Enter the operation you want: ” <<endl;
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"<<vol(&r,&h);
break;
case 2:
cout<<"Enter the side to calculate volume of a cube:";
cin>>a;
cout<<"\nVolume of cube is"<<vol(&a);
break;
case 3:
cout<<"Enter the radius of sphere to calculate its volume:";
cin>>r1;
cout<<"\nVolume of sphere is"<<vol(r1);
}
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);
}