Study the following pseudocode that converts a number of seconds into hours, minutes and seconds. DECLARE TotalSeconds : INTEGER DECLARE Hours : INTEGER DEC...

Assessment: Computer Science 0478 | Paper 2 Mock 01 | Algorithms, Programming and Logic Subject: Computer Science - 0478

Question 1 Report

Study the following pseudocode that converts a number of seconds into hours, minutes and seconds.

DECLARE TotalSeconds : INTEGER
DECLARE Hours : INTEGER
DECLARE Minutes : INTEGER
DECLARE Seconds : INTEGER

INPUT TotalSeconds

Hours ← TotalSeconds DIV 3600
TotalSeconds ← TotalSeconds MOD 3600
Minutes ← TotalSeconds DIV 60
Seconds ← TotalSeconds MOD 60

OUTPUT Hours, ":", Minutes, ":", Seconds

(a) Complete the trace table for the input TotalSeconds = 7384. [4]

StepTotalSecondsHoursMinutesSeconds
Input
Hours calc
Remaining secs
Minutes calc
Seconds calc

(b) State the output. [1]

(c) Explain the difference between the DIV and MOD operators. [1]

Answer Details

(a) The algorithm converts a total number of seconds into hours, minutes, and remaining seconds using DIV (integer division) and MOD (remainder):

StepTotalSecondsHoursMinutesSeconds
Input7384---
Hours calc73847384 DIV 3600 = 2--
Remaining secs7384 MOD 3600 = 1842--
Minutes calc1842184 DIV 60 = 3-
Seconds calc18423184 MOD 60 = 4

The key insight is that DIV extracts the whole units (hours or minutes) and MOD gives the remainder that still needs to be broken down further. [4]

(b) The output is: 2:3:4 (2 hours, 3 minutes, 4 seconds). [1]

(c) DIV performs integer division, returning only the whole number part and discarding the remainder. For example, 7384 DIV 3600 = 2 (not 2.051...). MOD returns only the remainder after integer division. For example, 7384 MOD 3600 = 184. Together, they allow decomposition of a large value into its component parts. [1]

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