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 wor...

Assessment: Computer Science 4CP0 | Paper 2 Mock 01 | Written Paper 2 Subject: Computer Science - 4CP0

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.

MAIN PROGRAMINPUT trackSecondsdisplayText <- makeLength(trackSeconds)CALL addToLog(displayText)DISPLAY displayTextFUNCTION makeLength(total)mins <- total DIV 60secs <- total MOD 60RETURN mins + ':' + secsPROCEDURE addToLog(text)WRITE text TO logFile© EAGLE BEACON GLOBAL

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]

Answer Details

(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]

Download The App On Google Playstore

Everything you need to excel in your exams

Green Bridge CBT Mobile App
Personalized AI Learning Chat Assistant
200,000+ Exam Questions Across IGCSE, JAMB, WAEC & NECO
Over 3,900 Lesson Notes
Offline Support - Learn Anytime, Anywhere
Green Bridge Timetable
Literature Summaries & Potential Questions
Track Your Performance & Progress
In-depth Explanations for Comprehensive Learning