IBDP Computer Science B2.3 Programming constructs SL Paper 1 - New Syllabus

Question 

(a) Define the nor Boolean operator.
A car has features that monitor its speed, direction and distance from the car in front. This is shown in Figure 1.
For example, if the car is travelling forward, input B would have a binary representation of 1.
(b) Construct a logic diagram with inputs A, B, and C and output Z to represent the following scenario:
Output Z equals 1 when:
• the car is travelling forward and it is less than 20 metres from the vehicle in front.
or
• the car speed is more than 130 km per hour.
In all other conditions, output Z equals 0.
An additional row (input D) is to be added to assist when the car is in reverse or stationary. Input D checks if there are obstructions less than 3 metres from the rear of the car.
(c) State the rules that need to be added to Figure 1 to test this condition.
Information similar to that presented in Figure 1 could be used to construct decisions and conditions in program design (see Figure 2).
(d) Determine the value of the following expression given that the input values for F, S and T are:
F = 5
S = 30
T = true
 
F >= 25 AND S >= 10 AND S <= 130 AND T = true
You must show your working.
(e) Construct an algorithm in pseudocode that repeats the following steps while the car is moving:
• Input the value for the distance from the vehicle in front.
• Input the value for the speed of the car.
• Check the inputs and notify the user if either the distance from the car in front is less than 20 metres or if the speed of the car is more than 130 kilometres per hour.
The algorithm will only terminate when the car stops moving.

Most-appropriate topic code

• A1.2: Data representation and computer logic — parts (a), (b), (c) and (d)
• B2.3: Programming constructs — part (e)
▶️ Answer/Explanation

(a)
For the correct answer (description OR truth table):
Outputs the value of one if and only if all inputs have a value of zero.

NOR is essentially a NOT applied to an OR gate. It only outputs 1 when every input is 0. The moment any input is 1, the output is 0.

(b)
For the correct answer:
The output Z should represent \(Z = A’ \cdot B + C’\), meaning:

  • Correct NOT gate with input A;
  • Correct NOT gate with input C;
  • Correct AND gate with one input from NOT(A) and one input from B;
  • Correct OR gate with inputs from the AND gate output and NOT(C), producing output Z.

Reading the scenario, “travelling forward AND less than 20m” translates to \(B=1\) AND \(A=0\), giving \(B \cdot \overline{A}\). “Speed more than 130 km/h” means \(C=0\), giving \(\overline{C}\). The two conditions are joined by OR, giving \(Z = \overline{A} \cdot B + \overline{C}\).

(c)
For the correct answer (rules for 0 and 1 can be reversed):

Input D follows the same convention as the existing inputs in Figure 1: binary 0 represents the dangerous/trigger condition (obstruction is close), and binary 1 represents the safe condition (no obstruction within 3 m).

(d)
For the correct answer:

5 >= 25 AND 30 >= 10 AND 30 <= 130 AND true
false AND true AND true AND true
Output = false

Substituting the given values, \(F=5\) fails the first condition \(F \geq 25\). Since AND requires all parts to be true, the entire expression is false.

(e)
For the correct answer:
Use of a flag (or otherwise) to maintain a continuous loop; appropriate loop structure (while/repeat..until); inputs for distance and speed inside the loop; correct conditions to implement alarm notification; correct output of alarm; correct condition to cause the loop to stop. Do NOT accept break to terminate the loop.

FLAG = true
loop while FLAG
    input D
    input S
    if D < 20 OR S > 130 then
        output "ALARM!!"
    end if
    if S = 0 then
        FLAG = false
    end if
end loop

The algorithm uses a boolean flag to keep the loop running while the car is moving. Inside the loop, it reads the distance and speed inputs, checks whether either threshold is breached, and outputs an alarm if so. The loop only exits when speed equals zero, meaning the car has stopped.

Scroll to Top