Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.
This Using an expression as an array index worksheet is part of the IGCSE Computer Science 0478 — 8.2 Arrays journey. Print it as a booklet?
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 | |
|---|---|---|
| 1Scores[n + 1] | AWorks out n + 1 first, then uses the element at that index, the one after position n | |
| 2Scores[n - 1] | BWorks out n - 1 first, then uses the element at that index, the one before position n | |
| 3Copy the value in element n into the next element along | Cn - 1 works out to 0, which is below the lower bound of 1, so the index is out of range | |
| 4Check that n + 1 stays within the bounds of an array declared ARRAY[1:10] before using it | DStudentNames[n + 1] ← StudentNames[n] | |
| 5StudentNames[n + 1] ← StudentNames[n] when n = 10 and the array is ARRAY[1:10] | En + 1 works out to 11, which is above the upper bound of 10, so the index is out of range | |
| 6StudentNames[n - 1] ← StudentNames[n] when n = 1 and the array is ARRAY[1:10] | FIF n + 1 <= 10 THEN StudentNames[n + 1] ← StudentNames[n] ENDIF |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
Array[n+1] — An index can be an expression like n+1. The expression is worked out first, then that element is used. It must stay within the array's bounds. Example: n=3 gives Array[4].StudentNames[n+1] ← StudentNames[n]Diff ← Marks[n] - Marks[n-1]n ← 3
OUTPUT Scores[n+1]
// Shows element Scores[4]IF n + 1 <= 10 THEN
Names[n + 1] ← Names[n]
ENDIF// Names is ARRAY[1:10]
FOR n ← 1 TO 9
Names[n + 1] ← Names[n]