int main()
{
int sum;
int i;
int number;
Boolean finished;
sum = 0;
i = 1;
finished = FALSE;
while (i <= LIMIT && !finished)
{
cin >> number;
if (number > 0)
sum = sum + number;
else if (number == 0)
finished = TRUE;
i++;
}
cout << End of test. << sum << << number << endl;
return 0;
}
and these data values:
5 6 -3 7 -4 0 5 8 9
a. What are the contents of sum and number after exit from the loop?
b. Does the data fully test the program? Explain your answer.
12. Write the invariant for an EOF-controlled loop that reads integer values, counts them, sums them, and sums the squares of the values.
13. Here is a simple count-controlled loop:
count = 1;
while (count < 20)
count++;
a. List three ways of changing the loop so that it executes 20 times instead of 19.
b. Which of those changes makes the value of count range from 1 through 21?
14. What is the output of the following program segment? (All variables are of type int.)