write a program in c++ to find volume of cube using function overloading in c++
Answers
#include<iostream.h>
#include<conio.h>
const float pi=3.14;
float vol(float l) //Cube
{
return l*l*l;
}
float vol(float r,float h) //Cylinder
{
return (pi*r*r*h);
}
float vol(float l,float b,float h)
{
return (l*b*h);
}
void main()
{
float l,r,b,h,t;
clrscr();
cout<<“\nEnter the Length of Cube: \n”;
cin>>l;
t=vol(l);
cout<<“\n\nVolume of Cube: “<<t;
cout<<“\n\nEnter the Radius & Hieght of Cylinder: \n”;
cin>>r>>h;
t=vol(r,h);
cout<<“\n\nVolume of Cylinder: “<<t;
cout<<“\n\nEnter the Length,Breadth & Hieght of Rectangle: \n”;
cin>>l>>b>>h;
t=vol(l,b,h);
cout<<“\n\nVolume of Rectangle: “<<t;
getch();
}
#include<iostream>
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);
}