Write a program that reads in three integers, then uses the function sort3(int&
ID: 3553129 • Letter: W
Question
Write a program that reads in three integers, then uses the function sort3(int& a, int& b, int& c)
that swaps its three arguments to arrange them in ascending sorted order. For example,
int v = 3;
int w = 4;
int x = 1;
sort3(v, w, x); // v is now 1, w is now 3, x is now 4
Hint: you can use the following sort2 function to implement your sort3 function:
/**
Swaps values of the parameters provided the first parameter
is larger than the second.
@param a first input value
@param b second input value
*/
void sort2(int& a, int& b)
{
if (a > b)
{
int temp = a;
a = b;
b = temp;
}
}
Provide a program that tests your function via a loop construct for acquiring testing data.
Enter three numbers or Q to quit: 2 1 3
Sorted: 1 2 3
Enter three numbers or Q to quit: 4 5 4
Sorted: 4 4 5
Enter three numbers or Q to quit: 3 2 -1
Sorted: -1 2 3
Enter three numbers or Q to quit: 0 15 10
Sorted: 0 10 15
Enter three numbers or Q to quit: Q