/*********************************************** * * * * * CSCI 1470, Fall 2005 * * Machine Problem: MP8 * * Purpose: Use functions to manipulate * * two numbers * ***********************************************/ #include using namespace std; //Function prototypes void get_data(double&, double&); double max(double, double); double min(double, double); double total(double, double); double avg(double, double); void swap(double&, double&); using namespace std; int main(void) { double a, b; get_data(a,b); cout << endl << "Maximum of the numbers is: " << max(a, b) << endl << endl; cout << "Minimum of the numbers is: " << min(a, b) << endl << endl; cout << "The sum of the two numbers is: " << total(a, b) << endl << endl; cout << "The average of the two numbers is: " << avg(a, b) << endl << endl; cout << "The given numbers are: " << a << " and " << b << endl << endl; swap(a, b); cout << "The numbers after swap function: " << a << " and " << b << endl << endl; return 0; }//end of function main //reads two real values from the keyboard with a prompt void get_data(double& num_1, double& num_2) { cout << "Enter the first number: "; cin >> num_1; cout << endl << "Enter the second number: "; cin >> num_2; return; }//end of function get_data //returns the largest of the two real values double max(double num_1, double num_2) { if (num_1 > num_2) return num_1; else return num_2; }//end of function max //returns the smallest of the two real values double min(double num_1, double num_2) { if (num_1 < num_2) return num_1; else return num_2; }//end of function min //returns the sum of the two real values double total(double num_1, double num_2) { return num_1 + num_2; }//end of function total //returns the average of the two real values double avg (double num_1, double num_2) { return total(num_1, num_2)/2; }//end of function avg //exchanges the two values void swap(double& num_1, double& num_2) { double temp = num_1; num_1 = num_2; num_2 = temp; return; }//end of function swap