operation adds unknown values to the total. 6. A loop control variable controls the loop; an event counter simply counts certain events during execution of the loop. 7. Because there are five days in a business week, you would use a count-controlled loop that runs from 1 to 5. 8. Nest the original loop inside a count-controlled loop that runs from 1 to 52. 9. A countcontrolled loop. 10. Run the program with data sets that have a different number of females and males, only females, only males, illegal values (other characters), and an empty input file.
Exam Preparation Exercises
1. In one or two sentences, explain the difference between loops and branches.
2. What does the following loop print out? (number is of type int.)
number = 1;
while (number < 11)
{
number++;
cout << number << endl;
}
3. By rearranging the order of the statements (don't change the way they are written), make the loop in Exercise 2 print the numbers from 1 through 10.
4. When the following code is executed, how many iterations of the loop are performed?
number = 2;
done = FALSE;
while ( !done )
{
number = number * 2;
if (number > 64)
done = TRUE;
}
5. What is the output of this nested loop structure?
i = 4;
while (i >= 1)
{
j = 2;
while (j >= 1)
{
cout << j << ;
j--;
}
cout << i << endl;
i--;
}
6. The following code segment is supposed to write out the even numbers between 1 and 15. (n is an int variable.) It has two flaws in it.