One-dimensional arrays

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

One-dimensional arrays

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which declaration creates a list of 10 whole numbers called Marks in Cambridge pseudocode?
A DECLARE Marks : INTEGER[10]
B DECLARE Marks : ARRAY[1:10] OF INTEGER
2. In ARRAY[1:10], what does the 1 stand for?
A The lower bound: the index of the first item
B The number of items stored in the array
3. In Cambridge pseudocode, which is the index of the first item in DECLARE Marks : ARRAY[1:10] OF INTEGER?
A Marks[0]
B Marks[1]
4. DECLARE Marks : ARRAY[1:10] OF INTEGER. How many items can Marks hold?
A 10 items, from Marks[1] to Marks[10]
B 9 items, from Marks[1] to Marks[9]
5. Which statement about the items in DECLARE Marks : ARRAY[1:10] OF INTEGER is true?
A Every item must be an INTEGER
B Some items can be INTEGER and some can be STRING

Match the Pairs

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

Left columnRight column
1DECLARE Marks : ARRAY[1:10] OF INTEGER ACreates an array called Names with 30 items, all of them STRING, from index 1 to index 30
2DECLARE Names : ARRAY[1:30] OF STRING BDECLARE Scores : ARRAY[1:5] OF INTEGER
3The lower bound of a Cambridge array is 1, so the first item is at index 1 and the upper bound 5 gives 5 items CCreates an array called Marks holding 10 whole numbers, numbered from index 1 to index 10
4All items in an array must be the same data type, such as REAL numbers for prices DCambridge arrays start at index 1, so the lower bound should be 1 and the upper bound 10 for 10 items, not [0:9].
5DECLARE Marks : ARRAY[0:9] OF INTEGER EThe data type is missing. An array declaration must say OF and give one type, such as OF INTEGER, for all the items.
6DECLARE Marks : ARRAY[1:10] FDECLARE Prices : ARRAY[1:8] OF REAL

Definitions

DECLARE Marks : ARRAY[1:10] OF INTEGER

Fill in the Blanks

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

1.
_______ Marks : ARRAY[1:10] OF INTEGER
2.
DECLARE Marks : _____[1:10] OF INTEGER
3.
DECLARE Marks : ARRAY[_:10] OF INTEGER
4.
DECLARE Marks : ARRAY[1:__] OF INTEGER
5.
DECLARE Names : ARRAY[1:30] OF ______

Spot the Error

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

Question 1
A DECLARE T : ARRAY[1:5] OF REAL
B T[1] ← 18.5
C T[6] ← 21.0
Question 2
A DECLARE T : ARRAY[1:5] OF REAL
B T[0] ← 18.5
C T[2] ← 21.0
D OUTPUT T[1]
Question 3
A DECLARE C : ARRAY[1:4] OF CHAR
B C[1] ← 'A'
C C[2] ← 'B'
D C[3] ← 7
Question 4
A DECLARE T : ARRAY(1:5) OF REAL
B T[1] ← 18.5
C T[5] ← 20.5
Question 5
A // Store 5 temperatures
B DECLARE T : ARRAY[5:1] OF REAL
C T[1] ← 18.5

Answer Key

One-dimensional arrays
Section A: Quick Questions
Q1
B — DECLARE Marks : ARRAY[1:10] OF INTEGER
Q2
A — The lower bound: the index of the first item
Q3
B — Marks[1]
Q4
A — 10 items, from Marks[1] to Marks[10]
Q5
A — Every item must be an INTEGER
Section B: Match the Pairs
Q1
DECLARE Marks : ARRAY[1:10] OF INTEGER → Creates an array called Marks holding 10 whole numbers, numbered from index 1 to index 10
Q2
DECLARE Names : ARRAY[1:30] OF STRING → Creates an array called Names with 30 items, all of them STRING, from index 1 to index 30
Q3
The lower bound of a Cambridge array is 1, so the first item is at index 1 and the upper bound 5 gives 5 items → DECLARE Scores : ARRAY[1:5] OF INTEGER
Q4
All items in an array must be the same data type, such as REAL numbers for prices → DECLARE Prices : ARRAY[1:8] OF REAL
Q5
DECLARE Marks : ARRAY[0:9] OF INTEGER → Cambridge arrays start at index 1, so the lower bound should be 1 and the upper bound 10 for 10 items, not [0:9].
Q6
DECLARE Marks : ARRAY[1:10] → The data type is missing. An array declaration must say OF and give one type, such as OF INTEGER, for all the items.
Section C: Definitions
Q1
DECLARE Marks : ARRAY[1:10] OF INTEGER — Creates an array called Marks: a named list of 10 items, numbered from lower bound 1 to upper bound 10. Every item must be the same data type, here INTEGER.
Section D: Fill in the Blanks
Q1
DECLARE Marks : ARRAY[1:10] OF INTEGER
Q2
DECLARE Marks : ARRAY[1:10] OF INTEGER
Q3
DECLARE Marks : ARRAY[1:10] OF INTEGER
Q4
DECLARE Marks : ARRAY[1:10] OF INTEGER
Q5
DECLARE Names : ARRAY[1:30] OF STRING
Section E: Spot the Error
Q1
C — The array is declared as ARRAY[1:5], so the upper bound is 5. Index 6 is outside the array. The line should use an index from 1 to 5, such as T[5] ← 21.0.
Q2
B — Cambridge arrays start at index 1, and this array has lower bound 1. Index 0 does not exist. The first item is T[1] ← 18.5.
Q3
D — Every item in an array must be the same data type. C is an array of CHAR, so it cannot hold the integer 7. The line should store a character, such as C[3] ← 'C'.
Q4
A — The bounds in an array declaration go in square brackets, not round brackets. It should be ARRAY[1:5].
Q5
B — The lower bound must come first and be smaller than the upper bound. [5:1] is back to front. It should be ARRAY[1:5].