Array data types: INTEGER, REAL, CHAR, STRING, BOOLEAN

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

Array data types: INTEGER, REAL, CHAR, STRING, BOOLEAN

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which declaration suits ten whole-number test scores?
A DECLARE Scores : ARRAY[1:10] OF INTEGER
B DECLARE Scores : ARRAY[1:10] OF CHAR
2. Which declaration suits ten prices such as 2.50 and 7.99?
A DECLARE Prices : ARRAY[1:10] OF REAL
B DECLARE Prices : ARRAY[1:10] OF INTEGER
3. Which declaration can store the 26 letters of the alphabet, one letter per element?
A DECLARE Letters : ARRAY[1:26] OF CHAR
B DECLARE Letters : ARRAY[1:26] OF BOOLEAN
4. Which declaration suits 30 yes/no flags that record whether each student is present?
A DECLARE Present : ARRAY[1:30] OF REAL
B DECLARE Present : ARRAY[1:30] OF BOOLEAN
5. Which statement about the data type in ARRAY[1:10] OF INTEGER is true?
A Each element can have a different data type
B Every element must be an INTEGER

Match the Pairs

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

Left columnRight column
1DECLARE Prices : ARRAY[1:10] OF REAL AAn array of ten elements, each of which can hold a number with a decimal part, such as 2.50
2DECLARE Flags : ARRAY[1:30] OF BOOLEAN BDECLARE Letters : ARRAY[1:26] OF CHAR
3The array must store ten whole-number test scores, so the element data type is INTEGER CAn array of thirty elements, each of which can only hold TRUE or FALSE
4The array must store the 26 letters of the alphabet, one single character in each element DDECLARE Scores : ARRAY[1:10] OF INTEGER
5DECLARE Prices : ARRAY[1:10] OF INTEGER Prices[1] ← 2.50 EA BOOLEAN element can only hold TRUE or FALSE. The text "Yes" is a string, so it does not match the element data type. It should be Flags[1] ← TRUE.
6DECLARE Flags : ARRAY[1:30] OF BOOLEAN Flags[1] ← "Yes" FThe array is declared OF INTEGER, so its elements can only hold whole numbers. The decimal 2.50 does not fit. The type after OF should be REAL.

Definitions

ARRAY[1:10] OF INTEGER

Fill in the Blanks

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

1.
DECLARE Scores : ARRAY[1:10] OF _______
2.
DECLARE Prices : ARRAY[1:10] OF ____
3.
DECLARE Letters : ARRAY[1:26] OF ____
4.
DECLARE Present : ARRAY[1:30] OF _______
5.
DECLARE Names : ARRAY[1:30] OF ______ Names[1] ← "Ava"

Spot the Error

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

Question 1
A DECLARE L : ARRAY[1:3] OF TEXT
B L[1] ← 'A'
C OUTPUT L[1]
Question 2
A DECLARE P : ARRAY[1:3] OF REAL
B P[1] ← 2.50
C P[2] ← 1.75
D P[3] ← "cheap"
Question 3
A DECLARE L : ARRAY[1:3] OF CHAR
B L[1] ← 'AB'
C L[2] ← 'B'
D OUTPUT L[1]
Question 4
A // F: ARRAY[1:30] OF BOOLEAN
B F[1] ← TRUE
C F[2] ← FALSE
D F[3] ← 1
Question 5
A // N: ARRAY[1:5] OF STRING
B N[1] ← 42
C N[2] ← "Liam"
D OUTPUT N[1]

Answer Key

Array data types: INTEGER, REAL, CHAR, STRING, BOOLEAN
Section A: Quick Questions
Q1
A — DECLARE Scores : ARRAY[1:10] OF INTEGER
Q2
A — DECLARE Prices : ARRAY[1:10] OF REAL
Q3
A — DECLARE Letters : ARRAY[1:26] OF CHAR
Q4
B — DECLARE Present : ARRAY[1:30] OF BOOLEAN
Q5
B — Every element must be an INTEGER
Section B: Match the Pairs
Q1
DECLARE Prices : ARRAY[1:10] OF REAL → An array of ten elements, each of which can hold a number with a decimal part, such as 2.50
Q2
DECLARE Flags : ARRAY[1:30] OF BOOLEAN → An array of thirty elements, each of which can only hold TRUE or FALSE
Q3
The array must store ten whole-number test scores, so the element data type is INTEGER → DECLARE Scores : ARRAY[1:10] OF INTEGER
Q4
The array must store the 26 letters of the alphabet, one single character in each element → DECLARE Letters : ARRAY[1:26] OF CHAR
Q5
DECLARE Prices : ARRAY[1:10] OF INTEGER Prices[1] ← 2.50 → The array is declared OF INTEGER, so its elements can only hold whole numbers. The decimal 2.50 does not fit. The type after OF should be REAL.
Q6
DECLARE Flags : ARRAY[1:30] OF BOOLEAN Flags[1] ← "Yes" → A BOOLEAN element can only hold TRUE or FALSE. The text "Yes" is a string, so it does not match the element data type. It should be Flags[1] ← TRUE.
Section C: Definitions
Q1
ARRAY[1:10] OF INTEGER — The data type after OF decides what every element can hold. ARRAY[1:10] OF INTEGER holds ten whole-number scores; REAL, CHAR, STRING or BOOLEAN would hold other kinds of data.
Section D: Fill in the Blanks
Q1
DECLARE Scores : ARRAY[1:10] OF INTEGER
Q2
DECLARE Prices : ARRAY[1:10] OF REAL
Q3
DECLARE Letters : ARRAY[1:26] OF CHAR
Q4
DECLARE Present : ARRAY[1:30] OF BOOLEAN
Q5
DECLARE Names : ARRAY[1:30] OF STRING Names[1] ← "Ava"
Section E: Spot the Error
Q1
A — TEXT is not a data type after OF. An array of single letters is declared with CHAR: DECLARE L : ARRAY[1:3] OF CHAR.
Q2
D — The array is OF REAL, so every element must hold a number with a decimal part. The text "cheap" cannot be stored. It should be P[3] ← 3.20.
Q3
B — A CHAR element holds exactly one character. 'AB' is two characters, so it should be L[1] ← 'A'.
Q4
D — A BOOLEAN array can only hold TRUE or FALSE. The number 1 is an INTEGER, so it should be F[3] ← TRUE.
Q5
B — The array is OF STRING, so each element holds text in double quotes. 42 is an INTEGER, so it should be N[1] ← "Ava".