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

Write a function which has 3 integer input values parameters which are 3 distinc

ID: 650897 • Letter: W

Question

Write a function which has 3 integer input values parameters which are 3 distinct integers unsorted. The function determines which number is the smallest the middle value and the largest value and puts them in 3 output parameters smallest, middle, largest. The function prototype is: void sort_3_numbers(int num1, int num2, int num3, int &smallest, int &middle, int &largest); Write a main program which Declares variables for both input and output. Asks the user for the 3 input values (3 distinct integers to sort) Calls the function by pass by reference Prints out the original integers and then Prints them the smallest, middle and largest values in order. Test with the following input values:

34 84 2012

56 2011 83

65 49 7

199 62 98

85 62 198

93 205 17

All of the input values should be tested in one program, not individually.

Explanation / Answer

You can test the values on user prompt for values: I dont have c++ compiler thats why cant test it. Just code I m writing , you can debug it on compilation:

#include <iostream>

using namespace std;

void sort_3_nos(int num1, num2, num3, &smallest, &middle, &largest);

void main()

{

int num1, num2, num3,&smallest, &middle, &largest;

clrscr();

cout<<"Enter three numbers" <<" ";

cin>>num1 >>num2>> num3;

sort_3_nos ( num1, num2, num3, &smallest, &middle, &largest)

}

sort_3_nos( a,b,c,smallest,middle,largest)

{

int a,b,c;

if (a>b && a>c)

largest = a;

else if (b>a && b>c)

largest = b;

else

largest = c;

}

if (a <b && a> c)

{

middle = a;

else if (b <a && b>c)

middle = b;

else

middle = c;

}

if (a<b && a<c)

{

smallest = a;

else if (b<a && b < c)

smallest = b;

else

smallest = c;

}

}

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