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

Write a function named sortie that takes three integer parameters by reference a

ID: 3864731 • Letter: W

Question

Write a function named sortie that takes three integer parameters by reference and rearranges them in ascending order--the first parameter being the smallest, the third parameter being the largest. A comment in the file indicates where the function should be written.

#include<iostream>
using namespace std;

// WRITE YOUR sortie FUNCTION HERE

int main()
{
cout << "Enter three numbers ";
int first, second, third;
cin >> first >> second >> third;
cout << endl;
cout << "Unsorted: " << first << ", " << second << ", " << third << endl;
sortie(first, second, third);
cout << "Sorted: " << first << ", " << second << ", " << third << endl;
return 0;
}

Explanation / Answer

#include<iostream.h>
#include<conio.h>
void sort(int *a, int *b)
{
if(*a>=*b)
{
int temp = *b;
*b=*a;
*a=temp;
}
}

void sortie(int *first, int *second, int *third)
{
sort(first,second);
sort(second,third);
sort(first,third);
}


int main()
{
cout<<"Enter three numbers:";
int first,second,third;
cin>>first>>second>>third;
cout<<endl;
cout<<"Unsorted:"<<first<<","<<second<<","<<third<<endl;
sortie(&first, &second, &third);
cout<<"Sorted: "<<first<<","<<second<<","<<third<<endl;
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