ITPEC FE Subject B April 2024 Question 1
From the answer group below, select the correct combination of answers to be inserted into A through C in the program.
A school determines the letter grade that a student will receive based on the score, which is an integer value between 0 and 100, as follows:
The function grade receives a score (non-negative integer value between 0 and 100) and returns the letter grade as a character.
Answer group
Explanation
A: ≥, B: "P", C: "F" — test the highest band first, so each later branch only sees the scores the earlier tests let through.
- •The first test must catch the whole 80–100 band, including 80 itself: A is
≥, givingscore ≥ 80. - •
elseif (score ≥ 50)is reached only when the score is below 80, so it covers 50–79, the Pass band: B is"P". - •The
elsebranch gets everything below 50, the Fail band: C is"F".
Check the boundaries: 100 and 80 give "D", 79 and 50 give "P", 49 and 0 give "F".
Answer (e)
Why not others:
- •(a) — A
=tests single values: only a score of exactly 80 gets "D" and exactly 50 gets "P"; 81–100 fall through to "F" - •(c) — A
>drops the boundary scores: 80 gets "P" instead of "D", and 50 gets "F" instead of "P" - •(f) — A is right, but B and C are swapped: 50–79 gets "F" and 0–49 gets "P"
- •(b) and (d) — the wrong operator of (a) and (c) respectively, plus the swapped grades of (f)
Key rule: In an if/elseif chain over descending thresholds, compare each lower bound with ≥; every later branch already carries the condition "below the previous bound".
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.