/*************************************************/
//moreSort3.cpp
//R. A. Hillyard
//October 15 2001
//Program to show function overloading of reference parameters
/*************************************************/

#include<iostream>

using namespace std;

void sort3(int& a, int& b, int& c);
void sort3(double& a, double& b, double& c);
void swap(int& a, int& b);
void swap(double& a, double& b);

int main()
  {
  char choice;
  int a = 0, b = 0, c = 0;
  double x = 0.0, y = 0.0, z = 0.0;
  
  cout << "Double or Ints [D/I]: ";
  cin >> choice;
  if(choice == 'I')
    {
    cout << " enter three ints: ";
    cin >>a>>b>>c;
    sort3(a,b,c);
    cout << "\n sorted: " << a << " " << b << " " << c << endl;
    }
  if(choice == 'D')
    {
    cout << " enter three doubles: ";
    cin >>x>>y>>z;
    sort3(x,y,z);
    cout << "\n sorted: " << x << " " << y << " " << z << endl;
    }
  return 0;
  }//end main

/*****************************************************************/
void sort3(int& a, int& b, int& c)
  {
  if(a > b)
    { swap(a,b); }
  if(a > c)
    { swap(a,c); }
  if(b > c)
    { swap(b,c); }
  }//end sort3

/*****************************************************************/
void swap(int& a, int& b)
  {
  int temp = a;
  a = b;
  b = temp;
  }//end swap

/*****************************************************************/
/*****************************************************************/
void sort3(double& a, double& b, double& c)
  {
  if(a > b)
    { swap(a,b); }
  if(a > c)
    { swap(a,c); }
  if(b > c)
    { swap(b,c); }
  }//end sort3

/*****************************************************************/
void swap(double& a, double& b)
  {
  double temp = a;
  a = b;
  b = temp;
  }//end swap

/**************************Program output*************************/
Double or Ints [D/I]: D
 enter three doubles: 6.6 4.3 8.2

 sorted: 4.3 6.6 8.2

/*****************************************************************/
Double or Ints [D/I]: I
 enter three ints: 8 2 9

 sorted: 2 8 9