Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.
Shade in the A or B circle for each question.
Draw a line connecting each item on the left to its match on the right.
| Left column | Right column | |
|---|---|---|
| 1Index | Total | Scores[Index] | ADECLARE Nums : ARRAY[1:5] OF INTEGER FOR Index ← 1 TO 6 OUTPUT Nums[Index] NEXT Index | |
| 2Scores[3] ← 7 (row 3 of the table) | BFOR Index ← 1 TO 3 Total ← Total + Nums[Index] NEXT Index OUTPUT Total | |
| 3Use a trace table to find the final OUTPUT by following the loop one pass at a time | CThe trace table starts at the wrong index. The loop begins at 0, which is below the lower bound of 1, so the first row should show Index = 0 and an error | |
| 4A trace table shows an off-by-one error when Index goes past the upper bound of the array | DColumn headings of a trace table: the loop variable, a running variable and the array element being used | |
| 5Trace table has only an Index column, with no column for Total or the array contents | EThe table is missing columns for the variables that change, so you cannot see the array contents or the running total after each pass | |
| 6FOR Index ← 0 TO 4 on ARRAY[1:5], trace starts with Index = 1 | FRecord the new array contents after the pass where Index is 3 |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
trace table — A table that records the loop variable, index and array contents after each pass of a loop, so you can predict the final OUTPUT and spot errors such as off-by-one.DECLARE Score : ARRAY[1:3] OF INTEGER
FOR Index ← 1 TO 3
OUTPUT Score[Index]FOR Index ← 1 TO 3
Total ← Total + Score[Index]
NEXT IndexDECLARE Mark : ARRAY[1:5] OF INTEGER
FOR Index ← 1 TO 5
OUTPUT Mark[Index]DECLARE Mark : ARRAY[0:2] OF INTEGER
FOR Index ← 0 TO 2
Mark[Index] ← Index * 2Total ← 0
Total ← Total + Score[1]
OUTPUT Total