Overload the min() function. : Function Overloaded « Function « C++






Overload the min() function.

Overload the min() function.
 
#include <iostream>
#include <cctype>
using namespace std;

char min(char a, char b);
int min(int a, int b);
double min(double a, double b);

int main()
{
  cout << "Min is: " << min('x', 'a') << endl;
  cout << "Min is: " << min(10, 20) << endl;
  cout << "Min is: " << min(0.2234, 99.2) << endl;

  return 0;
}

// min() for chars
char min(char a, char b)
{
  return tolower(a)<tolower(b) ? a : b;
}

// min() for ints
int min(int a, int b)
{
  return a<b ? a : b;
}

// min() for doubles
double min(double a, double b)
{
  return a<b ? a : b;
}

           
         
  








Related examples in the same category

1.Functions differ in number of parametersFunctions differ in number of parameters
2.Overload abs() three waysOverload abs() three ways
3.Overload function: int and longOverload function: int and long
4.Create three functions called prompt( ) that perform this task for data of types int, double, and long
5.Overload function to accept integer or char * argumentOverload function to accept integer or char * argument
6.Compute area of a rectangle using overloaded functions.Compute area of a rectangle using overloaded functions.
7.Overload function: int and floatOverload function: int and float
8.function overloading between int and string type