Tuesday, December 8, 2009

Review of second of two sample midterms

Midterm 2, the DOC file

1) since it *terminates* when either is true, it is Until, rather than While. So we need to negate. So it is the opposite of the two conditions, coupled with an And. Therefore, D.

2) C

3) It reads it at the bottom of the loop, and checks it
at the top, before using it. Therefore, the letter "q" would be read but not used. That tells us either B or C. Now, each time it appends the letter at the *beginning* of what was read, rather than at the end. so it is nop reversed, which is pon. Thus, B.

4) This accumulates all the values in the file, finding its sum. Thus, B.

5) Num starts out at 7, but is incremented before it is ever printed. We can cross out anything involving a 7. Num is greater than 6, so the loop will not repeat. Afterwards, we print again. Therefore, 8 and 8, which is D.

6) We fill the array with those values. We start at the end, and skip one each time. Britain must be first, so either B or D. And since we skip, Beetoven cannot appear, so it must be D.

7) C

8) B

9) C, because H, B, D, B is not purely ascending or descending.

10) A, since there are 3 elements.

Part II
a) since it is not modified by the second loop, it would be whatever 70 * 70 is.

b) since we are copying the value from a(i+13) into that slot, and initially, a(11+13) was set from the first loop, it should have (11+13)^2, whatever that is.

Part III
Answer: The first two loops just fill the arrays A and B. The third loop increments a counter variable whenever the two arrays have the same element in the same position. The ones which are aligned are 3, 5, 3, I think. So c is 3. What will be output? I think 3.

No comments:

Post a Comment