Question 1 Report
A theatre technician is writing a program to prepare lighting cues for a small touring production. For each cue, the operator enters a cue label, fade duration in seconds, a lantern channel number, a colour code and a safety-approved value. The program must calculate the total fade time, display the next cue, and prevent an operator from saving unsafe settings. The code will use arrays to store several cues and a subroutine to validate each channel number.
(a) State suitable data types for fadeDuration, cueLabel and safetyApproved. [3]
(b) Explain why a colour code such as R17 should not be stored as an integer. [2]
(c) Write pseudocode for a validation subroutine that accepts channel numbers from 1 to 48 inclusive and returns TRUE for a valid number. [5]
(d) Describe three test cases for this subroutine, including expected returned values. [3]
(e) Explain two benefits of using a subroutine rather than repeating the validation commands in the main program. [3]
(a) Suitable data types are:
fadeDuration: real/floating-point; [1]cueLabel: string/text; [1]safetyApproved: Boolean. [1](b) R17 contains a letter as well as digits, so it cannot be an integer. It is a code/identifier rather than a value used for calculation. [2]
(c) A suitable validation subroutine is:
SUBROUTINE validChannel(channel)
IF channel >= 1 AND channel <= 48 THEN
RETURN TRUE
ELSE
RETURN FALSE
ENDIF
ENDSUBROUTINEThe parameter receives the channel number; both inclusive boundary tests must be true for a valid channel. [5]
(d) Three suitable test cases are:
| Test input | Expected return | Reason |
|---|---|---|
| 1 | TRUE | Lower boundary is valid |
| 48 | TRUE | Upper boundary is valid |
| 49 | FALSE | Just above the maximum |
[3]
(e) A subroutine is written once and reused wherever the validation is needed. It reduces duplicated commands and maintenance effort, and any correction is made in one place. It can also be tested independently and keeps the main program easier to read. [3]
Everything you need to excel in your exams