Declaring a constant with CONSTANT

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

Declaring a constant with CONSTANT

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which line correctly declares a constant for an hourly pay rate?
A DECLARE HourlyRate : CONSTANT
B CONSTANT HourlyRate ← 6.50
2. Does a constant need a DECLARE line before it?
A Yes, DECLARE must come first
B No, CONSTANT declares it on its own
3. What is the data type of CONSTANT HourlyRate ← 6.50 ?
A REAL, because 6.50 is a decimal literal
B INTEGER, because it is a number
4. Which line gives the constant DefaultText the value N/A?
A CONSTANT DefaultText ← "N/A"
B CONSTANT DefaultText : STRING ← "N/A"
5. After CONSTANT HourlyRate ← 6.50, which statement is not allowed later in the program?
A HourlyRate ← 7.00
B OUTPUT HourlyRate

Match the Pairs

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

Left columnRight column
1CONSTANT HourlyRate ← 6.50 ACONSTANT VATRate ← 0.20
2CONSTANT DefaultText ← "N/A" BA constant is given its value with the ← assignment arrow, not =. It should be CONSTANT DefaultText ← "N/A".
3A constant is declared with the CONSTANT keyword, an identifier, the ← operator and a literal value CDeclares a constant named DefaultText holding the string "N/A". No DECLARE line is needed because the text literal makes it a STRING.
4A constant needs no DECLARE line and no data type, because the data type comes from the literal DDeclares a constant named HourlyRate with the value 6.50, so it is a REAL. The value is set once and cannot change.
5DECLARE HourlyRate : REAL CONSTANT HourlyRate ← 6.50 EA constant must not have a DECLARE line or a data type. Remove the DECLARE line and keep only CONSTANT HourlyRate ← 6.50.
6CONSTANT DefaultText = "N/A" FCONSTANT MaxScore ← 100

Definitions

CONSTANT HourlyRate ← 6.50

Fill in the Blanks

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

1.
________ HourlyRate ← 6.50
2.
CONSTANT HourlyRate _ 6.50
3.
CONSTANT HourlyRate ← 6.50 OUTPUT __________ * 8
4.
CONSTANT HourlyRate ← 6.50 // Data type: ____
5.
CONSTANT DefaultText ← "N/A" // No _______ line is needed

Spot the Error

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

Question 1
A CONSTANT Rate : REAL ← 6.50
B DECLARE Hours : INTEGER
C DECLARE Pay : REAL
D Hours ← 8
E Pay ← Rate * Hours
Question 2
A DECLARE Name : STRING
B OUTPUT "Enter name"
C CONSTANT DefaultText ← N/A
D Name ← DefaultText
Question 3
A DECLARE Total : REAL
B CONSTANT HourlyRate = 6.50
C Total ← HourlyRate * 4
D OUTPUT Total
Question 4
A CONSTANT HourlyRate ← 6.50
B DECLARE Hours : INTEGER
C DECLARE MaxHours ← 40
D INPUT Hours
Question 5
A CONST DefaultText ← "N/A"
B DECLARE Reply : STRING
C Reply ← DefaultText
D OUTPUT Reply

Answer Key

Declaring a constant with CONSTANT
Section A: Quick Questions
Q1
B — CONSTANT HourlyRate ← 6.50
Q2
B — No, CONSTANT declares it on its own
Q3
A — REAL, because 6.50 is a decimal literal
Q4
A — CONSTANT DefaultText ← "N/A"
Q5
A — HourlyRate ← 7.00
Section B: Match the Pairs
Q1
CONSTANT HourlyRate ← 6.50 → Declares a constant named HourlyRate with the value 6.50, so it is a REAL. The value is set once and cannot change.
Q2
CONSTANT DefaultText ← "N/A" → Declares a constant named DefaultText holding the string "N/A". No DECLARE line is needed because the text literal makes it a STRING.
Q3
A constant is declared with the CONSTANT keyword, an identifier, the ← operator and a literal value → CONSTANT MaxScore ← 100
Q4
A constant needs no DECLARE line and no data type, because the data type comes from the literal → CONSTANT VATRate ← 0.20
Q5
DECLARE HourlyRate : REAL CONSTANT HourlyRate ← 6.50 → A constant must not have a DECLARE line or a data type. Remove the DECLARE line and keep only CONSTANT HourlyRate ← 6.50.
Q6
CONSTANT DefaultText = "N/A" → A constant is given its value with the ← assignment arrow, not =. It should be CONSTANT DefaultText ← "N/A".
Section C: Definitions
Q1
CONSTANT HourlyRate ← 6.50 — Declares a named value that is set once. No DECLARE line or data type is needed: the type comes from the literal, so 6.50 makes it REAL. The value cannot change later.
Section D: Fill in the Blanks
Q1
CONSTANT HourlyRate ← 6.50
Q2
CONSTANT HourlyRate ← 6.50
Q3
CONSTANT HourlyRate ← 6.50 OUTPUT HourlyRate * 8
Q4
CONSTANT HourlyRate ← 6.50 // Data type: REAL
Q5
CONSTANT DefaultText ← "N/A" // No DECLARE line is needed
Section E: Spot the Error
Q1
A — A CONSTANT line has no data type. The type comes from the literal, so 6.50 makes it REAL. It should be CONSTANT Rate ← 6.50.
Q2
C — A string literal must be in double quotes. Without them, N/A is not a valid value. It should be CONSTANT DefaultText ← "N/A".
Q3
B — A constant is given its value with the ← operator, not =. It should be CONSTANT HourlyRate ← 6.50.
Q4
C — DECLARE is for variables and needs a data type. A constant uses the CONSTANT keyword. It should be CONSTANT MaxHours ← 40.
Q5
A — The Cambridge pseudocode keyword is CONSTANT, not CONST. It should be CONSTANT DefaultText ← "N/A".