CONSTANT declarations

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

CONSTANT declarations

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which line correctly declares a constant in Cambridge pseudocode?
A DECLARE HourlyRate : CONSTANT 6.50
B CONSTANT HourlyRate ← 6.50
2. A shop's VAT rate is 20% and never changes while the program runs. What should you use to store it?
A CONSTANT VatRate ← 0.2
B INPUT VatRate
3. What can be on the right-hand side of ← in a CONSTANT declaration?
A A calculation using another variable
B A literal value such as 6.50
4. Which statement is true about a constant?
A Its value does not change while the program runs.
B Its value changes each time it is used in a calculation.
5. The hourly rate of 6.50 is used on 20 different lines. The rate changes to 7.00. Using CONSTANT HourlyRate ← 6.50, what do you need to do?
A Change the value on the one CONSTANT line
B Change the value on all 20 lines that use it

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 AThe assignment arrow ← is missing between the identifier and the value.
2CONSTANT MaxScore ← 100 BGives the fixed value 100 a meaningful name so the code is easier to read
3A constant's value can only be a literal, such as a number, text or TRUE/FALSE CCONSTANT HourlyRate ← 7.00
4To change a constant's value, you edit it in one place only, where it is declared DThe value is a calculation using a variable, not a literal. A constant can only be given a literal value.
5CONSTANT HourlyRate ← Hours * 6.50 EDeclares a constant called HourlyRate that always holds the literal value 6.50
6CONSTANT HourlyRate 6.50 FCONSTANT Pi ← 3.14

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 Pay ← Hours * __________
4.
// The pay rate rises to 7.00 CONSTANT HourlyRate ← ____
5.
// A class has 30 students CONSTANT ClassSize ← __

Spot the Error

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

Question 1
A CONSTANT HourlyRate ← 6.50
B DECLARE Hours : INTEGER
C INPUT Hours
D OUTPUT Hours + HourlyRate
Question 2
A CONSTANT MaxScore ← 50
B DECLARE Score : INTEGER
C INPUT Score
D MaxScore ← Score
Question 3
A DECLARE Total : REAL
B CONSTANT VatRate ← 0.1 + 0.1
C INPUT Total
D OUTPUT Total * VatRate
Question 4
A CONSTANT Pi ← 3.14
B DECLARE Radius : REAL
C INPUT Pi
D OUTPUT Pi * Radius ^ 2
Question 5
A DECLARE Count : INTEGER
B CONSTANT MaxItems = 10
C Count ← 0
D WHILE Count < MaxItems DO
E Count ← Count + 1
F ENDWHILE

Answer Key

CONSTANT declarations
Section A: Quick Questions
Q1
B — CONSTANT HourlyRate ← 6.50
Q2
A — CONSTANT VatRate ← 0.2
Q3
B — A literal value such as 6.50
Q4
A — Its value does not change while the program runs.
Q5
A — Change the value on the one CONSTANT line
Section B: Match the Pairs
Q1
CONSTANT HourlyRate ← 6.50 → Declares a constant called HourlyRate that always holds the literal value 6.50
Q2
CONSTANT MaxScore ← 100 → Gives the fixed value 100 a meaningful name so the code is easier to read
Q3
A constant's value can only be a literal, such as a number, text or TRUE/FALSE → CONSTANT Pi ← 3.14
Q4
To change a constant's value, you edit it in one place only, where it is declared → CONSTANT HourlyRate ← 7.00
Q5
CONSTANT HourlyRate ← Hours * 6.50 → The value is a calculation using a variable, not a literal. A constant can only be given a literal value.
Q6
CONSTANT HourlyRate 6.50 → The assignment arrow ← is missing between the identifier and the value.
Section C: Definitions
Q1
CONSTANT HourlyRate ← 6.50 — Names a fixed literal value that never changes while the program runs. It makes code easier to read, and you update the value in one place only.
Section D: Fill in the Blanks
Q1
CONSTANT HourlyRate ← 6.50
Q2
CONSTANT HourlyRate ← 6.50
Q3
CONSTANT HourlyRate ← 6.50 Pay ← Hours * HourlyRate
Q4
// The pay rate rises to 7.00 CONSTANT HourlyRate ← 7.00
Q5
// A class has 30 students CONSTANT ClassSize ← 30
Section E: Spot the Error
Q1
D — Pay is hours worked multiplied by the hourly rate. The line should use * (OUTPUT Hours * HourlyRate), not +.
Q2
D — A constant cannot be changed once it is declared. Assigning a new value to MaxScore is wrong. The line should only use MaxScore, for example in an OUTPUT.
Q3
B — A constant must be given a single literal value, not a calculation. It should be CONSTANT VatRate ← 0.2.
Q4
C — A constant's value is fixed in its declaration, so the user cannot INPUT a new one. The line should be INPUT Radius, the variable.
Q5
B — A constant is declared with the assignment arrow ←, not =. It should be CONSTANT MaxItems ← 10.