Download this source file
// MaxOvrld.cpp - A program to show overloaded functions.
//
// Written by: Wayne Pollock, Tampa Florida, 1998
#include
#include
int max ( int x, int y )
{
if ( x > y )
return x;
else
return y;
}
float max ( float x, float y )
{
if ( x > y )
return x;
else
return y;
}
int main ()
{
// Set float values to show 2 places including trailing zeros:
cout << setprecision( 2 )
<< setiosflags( ios::fixed | ios::showpoint );
int i = 5, j = 12;
cout << "The max of " << i << " and " << j
<< " is " << max( i, j ) << "." << endl;
float a = 98.6, b = 3.1415;
cout << "The max of " << a << " and " << b
<< " is " << max( a, b ) << "." << endl;
return 0;
}
#ifdef COMMENTED_OUT
======================Output of Above Program:=========================
The max of 5 and 12 is 12.
The max of 98.60 and 3.14 is 98.60.
#endif