< previous page page_a55 next page >

Page A55
   while (temperature != -999)
   {
       // Update process

       cout << temperature << endl;
       if (temperature << low)        // Lowest temperature so far?
           low = temperature;
       if (temperature > high)       // Highest temperature so far?
           high = temperature;

       // Update loop ending condition

       cin >> temperature;
   }
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
This is a sentinel-controlled loop.
Chapter 7
Exam Preparation Exercises
4. 5 3 13
   3 3 9
   9 12 30
7. For pass-by-value, parts (a) through (g) are all valid. For pass-by-reference, only parts (a) and (c) are valid.
8. 13571 (the memory address of the variable widgets).
10. The answers are 12 10 3
11. Variables in main just before Change is called: a = 10 and b = 7. Variables in Change at the moment control enters the function (before any statements are executed): x = 10, y = 7, and the value of b is undefined. Variables in main after return from Change: a = 10 (x in Change is a value parameter, so the actual parameter is not modified) and b = 17.
Chapter 7
Programming Warm-Up Exercises
2. void RocketSimulation( /* in */    float    thrust,
                          /* inout */ float&  weight,
                          /* in */    int      timeStep,
                          /* in */    int      totalTime,
                          /* out */   float&   velocity,
                          /* out */   Boolean& outOfFuel )

5. void Halve( /* inout */ int& firstNumber,
               /* inout */ int& secondNumber )

   // Precondition:
   //     firstNumber and secondNumber are assigned

 
< previous page page_a55 next page >