DECLARE and data types

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

DECLARE and data types

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which line correctly declares a variable to store a student's age in whole years?
A DECLARE Age : REAL
B DECLARE Age : INTEGER
2. Which line correctly declares a variable to store a price such as 4.99?
A DECLARE Price : REAL
B DECLARE Price : INTEGER
3. Which line correctly declares a variable to hold a player's name such as "Sam"?
A DECLARE PlayerName : STRING
B DECLARE PlayerName : CHAR
4. Which line correctly declares a variable to hold a single grade letter such as 'B'?
A DECLARE Grade : CHAR
B DECLARE Grade : STRING
5. Which line correctly declares a variable that stores either TRUE or FALSE?
A DECLARE IsPassed : INTEGER
B DECLARE IsPassed : BOOLEAN

Match the Pairs

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

Left columnRight column
1DECLARE Score : INTEGER AThe identifier x is not meaningful, so it does not show what the variable stores. A name like Age or Score is better, for example DECLARE Age : INTEGER.
2DECLARE Grade : CHAR BCreates a variable called Score that stores whole numbers only
3A variable that stores a number with a decimal part, such as a price CCreates a variable called Grade that stores a single character such as 'A'
4A variable that stores only TRUE or FALSE, such as whether a number was found DThe colon is missing between the identifier and the data type. It should be DECLARE Name : STRING.
5DECLARE Name STRING EDECLARE Price : REAL
6DECLARE x : INTEGER FDECLARE Found : BOOLEAN

Definitions

DECLARE Score : INTEGER

Fill in the Blanks

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

1.
DECLARE Score : _______ Score ← 25
2.
_______ Price : REAL Price ← 4.5
3.
DECLARE Initial : ____ Initial ← 'A'
4.
DECLARE IsPassed : _______ IsPassed ← TRUE
5.
DECLARE ______ : REAL Height ← 1.75

Spot the Error

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

Question 1
A DECLARE Score : INTEGER
B DECLARE Name STRING
C Score ← 0
D Name ← "Ava"
Question 2
A DECLARE Age : INTEGER
B DECLARE Height : REAL
C Height ← "1.65"
D Age ← 15
Question 3
A DECLARE Grade : CHAR
B DECLARE Passed : BOOLEAN
C Grade ← 'BA'
D Passed ← TRUE
Question 4
A DECLARE Lives : NUMBER
B Lives ← 3
C OUTPUT Lives
Question 5
A DECLARE IsOpen : BOOLEAN
B DECLARE Count : INTEGER
C Count ← 0
D IsOpen ← "TRUE"

Answer Key

DECLARE and data types
Section A: Quick Questions
Q1
B — DECLARE Age : INTEGER
Q2
A — DECLARE Price : REAL
Q3
A — DECLARE PlayerName : STRING
Q4
A — DECLARE Grade : CHAR
Q5
B — DECLARE IsPassed : BOOLEAN
Section B: Match the Pairs
Q1
DECLARE Score : INTEGER → Creates a variable called Score that stores whole numbers only
Q2
DECLARE Grade : CHAR → Creates a variable called Grade that stores a single character such as 'A'
Q3
A variable that stores a number with a decimal part, such as a price → DECLARE Price : REAL
Q4
A variable that stores only TRUE or FALSE, such as whether a number was found → DECLARE Found : BOOLEAN
Q5
DECLARE Name STRING → The colon is missing between the identifier and the data type. It should be DECLARE Name : STRING.
Q6
DECLARE x : INTEGER → The identifier x is not meaningful, so it does not show what the variable stores. A name like Age or Score is better, for example DECLARE Age : INTEGER.
Section C: Definitions
Q1
DECLARE Score : INTEGER — Creates a variable called Score with a stated data type. Types: INTEGER, REAL, STRING, CHAR, BOOLEAN. Pick a meaningful name.
Section D: Fill in the Blanks
Q1
DECLARE Score : INTEGER Score ← 25
Q2
DECLARE Price : REAL Price ← 4.5
Q3
DECLARE Initial : CHAR Initial ← 'A'
Q4
DECLARE IsPassed : BOOLEAN IsPassed ← TRUE
Q5
DECLARE Height : REAL Height ← 1.75
Section E: Spot the Error
Q1
B — The colon is missing. A declaration must be written DECLARE Name : STRING, with a colon between the identifier and the data type.
Q2
C — Height is declared as REAL, so it must hold a number. Quotes make 1.65 a STRING. It should be Height ← 1.65.
Q3
C — A CHAR holds exactly one character. 'BA' has two characters, so it should be Grade ← 'B'. Use STRING for longer text.
Q4
A — NUMBER is not a Cambridge data type. A whole number such as Lives must be declared as INTEGER, or as REAL if it has decimals.
Q5
D — A BOOLEAN can only hold TRUE or FALSE, written without quotes. With quotes it becomes a STRING. It should be IsOpen ← TRUE.