< previous page page_381 next page >

Page 381
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
       void DoThis( int& value1,
                    int& value2 )
       {
           int value3;

_____    cin >> value3  valuel;
_____    value2 = valuel + 10;
      }
14. If the program in Exercise 13 were run with the data values 10 and 15, what would be the values of the following variables just before execution of the return statement in the main function?
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
number1 _____ number2 _____ value3 _____
Programming Warm-Up Exercises
1. Write the function heading for a void function named PrintMax that accepts a pair of integers and prints out the greater of the two. Document the data flow of each parameter with /* in */, /* out */, or /* inout */.
2. Write the heading for a void function that corresponds to the following list.
Module Rocket Simulation
Incoming
thrust (floating point)
Incoming/Outgoing
weight (floating point)
Incoming
timeStep (integer)
Incoming
totalTime (integer)
Outgoing
velocity (floating point)
Outgoing
outOfFuel (Boolean)

3. Write a void function that reads in a specified number of float values and returns their average. A call to this function might look like
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
GetMeanOf(5, mean);
where the first parameter specifies the number of values to be read, and the second parameter contains the result. Document the data flow of each parameter with /* in */, /* out */, or /* inout */.
4. Given the function heading
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
void Halve( /* inout */ int& firstNumber,
            /* inout */ int& secondNumber )
write the body of the function so that when it returns, the original values in firstNumber and secondNumber are halved.
5. Add comments to the preceding Halve function that state the function precondition and postcondition.
6. a. Write a single void function to replace the repeated pattern of statements you identified in Case Study Follow-Up Exercise 3 of Chapter 3. Document the data flow of the formal parameters with /* in */, /* out */, or /* inout */. Include comments giving the function precondition and postcondition.
b. Show the function calls with actual parameters.

 
< previous page page_381 next page >