Question 1 Report
Fig. 1 shows code from a music archive program. A volunteer enters a track length in seconds. The main program uses the function makeLength to produce a word in minutes and seconds, then uses the procedure addToLog to write the word to a file. The archive manager wants the same formatting code to be available in several parts of the program.
The test input is trackSeconds = 185. The code editor uses integer division for DIV and remainder division for MOD.
(a) Identify the type of each subprogram in Fig. 1. [2]
(b) Use the code to state the values of mins, secs and displayText for the test input. [3]
(c) Complete the procedure call that writes the formatted value to the file. [2]
CALL addToLog(__________)
(d) Give three reasons why makeLength is preferable to repeating its algorithm wherever a track length is displayed. [3]
(a) makeLength is a function because it returns a formatted text value. addToLog is a procedure because it performs the action of writing to the file. [2]
(b) Integer division gives:
\[185\operatorname{DIV}60=3\]
and the remainder is:
\[185\operatorname{MOD}60=5\]
Thus mins = 3, secs = 5, and displayText = "3:5". [3]
(c)
CALL addToLog(displayText)
The argument must be the text returned by makeLength. [2]
(d) Using makeLength reduces repeated code, makes the main algorithm clearer and means only one copy must be corrected if the format changes. It can also be tested independently and reused wherever a length is needed. Any three valid reasons gain credit. [3]
Everything you need to excel in your exams