CSE 232 Spring 2012 Name: __________________________________ Lab Exercise #4 -- C++ Functions and Modules A. C++ Functions and Parameters 1. Examine the C++ program below, and answer the questions about that program in the blanks provided. =============================================================================== int f( int, int&, int& ); int main() { int A = 5, B = 20, C = 15; cout << endl << f( A, B, C ) << endl; // Value of f: ____________ cout << "Value of A: " << A << endl; // Value of A: ____________ cout << "Value of B: " << B << endl; // Value of B: ____________ cout << "Value of C: " << C << endl; // Value of C: ____________ A = 15; B = 10; C = 5; cout << endl << f( A, B, C ) << endl; // Value of f: ____________ cout << "Value of A: " << A << endl; // Value of A: ____________ cout << "Value of B: " << B << endl; // Value of B: ____________ cout << "Value of C: " << C << endl; // Value of C: ____________ A = 25; B = 5; C = 10; cout << endl << f( A, B, C ) << endl; // Value of f: ____________ cout << "Value of A: " << A << endl; // Value of A: ____________ cout << "Value of B: " << B << endl; // Value of B: ____________ cout << "Value of C: " << C << endl; // Value of C: ____________ } int f( int X, int& Y, int& Z ) { if (X<10) { X = X + 10; } Y = Y - X / 2; if (Y > 8) { Z = Z - 12; } return X+Y+Z; } 2. After completing (1) above, translate and execute the C++ program to check your answers. Use the following commands to compile, link and execute the program: g++ /user/cse232/Labs/lab04.partA.cpp a.out If any of your answers are incorrect, re-work the appropriate questions. 3. In the C++ program shown on the previous page, locate and label each of the following: -- the declaration of function "f" -- the definition of function "f" -- all invocations of function "f" -- the formal arguments of function "f" -- the actual arguments of function "f" B. C++ Source Code Modules The files "lab04.driver.cpp" and "lab04.support.cpp" contain the outline of a C++ program, and the file "lab04.makefile" contains input to "make" which will control the translation of the program. 1. Examine "lab04.makefile" and answer the following questions. a) Give the command to translate the functions in "lab04.driver.cpp" into object code (which will be stored in the file named "lab04.driver.o"): b) Give the command to translate the functions in "lab04.support.cpp" into object code (which will be stored in the file named "lab04.support.o"): c) Give the command to link the object code functions into an executable program (which will be stored in the file named "lab04.run"): d) Give the "make" command which will run the commands in "lab04.makefile". 2. Modify "lab04.support.cpp" to complete the second "switch" statement so that the individual cases assign the correct result to "Value". 3. Modify "lab04.support.cpp" to allow the user to enter lower case letters for the units of measure. 4. Create an interface file named "lab04.support.h" which contans the declaration for function "ConvertLength". Then, modify "lab04.driver.cpp", "lab04.support.cpp" and "lab04.makefile" to utilize that interface file. 5. Test the completed program using a variety of input values, then demonstrate the results to your TA.