Time allowed: 1 hour 30 minutes
(a) Complete the flowchart logic below by filling in the empty boxes and labels. The flowchart should ask for a price, and if it is greater than 50, output "Discount", otherwise output "No Discount".
(b) Match the computational thinking terms to their definitions.
Term A: Abstraction | Term B: Decomposition | Term C: Algorithmic Thinking
1. The process of removes unnecessary detail to focus on key areas.
2. The process of creates a step-by-step logic to solve a task.
3. The process of breaks the problem down into sub-tasks.
(a) Describe the steps involved in a Merge Sort.
(b) (i) State the pre-condition that must be met before a Binary Search can be used on an array.
(b) (ii) A Linear Search is used on an array of 5,000 unsorted items.
Explain why a Binary Search would be more efficient if the array was sorted.
(a) Tick (✓) one box in each row to show whether the statement applies to a Compiler, an Interpreter, or Both.
| Statement | Compiler | Interpreter | Both |
|---|---|---|---|
| Translates high-level code into machine code | |||
| Translates and executes the code line-by-line | |||
| Produces a final executable file that can be distributed | |||
| Stops translating as soon as the first error is found |
(b) Identify and describe two tools provided by an IDE to help a programmer debug their code.
Tool 1:
Description:
Tool 2:
Description:
(a) Draw a logic gate circuit to represent the Boolean expression: P = (A AND B) OR (NOT C)
(b) Complete the truth table for the logic circuit.
| A | B | C | (A AND B) | (NOT C) | P |
|---|---|---|---|---|---|
| 0 | 0 | 0 | |||
| 0 | 0 | 1 | |||
| 0 | 1 | 0 | |||
| 0 | 1 | 1 | |||
| 1 | 0 | 0 | |||
| 1 | 0 | 1 | |||
| 1 | 1 | 0 | |||
| 1 | 1 | 1 |
(a) A database table `Products` stores the `ProductID`, `Name`, and `Price`.
Write an SQL query to output the `Name` and `Price` of all products where the `Price` is greater than 20.
(b) Complete the table to justify the most appropriate data type for each variable.
| Variable | Data Type | Justification |
|---|---|---|
Price (e.g. 15.99) | ||
InStock (e.g. True) |
Context: Retail Stock Management System
A clothing store uses a computer system to manage its inventory and restock orders.
(a) The system validates the Quantity of items received in a delivery. The quantity must be between 1 and 500 inclusive.
Complete the table with one example of test data for each category.
| Test Category | Test Data Example |
|---|---|
| Normal Data | |
| Valid Boundary Data | |
| Invalid Data |
(b) Identify two ways the programmer can make the stock management code more maintainable, and explain why each helps.
Method 1:
Reason:
Method 2:
Reason:
(a) The programmer has written a flawed function to check if restock is needed.
Identify the line number of the logic error regarding parameter usage, and write the corrected line of code.
Line number of error:
Corrected code (or state if line should be removed):
(b) Write a new function called calculateOrder.
currentStock and maxCapacity.maxCapacity.You must use OCR Reference Language or a high-level programming language.
(a) The system requires staff to enter a Product Code. The code must be exactly 5 characters long.
Write an algorithm using a validation loop that:
(b) A trace table is used to test a different algorithm below:
Complete the trace table for this algorithm.
| x | y | Output |
|---|---|---|
| 0 | 10 | |
(a) The store's inventory is stored in a 2D array called inventoryData. There are 50 rows (representing different products) and 3 columns (representing data for each product).
Column index 2 holds the quantity in stock for that product.
Write an algorithm using iteration to calculate and output the total quantity of all products combined.
(b) The store needs to save a list of critical products to an external text file.
A 1D array called criticalItems contains 20 product names. Write an algorithm that:
"urgent.txt" in write mode.criticalItems array.