ITPEC FE Subject B April 2024 Question 5

From the answer group below, select the correct combination of answers to be inserted into A and B in the program.

The function division receives two integer values a and b and returns the quotient of a divided by b. The function modulus receives two integer values a and b and returns the remainder of a divided by b. The procedure convert receives the value of seconds as the input argument and outputs that value in the form of hours, minutes, and seconds. For example, when the procedure convert is called as convert(5450) the output is “1, 30, 50”. Here, suppose that the range of input values satisfy 0 ≤ input < 86400.

[Program]
○ convert(integer: input)
integer: hour, minute, second
second ← modulus(input, 60)
minute ← A
hour ← B
output hour, minute, second
○ integer: division(integer: a, integer: b)
integer: u
u ← integer part of (a ÷ b)
return u
○ integer: modulus(integer: a, integer: b)
integer: u
u ← a mod b
return u

Answer group

OptionAB

Explanation

A: modulus(division(input, 60), 60), B: division(input, 3600) — for minutes, convert to whole minutes and drop the full hours; for hours, divide by the seconds in an hour.

Trace for convert(5450):

  • •second: modulus(5450, 60) is 50.
  • •A: division(5450, 60) is 90 whole minutes, and modulus(90, 60) is the 30 minutes left over after the full hours.
  • •B: division(5450, 3600) is 1 whole hour.

The output is "1, 30, 50", as in the example. Because input is below 86400, the hour is at most 23 and needs no further reduction.

Answer (d)

Why not others:

  • •(a), (b) and (c) — A division(modulus(input, 60), 60) divides the leftover seconds (50) by 60; a remainder by 60 is always below 60, so the minutes are always 0
  • •(e) — B is that same always-0 expression, so the hour prints as 0
  • •(f) — B modulus(division(input, 60), 60) is the minute formula again, so the hour prints as 30

Key rule: To split a quantity into mixed units, divide by a unit's size to discard the smaller units, then take the remainder by the next unit's size to discard the larger ones; the largest unit needs only the division.

Math & Numbers · AI-written, may contain errors

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.