52.8k views
3 votes
A bank uses a computer program during the night to tell if the alarm should ring. Sensors in the bank set the following Boolean variables:

vaultClosed: set to true if the bank vault is closed; otherwise false
heardNoise: set to true if a microphone heard noise; otherwise false
sawMovement: set to true if a camera saw movement in the bank; otherwise false

The automatic alarm should notify the police if there is noise and movement in the bank, or if the bank vault is open. Which boolean expressions can be used in a selection statement to ring the alarm?

1 Answer

1 vote

Answer:

(vaultClosed OR (heardNoise AND sawMovement))

Step-by-step explanation:

The first step is to understand the conditions that must be satisfied to alarm notifies the police.

"The automatic alarm should notify the police IF there is noise and movement in the bank, or IF the bank vault is open".

The first IF (bold), sets the first condition which is formed by two sub-conditions: "noise AND movement". The word AND is very important because both sub-conditions must be satisfied, if there is noise but no movement, the the whole condition is not satisfied and the alarm does not notify, and vice versa.

The second IF (underlined), sets the second condition and is about the bank vault is open.

In conclusion, there are two ways to alarm notify the police.

  1. There is noise and movement (must be both)
  2. The bank vault is open

As can be either, the operator OR is used.

(condition 1) OR (condition 2)

Now, condition 1 is formed by two.

FINAL EXPRESSION

(condition 1) OR (condition 2)

((heardNoise equals True AND sawMovement equals True) OR vaultClosed equals True)

REAL CODE

Depending on the programming language you are using, the way to write the expression could vary. If C language is used, the expression would be:

if((heardNoise==1 && sawMovement==1) || vaultClosed==1))

The number 1 refers to the word TRUE

User Jamesplease
by
5.2k points