Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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

Explanation / Answer

#include #include using namespace std; int swapthree(float& dummya, float& dummyb, float& dummyc); int main() { float a, b, c; cout > a; cout > b; cout > c; if ( swapthree(a, b, c) ) { cout dummya) ) { float temp = dummyc; dummyc = dummya; dummya = temp; return 1; } else { return 0; } }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote