// This program allows you to practice with prototypes and // function calls for Lab 3. Note that the comments provided // in this program are to help you with the terminology. They // are NOT the type of comments you should place in your // programs in general. #include #include // The prototypes for power, power2 and absdiff are missing. // Place these prototypes here: int main() { int a, b; // Actual parameters used for power and power2 float c, d; // Actual parameters used for absdiff long p2_result, p_result; // Output from power and power2 float a_result; // Output from absdiff cout << "Please enter 2 integers (with a space between them): "; cin >> a >> b; // Place your function calls for power and power2 here: cout << endl << endl << 2 << "^" << a << " = " << p2_result << endl; cout << a << "^" << b << " = " << p_result << endl << endl << endl; cout << "Please enter 2 real numbers (with a space between them): "; cin >> c >> d; // Place your function call for absdiff here: cout << endl << endl << setiosflags(ios::fixed) << setprecision(3) << "|" << c << "-" << d << "| = " << a_result << endl << endl; return 0; } //////////////////////////////////////////////////////////////////// // THE FOLLOWING ARE THE FUNCTION IMPLEMENTATIONS. // // YOU DO NOT NEED TO UNDERSTAND THE CODE INSIDE THESE FUNCTIONS. // //////////////////////////////////////////////////////////////////// // Function implementation for power2 long power2 (int x) { return 1 << x; } // Function implementation for power long power (int x, int y) { long result = 1, i; for (i = 1; i <= y; ++i) result *= x; return result; } // Function implementation for absdiff float absdiff (float x, float y) { float diff = x-y; if (diff < 0) return -diff; else return diff; }