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

This program allows the user to enter 5 integers. There are no restrictionson th

ID: 3814704 • Letter: T

Question

This program allows the user to enter 5 integers. There are no restrictionson these integers. Your program should then sort the integers from small-est to largest using an if-else chain and then display the sorted list to the monitor. For example, if the file contains: 2 1 2 0 1, your program would display: 1 0 1 2 2

Requirements: Do not use loops or arrays in any way. Do not use any built-in C++ function that might be used for sorting. It is impractical to enumerate all possibilities in this case. Try to think of a sorting method which is easier to implement, using a series of if-else statements (probably

15 or fewer lines)

Explanation / Answer

#include <iostream>

using namespace std;

void swap(int& int1,int&int2)
{
int temp=int1;
int1=int2;
int2=temp;
}

int main ()
{
int int1;
int int2;
int int3;
int int4;

cout<<"Enter four integers here: "; // Enter four numbers.
cin >> int1;
cin >> int2;
cin >> int3;
cin >> int4;

if(int2<int1)
swap(int2,int1);
if(int3<int1);
swap(int3,int1);
if(int4<int1)
swap(int4,int1);
if(int3<int2);
swap(int3,int2);
if(int4<int2)
swap(int4,int2);
if(int4<int3)
swap(int4,int3);
cout<<"Enter four integers here: ";
cout<<"Sorted Integers are: "<<int1<<" "<<int2<<" "<<int3<<" "<<int4;
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