Question 1 Report
Fig. 1 shows a smart-home program that decides whether a window should be closed. The window closes if rain is detected, or if the outside temperature is below 2 degrees C and the house is empty. The temperature comparison creates veryCold. A resident is at home while the temperature is below 2 degrees C and no rain is detected. The programmer wants to predict the command before running a test, because closing the window unnecessarily would be inconvenient.
(a) Explain why houseOccupied is preceded by NOT. [2]
(b) When rainDetected is False, veryCold is True and houseOccupied is True, state the value of closeWindow. [1]
(c) When rainDetected is True, state the value of closeWindow. [1]
Fig. 1 shows an electronic scoreboard program for a wheelchair basketball game. At the end of a turn, the program awards a bonus if the player scored at least 10 points and did not commit a foul. The two comparison statements are evaluated before the IF statement runs. A trainee has placed brackets around the NOT operation. The referee wants to know whether the command works correctly when a player earns 12 points but commits a foul during the same turn.
(a) Explain why the second condition uses NOT foul. [2]
(b) When points >= 10 is True and foul is True, state whether the bonus is awarded. [1]
(c) When the player scores 8 points and does not foul, state whether the bonus is awarded. [1]
Smart-home condition
houseOccupied is True, NOT houseOccupied is False, preventing the cold-and-empty part of the condition from closing the window. [1]NOT houseOccupied is False, so True AND False is False; False OR False gives False. [1]rainDetected is True, the OR condition is True regardless of the other values. Therefore closeWindow is True. [1]Basketball-bonus condition
NOT foul is True only when foul is False, so it correctly represents the requirement of no foul. [1]foul is True, then NOT foul is False. True AND False is False, so the bonus is not awarded. [1]points >= 10 False. Even without a foul, False AND True is False, so the bonus is not awarded. [1]Everything you need to excel in your exams