< previous page page_496 next page >

Page 496
12. What is printed by the following program fragment? (All variables are of type int.)
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
for (row = 1; row <= 10; row++)
{
    for (col = 1; col <= 10 - row; col++)
        cout << *;
    for (col = 1; col <= 2*row - 1; col++)
        cout <<  ;
    for (col = 1; col <= 10 - row; col++)
        cout << *;
    cout << endl;
}
13. A break statement located inside a Switch statement that is within a While loop causes control to exit the loop immediately. (True or False?)
14. Given the For statement
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
for (count = 3; count <= 20; count++)
    cout << Hello << endl;
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
which one of the following invariants for count is correct just prior to the loop test?
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
a. 1< count < 20
b. 3< count < 20
c. 2< count < 20
d. 3< count < 21
e. 3< count < 21
Programming Warm-Up Exercises
1. Write a Switch statement that does the following:
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
If the value of grade is
A, add 4 to
sum
B, add 3 to sum
C, add 2 to sum
D, add 1 to sum
F, print Student is on probation
2. Modify the code for Exercise 1 so that an error message is printed if grade does not equal one of the five possible grades.
3. Rewrite the Day function of Chapter 8 (pages 406408), replacing the If-Then-Else-If structure with a Switch statement.
4. Write a program segment that reads and sums until it has summed 10 data values or until a negative value is read, whichever comes first. Use a Do-While loop for your solution.
5. Rewrite the following code segment using a Do-While loop instead of a While loop.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
cout << Enter 1, 2, or 3: ;
cin >> response;

 
< previous page page_496 next page >