Question 1 Report
At a skating rink, a ticket program checks whether a visitor qualifies for a child price. The visitor's age is entered as an integer in age. Child tickets are available to players and visitors who are under 13 years old. The skeleton program includes this command:
IF age < 13 THEN
price = 4.50
ENDIF
The manager wants the displayed price to be correct before a receipt is printed.
(a) Explain what the < relational operation tests. [1]
(b) When age is 13, state whether the statement in the IF block is carried out. [1]
(c) When the age is 12, explain why the assignment to price is carried out. [1]
In the dispatch program of a bicycle repair service, a mechanic enters the number of completed repairs into repairs. A bonus message is displayed only when the mechanic has completed between 12 and 20 repairs inclusive. The programmer must use relational operations in one selection statement.
(a) When repairs is 12, explain the result of repairs >= 12. [1]
(b) When repairs is 21, explain the result of repairs <= 20. [1]
(c) When both limits must be tested, write a complete condition using AND. [2]
Skating-rink program
< tests whether the value on its left is less than the value on its right. Here it tests whether age is less than 13. [1]age < 13 is false, so the statement inside the IF block is not carried out. [1]12 < 13 is true. Therefore the condition is true and price = 4.50 is carried out. [1]Bicycle-repair program
repairs >= 12 is true when repairs is 12, because >= includes the boundary value. [1]repairs <= 20 is false when repairs is 21, because 21 is greater than 20. [1]repairs >= 12 AND repairs <= 20 [2]Use AND for a value that must be within a range: it must be at least the lower limit and no more than the upper limit.
Everything you need to excel in your exams