Loading....

Computer Science 0478 | Paper 2 Mock 01 | Algorithms, Programming and Logic

Question 1 Report

A home security system uses three sensors:

  • DoorOpen - TRUE if any door is open
  • WindowOpen - TRUE if any window is open
  • AlarmSet - TRUE if the alarm is armed

The alarm sounds when: the alarm is set AND (a door is open OR a window is open).

(a) Write the Boolean expression for the alarm sounding. [1]

(b) Complete the truth table. [4]

AlarmSetDoorOpenWindowOpenAlarm sounds?
FALSEFALSEFALSE
FALSETRUEFALSE
TRUEFALSEFALSE
TRUETRUEFALSE
TRUEFALSETRUE
TRUETRUETRUE

(c) Write pseudocode that implements this security system logic and outputs appropriate messages. [2]

(d) Write the Boolean expression for the alarm NOT sounding (using De Morgan's law). [1]

Answer Details

(a) The Boolean expression for the alarm sounding is:

AlarmSounds = AlarmSet AND (DoorOpen OR WindowOpen) [1]

The alarm requires the system to be armed AND at least one entry point to be open.

(b)

AlarmSetDoorOpenWindowOpenDoorOpen OR WindowOpenAlarm sounds?
FALSEFALSEFALSEFALSEFALSE
FALSETRUEFALSETRUEFALSE
TRUEFALSEFALSEFALSEFALSE
TRUETRUEFALSETRUETRUE
TRUEFALSETRUETRUETRUE
TRUETRUETRUETRUETRUE

When AlarmSet is FALSE (rows 1-2), the AND makes the result FALSE regardless of door/window state. [1] When AlarmSet is TRUE but both sensors are FALSE (row 3), the OR evaluates to FALSE. [1] When AlarmSet is TRUE and at least one sensor is TRUE (rows 4-6), the alarm sounds. [1] [1]

(c)

IF AlarmSet AND (DoorOpen OR WindowOpen) THEN
    OUTPUT "ALARM: Intruder detected!"
    IF DoorOpen THEN
        OUTPUT "Door breach detected"
    ENDIF
    IF WindowOpen THEN
        OUTPUT "Window breach detected"
    ENDIF
ELSE
    OUTPUT "System OK"
ENDIF

The Boolean expression is the IF condition. [1] Nested IFs identify which sensor(s) triggered. [1]

(d) Applying De Morgan's law:

NOT AlarmSet OR (NOT DoorOpen AND NOT WindowOpen) [1]

NOT (A AND B) = (NOT A) OR (NOT B), and NOT (C OR D) = (NOT C) AND (NOT D).

1
2
3
4
5
6
7
8
9
10
11