< previous page page_247 next page >

Page 247
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
write a statement that sets leftPage to TRUE if pageNumber is even. (Hint: Consider what the remainders are when you divide different integers by two.)
5. Write an If statement (or a series of If statements) that assigns to the variable biggest the greatest value contained in variables i, j, and k. Assume the three values are distinct.
6. Rewrite the following sequence of If-Thens as a single If-Then-Else.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
if (year % 4 == 0)
    cout << year <  is a leap year. << endl;
if (year % 4 != 0)
{
    year = year + 4  - year % 4;
    cout << year <  is the next leap year. << endl;
}
7. Simplify the following program segment, taking out unnecessary comparisons. Assume that age is an int variable.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
if (age > 64)
    cout << Senior voter;
if (age < 18)
    cout << Under age;
if (age >= 18 && age < 65)
    cout << Regular voter;
8. The following program fragment is supposed to print out the values 25, 60, and 8, in that order. Instead, it prints out 50, 60, and 4. Why?
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
length = 25;
width = 60;
if (length = 50)
    height = 4;
else
    height = 8;
cout << length <   < width <   < height << endl;
9. The following C++ program segment is almost unreadable because of the inconsistent indentation and the random placement of left and right braces. Fix the indentation and align the braces properly.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
// This is a nonsense program
if (a > 0)
if (a < 20)
         {
    cout << A is in range. << endl;
b = 5;
    }
        else

 
< previous page page_247 next page >