This is a sample C++ program on function overloading. Using function overloading, this program can find area of figure like Cube, Sphere.
#include <iostream.h>
#include <conio.h>
#include <math.h>
void volume (int);
void volume (float);
void main()
{
int a, r,ch;
cout<<"*********MENU*********"<<'\n';
cout<<"1. Cube "<<'\n';
cout<<"2. Sphere "<<'\n';
cout<<"Enter Choice: ";
cin>>ch;
if (ch==1)
{
cout<<"Enter Side:";
cin>>a;
volume(a);
}
else if(ch==2)
{
cout<<"Enter Radius:";
cin>>r;
volume(r);
}
getch();
}
void volume(int a)
{
cout<<"Volume Of Cube = "<<a*a*a<<'\n';
}
void volume(float r)
{
cout<<"Volume Of Sphere = "<<(4/3)*3.14*pow(r,3);
}
OUTPUT:
*********MENU*********
1. Cube
2. Sphere
Enter Choice: 1
Enter Side :3
Volume Of Cube = 27
Comments
Post a Comment
Please share your opinions and suggestions or your experience in the comments section. This way we can all help each other...
Experienced guys can share their resumes at admin@interview-made-easy.com