A function name having several definitions that are differentiable by the number or types of their arguments(signature), is known as function overloading.
#include <iostream.h>
#include <conio.h>
// Volume of a cube
double volume(float s)
{
double vol;
vol = (double) ( s * s * s);
return vol ;}
// volume of a cylinder
double volume(float r, float h)
{
double vol = (double)(3.14 * r * r * h);
return vol;
}
// volume of a rectangular box
double volume( float l, float b, float h)
{
double vol = (double) (l * b * h );
return vol;
}
void main()
{
double volume(float s);
double volume(float r, float h);
double volume ( float l, float b, float h);
/* Volume of a cube with side 3.6 unit */
double v = volume(3.6);
cout<< "\n The Volume of a cube = " << v << "Unit Cube";
/* Volume of a cylinder with radius 2.5 unit, height = 6 unit */
v = volume(2.5, 6);
cout<< "\n The Volume of a cylinder = " << v << "Unit Cube";
/* Volume of a rectangular box of l = 10, b =6 , h =4 units , respectively */
v = volume(10, 6, 4);
cout<< "\n The Volume of a rectangular box = " << v << "Unit Cube";
getch();
}
No comments:
Post a Comment