ITPEC FE Subject B April 2024 Question 5
ITPEC FE Subject B April 2024 — Question 5 of 20
Converting total seconds into hours, minutes, and seconds using integer division and modulus.
The program converts a value in seconds (e.g., 5450) into hour, minute, second format (e.g., 1, 30, 50).
Step-by-step with `convert(5450)`:
second ← modulus(input, 60)→5450 mod 60 = 50— extracts the remaining seconds.- A (minute): First,
division(input, 60)=integer part of (5450 ÷ 60) = 90— total minutes. Thenmodulus(90, 60) = 30— minutes without full hours. So A =modulus(division(input, 60), 60). - B (hour):
division(input, 3600)=integer part of (5450 ÷ 3600) = 1— full hours. So B =division(input, 3600).
Why not others:
- (a) A = division(modulus(input, 60), 60) → division(50, 60) = 0, not 30
- (b) Same A as (a), fails for the same reason
- (c) Same A as (a); B = modulus(division(input, 60), 60) gives minutes (30), not hours
- (e) A is correct, but B = division(modulus(input, 60), 60) → division(50, 60) = 0, not 1
- (f) A is correct, but B = modulus(division(input, 60), 60) → 30 (minutes, not hours)
Key rule: To extract a middle unit (minutes from seconds), divide first to remove the smaller unit, then use modulus to remove the larger unit. For the largest unit (hours), divide by the full conversion factor (3600).
AI-generated — may contain errors
The original exam layout is preserved in the image so diagrams, formulas, tables, and code remain accurate.
This question comes from an official ITPEC past paper. ITPEC Practice is an independent study tool and is not affiliated with ITPEC. See the official FE past-paper collection or Report an issue.