1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
#include <iostream>
using namespace std;
class Sort3
{
private:
float& first;
float& second;
float& third;
public:
Sort3(float& a, float& b, float& c) : first(a), second(b), third(c)
{
}
void swap(float& x, float& y)
{
float temp;
temp = x;
x = y;
y = temp;
}
void mySort(float& first, float& second, float& third)
{
if (first < second)
swap(first, second);
if (first < third)
swap(first, third);
if (second < third)
swap(second, third);
return;
}
};
int main()
{
float first, second, third;
cout << "Please enter the first integer: " << endl;
cin >> first;
cout << "Please enter the second integer: " << endl;
cin >> second;
cout << "Please enter the third integer: " << endl;
cin >> third;
Sort3 obj(first, second, third);
obj.mySort(first, second, third);
cout << "The three numbers in descending order: " << endl;
cout << first << ', ' << second << ', ' << third << endl;
return 0;
}
|