#include <iostream.h>
/********************************************************
An example to demonstrate Function Overloading
********************************************************/
int main(){
int GetMax(int , int );
float GetMax(float , float );
int ival1, ival2;
float fval1, fval2;
cout << "Enter two integer values: ";
cin >> ival1 >> ival2;
cout << "Enter two float values: ";
cin >> fval1 >> fval2;
cout << "The larger of the two integers is " << GetMax(ival1,
ival2) << endl;
cout << "The larger of the two floats is " << GetMax(fval1, fval2)
<< endl;
return(0);
}
int GetMax(int v1 , int v2){
return(v1 > v2? v1: v2);
}
float GetMax(float v1 , float v2){
return(v1 > v2? v1: v2);
}
Output:
Enter two integer values: 57 62
Enter two float values: 3.145 3.142
The larger of the two integers is 62
The larger of the two floats is 3.145
Back to Previous Page
Document:
Local Date:
Last Modified On: