Parallel arrays

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Parallel arrays

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. StudentNames[4] holds "Mia". Which element of Marks holds Mia's mark if the arrays are parallel?
A Marks[5]
B Marks[4]
2. Which statement describes parallel arrays?
A Two arrays of the same size where the same index holds related data
B One array whose elements are stored in two rows and two columns
3. Which loop reads a name and a mark for each student into parallel arrays (indexes 1 to 30)?
A FOR Index ← 1 TO 30 INPUT StudentNames[Index] INPUT Marks[Index + 1] NEXT Index
B FOR Index ← 1 TO 30 INPUT StudentNames[Index] INPUT Marks[Index] NEXT Index
4. A school stores names in StudentNames and marks in Marks. Which pair of declarations suits parallel arrays?
A ARRAY[1:30] OF STRING and ARRAY[1:30] OF INTEGER
B ARRAY[1:30] OF STRING and ARRAY[1:20] OF INTEGER
5. Can parallel arrays store different data types, such as STRING names and INTEGER marks?
A Yes, each array has one type but the arrays can differ
B No, all parallel arrays must use the same data type

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1OUTPUT StudentNames[3], Marks[3] ADisplays the name and the mark of the same student, because index 3 is used in both parallel arrays.
2DECLARE Marks : ARRAY[1:30] OF INTEGER BFOR Index ← 1 TO 30 INPUT StudentNames[Index] INPUT Marks[Index] NEXT Index
3One loop can read both parallel arrays, because the same index refers to the same student in each array. CDeclares an INTEGER array with 30 elements that can sit beside a 30-element names array, so each index matches one student.
4Parallel arrays can hold different data types for one record, such as STRING names and INTEGER marks. DDECLARE StudentNames : ARRAY[1:30] OF STRING DECLARE Marks : ARRAY[1:30] OF INTEGER
5DECLARE StudentNames : ARRAY[1:30] OF STRING DECLARE Marks : ARRAY[1:25] OF INTEGER EDifferent indexes are used, so the name of student 3 is shown with the mark of student 4, which are not related.
6OUTPUT StudentNames[3], Marks[4] FThe arrays have different lengths (30 and 25), so some students would have no matching mark and the indexes would not line up.

Definitions

parallel arrays

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
DECLARE StudentNames : ARRAY[1:5] OF ______
2.
DECLARE Marks : ARRAY[1:5] OF _______
3.
OUTPUT StudentNames[Index], Marks[_____]
4.
DECLARE StudentNames : ARRAY[1:30] OF STRING DECLARE Marks : ARRAY[1:__] OF INTEGER
5.
FOR Index ← 1 TO 30 OUTPUT StudentNames[Index], Marks[Index] NEXT _____

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A FOR I ← 1 TO 3
B INPUT Names[I]
C INPUT Marks[I]
D OUTPUT Names[I], Marks[I+1]
E NEXT I
Question 2
A // 5 students in each array
B FOR I ← 1 TO 6
C OUTPUT Names[I]
D OUTPUT Marks[I]
E NEXT I
Question 3
A Names[1] ← "Ava"
B Marks[1] ← 88
C Passed[1] ← "TRUE"
Question 4
A FOR I ← 1 TO 3
B OUTPUT Names[I]
C OUTPUT Marks[I]
D NEXT J
Question 5
A FOR I ← 1 TO 5
B IF Names[I] = "Zoe" THEN
C OUTPUT Names[I]
D ENDIF
E NEXT I

Answer Key

Parallel arrays
Section A: Quick Questions
Q1
B — Marks[4]
Q2
A — Two arrays of the same size where the same index holds related data
Q3
B — FOR Index ← 1 TO 30 INPUT StudentNames[Index] INPUT Marks[Index] NEXT Index
Q4
A — ARRAY[1:30] OF STRING and ARRAY[1:30] OF INTEGER
Q5
A — Yes, each array has one type but the arrays can differ
Section B: Match the Pairs
Q1
OUTPUT StudentNames[3], Marks[3] → Displays the name and the mark of the same student, because index 3 is used in both parallel arrays.
Q2
DECLARE Marks : ARRAY[1:30] OF INTEGER → Declares an INTEGER array with 30 elements that can sit beside a 30-element names array, so each index matches one student.
Q3
One loop can read both parallel arrays, because the same index refers to the same student in each array. → FOR Index ← 1 TO 30 INPUT StudentNames[Index] INPUT Marks[Index] NEXT Index
Q4
Parallel arrays can hold different data types for one record, such as STRING names and INTEGER marks. → DECLARE StudentNames : ARRAY[1:30] OF STRING DECLARE Marks : ARRAY[1:30] OF INTEGER
Q5
DECLARE StudentNames : ARRAY[1:30] OF STRING DECLARE Marks : ARRAY[1:25] OF INTEGER → The arrays have different lengths (30 and 25), so some students would have no matching mark and the indexes would not line up.
Q6
OUTPUT StudentNames[3], Marks[4] → Different indexes are used, so the name of student 3 is shown with the mark of student 4, which are not related.
Section C: Definitions
Q1
parallel arrays — Two or more arrays of the same size where the same index holds related data, e.g. StudentNames[3] and Marks[3] both describe the same student.
Section D: Fill in the Blanks
Q1
DECLARE StudentNames : ARRAY[1:5] OF STRING
Q2
DECLARE Marks : ARRAY[1:5] OF INTEGER
Q3
OUTPUT StudentNames[Index], Marks[Index]
Q4
DECLARE StudentNames : ARRAY[1:30] OF STRING DECLARE Marks : ARRAY[1:30] OF INTEGER
Q5
FOR Index ← 1 TO 30 OUTPUT StudentNames[Index], Marks[Index] NEXT Index
Section E: Spot the Error
Q1
D — Parallel arrays must use the same index for the same student. Marks[I+1] shows the next student's mark next to this name. It should be Marks[I].
Q2
B — Both arrays hold 5 items, so the loop must stop at 5. Going to 6 uses an index that does not exist in either array. It should be FOR I ← 1 TO 5.
Q3
C — Passed is a BOOLEAN array, so it can only store TRUE or FALSE, not a STRING. The quotes must be removed: Passed[1] ← TRUE.
Q4
D — The loop counter is I, so the loop must end with NEXT I. NEXT J names a variable that is not the loop counter, so the same index would not be used for both arrays.
Q5
C — Once Zoe is found at index I, her mark is in the parallel array at the same index. It should output Marks[I], not Names[I], which just repeats her name.