Time allowed: 1 hour 30 minutes
Principles of Computational Thinking.
(a) Define the following terms:
Abstraction:
Decomposition:
(b) A smart thermostat system controls the temperature in a home. Identify the **inputs**, **processes**, and **outputs** for this system.
Inputs:
Processes:
Outputs:
Algorithms and Logic.
(a) A program uses a Bubble Sort algorithm to sort the following list of numbers in ascending order:
8, 5, 2, 7, 3
Show the state of the list after the first full pass of the algorithm.
(b) A security system uses a logic circuit. The alarm (A) sounds if the sensor (S) detects movement AND the system is armed (M), OR if the panic button (P) is pressed.
Complete the truth table for this logic circuit:
| S | M | P | A |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 1 |
| 0 | 1 | 0 | |
| 0 | 1 | 1 | |
| 1 | 0 | 0 | |
| 1 | 1 | 0 |
Robust Programs and Testing.
(a) Explain how **Anticipating Misuse** helps a developer create a robust program. Give one example of a technique used.
(b) Compare **Iterative Testing** and **Final/Terminal Testing**.
(c) A programmer discovers a Logic Error in their code. Define what is meant by a logic error and explain how it differs from a Syntax Error.
Programming Fundamentals.
(a) Identify the three basic programming constructs used to control the flow of a program.
(b) State the correct data type (e.g. Integer, Real, Boolean, String) for the following variables:
age = 15 :
price = 4.99 :
is_valid = True :
name = "Alex" :
(c) A database stores student information. A Record is used to group related data. Define the structure of a record that could store a student's ID, Name, and whether they have paid their fees.
Algorithm Design and Refinement.
The following algorithm is intended to check if a user is old enough to vote (age 18 or over). However, it contains several errors.
(a) Identify **three** errors or potential improvements to make this algorithm more robust.
(b) Rewrite the algorithm in **pseudocode** or a high-level language of your choice, ensuring it is robust and error-free.
15-Mark Programming Challenge.
Write an algorithm (pseudocode or high-level language) that: