// FILE: Sort3Nmb.cpp // READS THREE FLOATING POINT NUMBERS AND SORTS THEM IN ASCENDING // ORDER #include // Functions used ... // SORTS A PAIR OF FLOATING POINT NUMBERS void order (double&, double&); // INOUT: numbers to be ordered int main () { // Local data ... double num1, num2, num3; // input: holds numbers to be sorted // Read and sort numbers. cout << "Enter 3 numbers to be sorted separated by spaces:" << endl; cin >> num1 >> num2 >> num3; order (num1, num2); // order the data in num1 and num2 order (num1, num3); // order the data in num1 and num3 order (num2, num3); // order the data in num2 and num3 // Print results. cout << "The three numbers in order are:" << endl; cout << num1 << " " << num2 << " " << num3 << endl; return 0; } //end main // SORTS A PAIR OF NUMBERS REPRESENTED BY x AND y void order (double& x, double& y) // INOUT: numbers to be ordered // Pre: x and y are assigned values. // Post: x is the smaller of the pair and y is the larger. { // Local data ... double temp; // temp holding cell for number in x // Compare x and y and exchange values if not properly ordered. if (x > y) { // exchange the values in x and y temp = x; // store old x in temp x = y; // store old y in x y = temp; // store old x in y } // end if } // end order