logo

Question detail

An alarm should sound when a door is open and either the security code is invalid or a window is open.\n\na) Write a Boolean expression for the alarm condition using DoorOpen, CodeValid and WindowOpen.\nb) Evaluate the expression for each case below:\n\n1. DoorOpen = true, CodeValid = true, WindowOpen = true\n2. DoorOpen = true, CodeValid = false, WindowOpen = false\n3. DoorOpen = false, CodeValid = false, WindowOpen = true

Try the question, check the answer, then read the explanation to understand the curriculum point.

At a glance

Question

Type

practice

Style

Topic

Abstraction and automation

Exam-style question

Try this first

An alarm should sound when a door is open and either the security code is invalid or a window is open.\n\na) Write a Boolean expression for the alarm condition using DoorOpen, CodeValid and WindowOpen.\nb) Evaluate the expression for each case below:\n\n1. DoorOpen = true, CodeValid = true, WindowOpen = true\n2. DoorOpen = true, CodeValid = false, WindowOpen = false\n3. DoorOpen = false, CodeValid = false, WindowOpen = true.

Model answer

What a good answer should say

  • a) DoorOpen AND (NOT CodeValid OR WindowOpen).
  • b) 1: false, because the door is open but the code is valid and the window is open does not cause the condition to be true when the expression requires NOT CodeValid OR WindowOpen?
  • Correction: the OR part is true because WindowOpen is true, so the result is true.
  • Therefore 1: true.

Explanation

Why this works

The door condition must be true, so DoorOpen is joined to the other condition with AND. The alarm-related alternatives are an invalid code or an open window, so they are joined with OR.

In case 1, NOT CodeValid is false but WindowOpen is true, making the OR part true; the complete expression is true. In case 2, both DoorOpen and NOT CodeValid are true, so the result is true.

In case 3, DoorOpen is false, so the complete AND expression is false.

Common mistake

No common mistake is linked to this question yet.

Related flashcards

No flashcards are published for this page yet.

Related practice questions

No questions are published for this page yet.