Sunday, 30 June 2013

Write a C++ Program to demonstrate function Overloading

//Program demonstrating the concept of function overloading//

//Author- Ashish Mishra//

//Date - 30/06//2013//

#include<iostream>

using namespace std;

//Prototype declarations

int volume (int);
double volume (double, int);
long volume (long, int, int);

int main()
{
cout<<volume(10)<<"\n";
cout<<volume(2.5,8)<<"\n";
cout<<volume(100L, 75,15)<<"\n";

return 0;
}

//Function definitions

int volume (int s)                //volume of a cube
{
return (s*s*s);
}

double volume ( double r, int h) //volume of a cylinder
{
return (3.14159 *r*r*h);
}

long volume ( long l, int b, int h)  //volume of rectangle
{
return (l*b*h);
}

The output of this program will be

1000
157.08
112500

No comments:

Post a Comment

Thank you for commenting.