CSE 232 Spring 2012 Name: __________________________________ Lab Exercise #5 -- C++ Functions and Modules A. The "make" Utility Copy all of the files named "~cse232/Labs/lab05.*" into your account, then perform the following experiments. 1. Use the "make" utility to control the translation of the program: make -f lab05.makefile Name the files which are created by this command, and explain what is contained in each file: _______________________________________________________________________________ _______________________________________________________________________________ _______________________________________________________________________________ 2. Enter the "make" command again: make -f lab05.makefile (or, "!make" to use history substitution) What results are reported, and why? _______________________________________________________________________________ _______________________________________________________________________________ 3. Edit your copy of "lab05.driver.cpp" and make some cosmetic change to the source code (modify a comment or the spacing of some statement, for example). Then, enter the "make" command again. What files are created by this operation, and why? _______________________________________________________________________________ _______________________________________________________________________________ 4. Edit your copy of "lab05.support.h" and make some cosmetic change to the source code. Then, enter the "make" command again. What files are created by this operation, and why? _______________________________________________________________________________ _______________________________________________________________________________ 5. What criteria is "make" using to decide whether or not to re-create a given object code file? _______________________________________________________________________________ _______________________________________________________________________________ _______________________________________________________________________________ B. Scope and Lifetime Recall that one of the attributes of an identifier is its scope (file scope or block scope); an identifier which represents a data object also has a lifetime associated with it (program lifetime or block lifetime). 1. Examine the contents of "lab05.driver.cpp" and complete the following chart. Identifier Scope Lifetime cin ____________ ____________ cout ____________ ____________ InputStatus ____________ ____________ RootStatus ____________ ____________ Root2 ____________ ____________ 2. Examine the contents of "lab05.support.cpp" and complete the following chart. Identifier Scope Lifetime cin ____________ ____________ cout ____________ ____________ InputStatus ____________ ____________ Flag ____________ ____________ Discriminant ____________ ____________ 3. Revise "lab05.support.h" to include the declaration of "InputStatus", but not the statement where storage is allocated. That is, the following statement should be moved into "lab05.support.h": extern int InputStatus; However, the following statement should remain in "lab05.support.cpp": int InputStatus; Use the "make" file to translate the program, then execute it and verify that it still has the same behavior. 4. In general, it is a good idea to avoid the use of "global" variables (ones with file scope and program lifetime) because they can be modified via an assignment operation in any function that is part of the program. Eliminate the global variable "InputStatus" from the program. Then, revise the declaration and definition of function "coefficients" so that it returns the input status to the callng function via a "return" statement. Use the "make" file to translate the program, then execute it and verify that it still has the same behavior. 5. Demonstrate the final version of the program to your TA.