ITPEC FE Subject B April 2025 Question 1

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

Centurial years refer to the years that are divisible by 100. The centurial years are not leap years except for years that are exactly divisible by 400. The non-centurial years, that is, years that are not divisible by 100, refer to leap years that are divisible by 4. The function isLeapYear receives an integer number year and returns true if a given year is a leap year or false otherwise.

[Program]
○ boolean: isLeapYear(integer: year) // returns true if the variable year
// is a leap year; otherwise, returns false
if (A)
return B
elseif (C)
return false
elseif (year mod 4 = 0)
return true
else
return false
endif

Answer group

OptionABC

Explanation

A: year mod 400 = 0, B: true, C: year mod 100 = 0 — an if/elseif chain returns at the first match, so the narrowest rule has to be tested first.

The three rules nest: every year divisible by 400 is divisible by 100, and every year divisible by 100 is divisible by 4. The chain must therefore run from the most specific test to the broadest:

  1. year mod 400 = 0 → return true (2000 is a leap year)
  2. year mod 100 = 0 → return false (1900 is not)
  3. year mod 4 = 0 → return true (2024 is), already in the program
  4. otherwise return false (2023 is not)

Check: 2000 stops at A and returns true. 1900 fails A and stops at C with false. 2024 fails A and C and reaches the mod 4 test, true. 2023 falls through to false.

Answer (f)

Why not others:

  • •(a) and (b) — A tests year mod 100 = 0 first, so every centurial year returns at B before the 400 rule is seen: (a) makes 2000 a common year, (b) makes 1900 a leap year.
  • •(c) and (d) — A = year mod 100 ≠ 0 catches every non-centurial year before the mod 4 test: (c) makes 2024 a common year, (d) makes 2023 a leap year.
  • •(e) — the right order of tests, but B = false makes 2000 a common year.
  • •(g) and (h) — A = year mod 400 ≠ 0 catches nearly every year at once: (g) makes 2024 a common year, (h) makes 2023 and 1900 leap years.

Key rule: When conditions nest, test the most specific case first; a broader test placed earlier swallows the exception.

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.