Procedures, Functions, Arrays and File Handling: Question 7
Syllabus 8.1
An online coding bootcamp uses a function, IsPassMark, to check whether a learner's score on a short quiz meets the pass mark required for that particular module.
FUNCTION IsPassMark(Score : INTEGER, PassMark : INTEGER) RETURNS BOOLEAN
IF Score >= PassMark
THEN
RETURN TRUE
ELSE
RETURN FALSE
ENDIF
ENDFUNCTION
DECLARE Result1 : BOOLEAN
DECLARE Result2 : BOOLEAN
Result1 ← IsPassMark(48, 50)
Result2 ← IsPassMark(72, 50) AND IsPassMark(72, 70)
OUTPUT Result1
OUTPUT Result2
What is displayed, in order, by the two OUTPUT statements above?
Show worked solution Hide worked solution
Worked solution
Step 1: Trace Result1 ← IsPassMark(48, 50)
Score = 48, PassMark = 50. Is 48 >= 50? No, so the ELSE branch runs: RETURN FALSE.
Result1 ← FALSE.
Step 2: Trace Result2 ← IsPassMark(72, 50) AND IsPassMark(72, 70)
Both function calls must be evaluated before the AND can be applied:
IsPassMark(72, 50):Score = 72,PassMark = 50. Is72 >= 50? Yes, soRETURN TRUE.IsPassMark(72, 70):Score = 72,PassMark = 70. Is72 >= 70? Yes, soRETURN TRUE.
Result2 ← TRUE AND TRUE = TRUE.
Step 3: Read off the two OUTPUT statements
OUTPUT Result1 displays FALSE. OUTPUT Result2 displays TRUE.
Displayed, in order: FALSE then TRUE, option B.
Final answer
- Result1 = FALSE, Result2 = TRUE
- Displayed, in order: FALSE then TRUE, option B