Write a programme in c++ to find volume of cube, rectangular box, cylinder, cone and sphere using function overloading
Answers
Answer :
using namespace std;
float vol(int,int);
float vol(float);
int vol(int);
int main()
{
int r,h,a;
float r1;
cout<<"Enter radius and height of a cylinder:";
cin>>r>>h;
cout<<"Enter side of cube:";
cin>>a;
cout<<"Enter radius of sphere:";
cin>>r1;
cout<<"Volume of cylinder is"<<vol(r,h);
cout<<"\nVolume of cube is"<<vol(a);
cout<<"\nVolume of sphere is"<<vol(r1);
return 0;
}
float vol(int r,int h)
{
return(3.14*r*r*h);
}
float vol(float r1)
{
return((4*3.14*r1*r1*r1)/3);
}
int vol(int a)
{
return(a*a*a);
}
Sample Input
Enter radius and height of a cylinder:8 12
Enter side of cube:2
Enter radius of sphere:3
Sample Output
Volume of cylinder is2411.52
Volume of cube is8
Volume of sphere is113.04