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 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
|
#include <iostream>
#include <ctime>
using namespace std;
void Sort(double* pNum1, double* pNum2, bool ascending);
double ReplaceIfGreater(double* pDouble, double input);
void Swap (double &a, double & b);
int main ()
{
double num1,num2,num3,num4;
cout << "please enter two doubles : " << endl;
cin >> num1;
cin >> num2;
Sort(&num1,&num2,true);
cout << " The doubles in ascending order are:" << num1 <<" , "<< num2<< endl;
Sort(&num1,&num2,false);
cout << "The doubles in descending order are:" << num1 <<" , "<< num2<< endl;
cout << "Please enter two more doubles:" << endl;
cin >> num3;
cin >> num4;
double value=ReplaceIfGreater(&num3, num4);
cout << "The return value of ReplaceIfGreater is " << value <<" and the pointer value is: "<< num4 << endl;
return 0;
}
void Sort(double* pNum1, double* pNum2, bool ascending)
{
double number1=*pNum1;
double number2=*pNum2;
if(ascending)
{
(number1 > number2);
Swap(number1, number2);
ascending=true;
}
else
{
(number1 > number2);
Swap(number1, number2);
ascending=false;
}
return;
}
double ReplaceIfGreater(double* pDouble, double input)
{
double FirstDouble= *pDouble;
if(FirstDouble>input)
{
Swap (FirstDouble, input);
return FirstDouble;
}
else
{
return input;
}
}
void Swap (double & a, double & b)
{
double x;
x = a;
a = b;
b = x;
}
|