SOURCE FILE: sortThree.cpp
/* This program uses functions with reference parameters
to sort a list of three numbers input by the user.
*/
#include <iostream>
using namespace std ;
void GetNumbers(int & x, int & y, int & z) ;
// get values for x, y, and z from user
void Sort(int & x, int & y, int & z) ;
// put x, y, and z in ascending order
void PrintOut(int x, int y, int z) ;
// print x, y, and z, in that order
void swap (int & x, int & y) ;
// interchange x and y
int main (void)
{
int i, j, k ;
GetNumbers(i, j, k) ;
Sort(i, j, k) ;
PrintOut(i, j, k) ;
return 0;
}
void GetNumbers(int & x, int & y, int & z)
{
cout << "\nPlease enter three integers: " ;
cin >> x >> y >> z ;
}
void Sort(int & x, int & y, int & z)
{
if (x > y) swap(x,y) ;
if (y > z) swap(y,z) ;
if (x > y) swap(x,y) ;
}
void swap (int & x, int & y)
{
int temp ;
temp = x ;
x = y ;
y = temp ;
}
void PrintOut(int x, int y, int z)
{
cout << "\nThe sorted list is: " ;
cout << x << " " << y << " " << z << endl << endl ;
}