SOURCE FILE: 07RefPrmSrtr.cpp
/* Example of the use of reference parameters to change variable
valuess. */
#include <iostream>
using namespace std ;
void swap (int &, int &) ;
void sort (int &, int&, int&) ;
void getValues (int &, int&, int&) ;
void writeValues (int &, int&, int&) ;
int main(void)
{
int val1, val2, val3 ;
getValues(val1, val2, val3) ;
sort (val1, val2, val3) ;
cout << "In sorted order, the values are: " << endl ;
writeValues (val1, val2, val3) ;
return 0;
}
/* Switch the values of x and y */
void swap (int & x, int & y)
{
int temp = x ;
x = y ;
y = temp ;
}
/* Input three numbers and return the same three in ascending order. */
void sort (int & a, int& b, int& c)
{
if (a > b) swap (a,b) ;
if (b > c) swap (b,c) ;
if (a > b) swap (a,b) ;
}
void getValues (int & i, int& j, int& k)
{
cout << "Please enter three integers (in any order): " ;
cin >> i >> j >> k ;
}
void writeValues (int & r, int& s , int& t)
{
cout << " First: " << r << endl ;
cout << "Second: " << s << endl ;
cout << " Third: " << t << endl ;
}