Cambridge IGCSE · Thinka-original Practice Paper

2023 Cambridge IGCSE Computer Science (0478) Practice Paper with Answers

Thinka Jun 2023 (V3) Cambridge International A Level-Style Mock — Computer Science (0478)

150 marks210 mins2023
An original Thinka practice paper modelled on the structure and difficulty of the Jun 2023 (V3) Cambridge International A Level Computer Science (0478) paper. Not affiliated with or reproduced from Cambridge.

Paper 1 Computer Systems

Answer all questions. Calculators must not be used.
11 Question · 75.02000000000001 marks
Question 1 · Short/Medium Answer
6.82 marks
An 8-bit register is used to store an unsigned binary integer. (a) Show how the denary number 141 is represented as a binary number in this register. (b) Convert this binary number into hexadecimal. (c) State two reasons why computer scientists use hexadecimal notation to represent binary values.
Show answer & marking scheme

Worked solution

Part (a): To convert 141 to binary: 141 - 128 = 13. 13 - 8 = 5. 5 - 4 = 1. 1 - 1 = 0. The binary equivalent is 10001101. Part (b): Split 10001101 into two 4-bit nibbles: 1000 and 1101. 1000 in denary is 8, which is 8 in hex. 1101 in denary is 13, which is D in hex. Thus, the hex value is 8D. Part (c): Hexadecimal is shorter and more compact, making it easier to read and debug, and it is less prone to human error when typed by programmers.

Marking scheme

1 mark for correct binary representation (10001101). 1 mark for correct conversion to hex (8D). 2 marks for two distinct, valid reasons (e.g., easier to read, fewer transcription errors, maps directly to nibbles). Total marks scaled to 6.82.
Question 2 · Short/Medium Answer
6.82 marks
During the fetch stage of the fetch-decode-execute cycle, several internal registers and buses within the CPU are utilized. Describe the roles and interactions of the Program Counter (PC) and the Memory Address Register (MAR) during this stage. Include details about how system buses are used.
Show answer & marking scheme

Worked solution

At the start of the fetch cycle, the address of the next instruction to be executed is held in the Program Counter (PC). This address is copied from the PC to the Memory Address Register (MAR) using the internal bus. While this happens, the PC is incremented by 1 to point to the next instruction. The address in the MAR is then sent along the address bus to main memory (RAM). The instruction stored at that address is retrieved and sent back via the data bus to the Memory Data Register (MDR).

Marking scheme

1 mark for identifying that PC holds the address of the next instruction. 1 mark for explaining that this address is copied from PC to MAR. 1 mark for stating that the PC is incremented to point to the next instruction. 1 mark for describing that the MAR sends the address along the address bus to memory. 1 mark for describing that the instruction is retrieved from memory and sent back via the data bus. Total marks scaled to 6.82.
Question 3 · Short/Medium Answer
6.82 marks
Cybersecurity threats can compromise user data. Contrast 'phishing' and 'pharming' by explaining how each threat is carried out and how a user can protect themselves against each threat.
Show answer & marking scheme

Worked solution

Phishing: The attacker sends a fraudulent email, text, or social media message designed to look like a legitimate organization (e.g., a bank). The message contains a link to a fake website where the user is prompted to input personal details like passwords. Prevention: Check the sender's email address closely, look for spelling mistakes, and never click links in unexpected emails. Pharming: Malicious code is installed on the user's hard drive or web server, which alters domain resolution settings. This causes the browser to redirect the user to a fake website even when they type the correct URL. Prevention: Install and update anti-malware software, check that the website uses HTTPS, and look for valid security certificates.

Marking scheme

1 mark for describing phishing (fraudulent emails directing to fake sites). 1 mark for describing phishing prevention (checking email domains, not clicking links). 1 mark for describing pharming (redirection of traffic/DNS poisoning). 1 mark for describing pharming prevention (anti-malware, verifying HTTPS certificates). Total marks scaled to 6.82.
Question 4 · Short/Medium Answer
6.82 marks
A school network administrator needs to connect a classroom of 10 computers to the internet. Identify three essential network hardware devices needed for this setup and explain the primary function of each device in this context.
Show answer & marking scheme

Worked solution

The three essential devices are: 1. Network Interface Card (NIC): Every computer must have a NIC to convert internal digital signals into network signals and to assign a unique MAC address for identification. 2. Switch: Connects all 10 computers within the classroom LAN, sending data packets specifically to the destination MAC address of the target computer. 3. Router: Connects the classroom local area network to the internet (Wide Area Network). It reads IP addresses to route packets of data between the internal network and external networks.

Marking scheme

1 mark for identifying NIC and 1 mark for its function. 1 mark for identifying Switch (or Hub) and 1 mark for its function. 1 mark for identifying Router and 1 mark for its function. Total marks scaled to 6.82.
Question 5 · Short/Medium Answer
6.82 marks
A communication link uses an even parity block check (longitudinal redundancy check) to detect errors during data transmission. Explain how this method operates to detect and correct single-bit errors, and explain one limitation of parity checks compared to a Cyclic Redundancy Check (CRC).
Show answer & marking scheme

Worked solution

In a parity block check, data is sent in blocks of bytes. A parity bit is added to each individual byte (row parity). A separate parity byte is also calculated and appended to the end of the block, where each bit is the parity bit for that vertical column (column parity). During transmission, if a single bit flips, it causes a parity error in both its row and its column. The intersection of this row and column points to the exact bit that was corrupted, allowing it to be inverted (corrected). A key limitation of parity checks is that if an even number of bits flip in the same row or column, the errors will cancel out and not be detected. In contrast, a CRC uses a mathematical polynomial division algorithm on the entire block of data to generate a checksum, which is far more robust at detecting multiple-bit and burst errors.

Marking scheme

1 mark for describing row and column parity calculations. 1 mark for explaining how the intersection of failed parities pinpoints a single-bit error for correction. 1 mark for identifying the limitation (even number of bit errors in a row/column can go undetected). 1 mark for explaining that CRC uses polynomial division to generate a checksum, which detects burst errors much more reliably. Total marks scaled to 6.82.
Question 6 · Short/Medium Answer
6.82 marks
Compare serial half-duplex transmission and parallel full-duplex transmission. For each method, explain how data is transmitted and provide a typical practical application where it is used.
Show answer & marking scheme

Worked solution

Serial half-duplex transmission: Data is transmitted sequentially, one bit at a time, along a single wire/channel. Data can travel in both directions (bidirectional), but not simultaneously (only one direction at any given time). A practical application is USB connection or walkie-talkie systems. Parallel full-duplex transmission: Data is transmitted with multiple bits sent simultaneously over multiple parallel wires/channels. Communication is bidirectional and occurs in both directions at the same time. A practical application is high-speed internal communication within a computer, such as a PCIe bus or memory bus connecting CPU and RAM.

Marking scheme

1 mark for serial half-duplex mechanism (one bit at a time, bidirectional but not simultaneous). 1 mark for serial half-duplex application. 1 mark for parallel full-duplex mechanism (multiple bits simultaneously, bidirectional at the same time). 1 mark for parallel full-duplex application. Total marks scaled to 6.82.
Question 7 · Short/Medium Answer
6.82 marks
An operating system uses interrupts to manage hardware and software events. Define what an 'interrupt' is, give two examples of events that generate interrupts, and explain the steps the CPU takes when an interrupt is detected.
Show answer & marking scheme

Worked solution

An interrupt is a signal sent to the CPU from a hardware device or software program indicating that an event has occurred that needs immediate processing. Two examples of events: 1. A hardware device signal (e.g., a keyboard key is pressed, or a printer runs out of paper). 2. A software error (e.g., division by zero, or a segmentation fault). When an interrupt is received, the CPU completes its current instruction. It then saves the state of its current registers onto a stack so it can resume later. The CPU identifies the interrupt source and loads the memory address of the corresponding Interrupt Service Routine (ISR) into the Program Counter. The CPU executes the ISR to handle the event. Once completed, the CPU restores the saved registers from the stack and resumes the main task from where it was interrupted.

Marking scheme

1 mark for defining interrupt. 1 mark for two valid examples. 1 mark for stating that the CPU finishes the current instruction and saves registers. 1 mark for explaining that the CPU loads and runs the Interrupt Service Routine (ISR). 1 mark for stating that the CPU restores registers and resumes the task. Total marks scaled to 6.82.
Question 8 · Short/Medium Answer
6.82 marks
A logic circuit is represented by the Boolean expression: \( X = \text{NOT } (A \text{ AND } B) \text{ OR } (B \text{ AND } \text{NOT } C) \). Generate the complete truth table for this expression and list the final outputs for \( X \) for all eight possible input combinations, starting from \( A=0, B=0, C=0 \) up to \( A=1, B=1, C=1 \) in standard binary order.
Show answer & marking scheme

Worked solution

To find the truth table: Let Y = NOT (A AND B) and Z = B AND NOT C. 1. For A=0, B=0, C=0: A AND B = 0, so Y = 1. Z = 0 AND 1 = 0. X = 1 OR 0 = 1. 2. For A=0, B=0, C=1: A AND B = 0, so Y = 1. Z = 0 AND 0 = 0. X = 1 OR 0 = 1. 3. For A=0, B=1, C=0: A AND B = 0, so Y = 1. Z = 1 AND 1 = 1. X = 1 OR 1 = 1. 4. For A=0, B=1, C=1: A AND B = 0, so Y = 1. Z = 1 AND 0 = 0. X = 1 OR 0 = 1. 5. For A=1, B=0, C=0: A AND B = 0, so Y = 1. Z = 0 AND 1 = 0. X = 1 OR 0 = 1. 6. For A=1, B=0, C=1: A AND B = 0, so Y = 1. Z = 0 AND 0 = 0. X = 1 OR 0 = 1. 7. For A=1, B=1, C=0: A AND B = 1, so Y = 0. Z = 1 AND 1 = 1. X = 0 OR 1 = 1. 8. For A=1, B=1, C=1: A AND B = 1, so Y = 0. Z = 1 AND 0 = 0. X = 0 OR 0 = 0. Thus, the final outputs of X are 1, 1, 1, 1, 1, 1, 1, 0.

Marking scheme

1 mark for evaluating Y = NOT(A AND B) correctly across all rows. 1 mark for evaluating Z = B AND NOT C correctly across all rows. 1 mark for combining Y and Z with the OR gate. 1 mark for presenting the final 8 correct outputs in order (1, 1, 1, 1, 1, 1, 1, 0). Total marks scaled to 6.82.
Question 9 · Short/Medium Answer
6.82 marks
During the fetch-decode-execute cycle, several registers within the CPU are utilized. Describe the role of the Program Counter (PC), the Memory Address Register (MAR), and the Memory Data Register (MDR) specifically during the fetch stage of this cycle. Include in your description how these registers interact with each other and with memory.
Show answer & marking scheme

Worked solution

The Program Counter (PC) stores the address of the next instruction to be fetched. At the start of the fetch stage, this address is copied from the PC to the Memory Address Register (MAR) via the address bus. The PC is then immediately incremented by one to point to the next instruction. A read signal is sent to primary memory (RAM), and the instruction stored at the address currently held in the MAR is retrieved. This instruction is transferred back to the CPU via the data bus and is stored in the Memory Data Register (MDR).

Marking scheme

Maximum of 7 marks:
- 1 mark: PC holds the address of the next instruction to be fetched.
- 1 mark: Address is copied from PC to MAR (via the address bus).
- 1 mark: PC is incremented by 1.
- 1 mark: CPU sends a read signal to memory (via control bus).
- 1 mark: MAR holds the address of the memory location being accessed.
- 1 mark: Instruction from RAM is sent via the data bus.
- 1 mark: Instruction is stored in the MDR.
Question 10 · Short/Medium Answer
6.82 marks
A system uses a simple checksum algorithm to detect errors in transmitted data. The transmitter calculates a checksum by summing the decimal values of the data bytes and finding the remainder when this sum is divided by 256 (i.e., sum modulo 256).

(a) Explain how a checksum is used by both the sender and the receiver to detect if transmission errors have occurred.

(b) A block of data consists of four bytes with the following decimal values:
105, 201, 75, 112

Calculate the checksum value for this block of data. Show your working.
Show answer & marking scheme

Worked solution

(a) The sender applies the checksum algorithm to the block of data to generate a checksum value, which is appended to the data block and transmitted. Upon receipt, the receiver applies the same checksum algorithm to the received data. The receiver then compares their calculated checksum with the received checksum. If they match, no transmission error is detected. If they do not match, an error is identified, and retransmission is typically requested.

(b) Sum the decimal values of the bytes:
\( 105 + 201 + 75 + 112 = 493 \).
Divide by 256 to find the remainder:
\( 493 \div 256 = 1 \) remainder \( 237 \).
Therefore, the checksum value is \( 237 \).

Marking scheme

Part (a) [Max 4 marks]:
- 1 mark: Sender calculates checksum based on the data block.
- 1 mark: Checksum is transmitted alongside/appended to the data.
- 1 mark: Receiver recalculates checksum using the received data.
- 1 mark: Receiver compares calculated checksum with transmitted checksum; mismatch indicates error.

Part (b) [Max 3 marks]:
- 1 mark: Correct sum of bytes shown as \( 493 \).
- 1 mark: Modulo 256 operation shown or implied.
- 1 mark: Correct final checksum value of \( 237 \).
Question 11 · Short/Medium Answer
6.82 marks
A school wants to secure its local area network (LAN) from external cyber threats and control student access to the internet. The network administrator decides to implement both a firewall and a proxy server.

(a) Describe how a firewall helps protect the school's network.

(b) Explain the functions of a proxy server in this setup and how it differs from a firewall.
Show answer & marking scheme

Worked solution

(a) A firewall acts as a barrier between the internal LAN and external networks (the internet). It inspects all incoming and outgoing packets of data and checks them against a set of predefined security rules. It blocks packets that do not meet these rules, preventing hacking attempts, unauthorized external access, and stopping malicious software from communicating outward.

(b) A proxy server sits between the school's user devices and the internet. It intercepts all web requests, hiding the internal IP addresses of the school's devices (providing anonymity). It can cache frequently accessed web pages to reduce bandwidth and speed up access. Additionally, it filters content to block access to specific websites. It differs from a firewall because a firewall focuses on packet inspection and blocking unauthorized port connections, while a proxy server manages web requests on behalf of the clients and handles content-level controls.

Marking scheme

Part (a) [Max 3 marks]:
- 1 mark: Inspects incoming and outgoing network traffic.
- 1 mark: Compares traffic against a set of predefined security rules.
- 1 mark: Blocks unauthorized traffic or suspicious activities.

Part (b) [Max 4 marks]:
- 1 mark: Acts as an intermediary between client devices and the internet.
- 1 mark: Hides internal IP addresses (providing anonymity/security).
- 1 mark: Caches web pages to reduce bandwidth/speed up web page load times.
- 1 mark: Provides web content filtering to block undesirable websites.
- 1 mark: Difference: Firewall focuses on packet inspection and port blocking, whereas a proxy server makes requests on behalf of clients and works at the application layer.

Paper 2 Algorithms, Programming and Logic

Answer all questions. Use of calculators is not permitted.
11 Question · 75 marks
Question 1 · Short Answer
6 marks
A programmer has written the following pseudocode algorithm to process two integer inputs, A and B:

```text
DECLARE A, B, C : INTEGER
INPUT A, B
C <- 0
WHILE A > 0 DO
IF A MOD 2 = 1 THEN
C <- C + B
ENDIF
A <- A DIV 2
B <- B * 2
ENDWHILE
OUTPUT C
```

Complete the trace table below for the inputs: A = 11, B = 3.

| A | B | C | Output |
|---|---|---|--------|
| | | | |
Show answer & marking scheme

Worked solution

Let's trace the execution step by step:
1. Initial state: A = 11, B = 3, C = 0.
2. Loop condition: A > 0 (11 > 0) is TRUE.
- A MOD 2 = 1 (11 MOD 2 = 1) is TRUE, so C <- C + B = 0 + 3 = 3.
- A <- A DIV 2 = 11 DIV 2 = 5.
- B <- B * 2 = 3 * 2 = 6.
3. Loop condition: A > 0 (5 > 0) is TRUE.
- A MOD 2 = 1 (5 MOD 2 = 1) is TRUE, so C <- C + B = 3 + 6 = 9.
- A <- A DIV 2 = 5 DIV 2 = 2.
- B <- B * 2 = 6 * 2 = 12.
4. Loop condition: A > 0 (2 > 0) is TRUE.
- A MOD 2 = 1 (2 MOD 2 = 0) is FALSE.
- A <- A DIV 2 = 2 DIV 2 = 1.
- B <- B * 2 = 12 * 2 = 24.
5. Loop condition: A > 0 (1 > 0) is TRUE.
- A MOD 2 = 1 (1 MOD 2 = 1) is TRUE, so C <- C + B = 9 + 24 = 33.
- A <- A DIV 2 = 1 DIV 2 = 0.
- B <- B * 2 = 24 * 2 = 48.
6. Loop condition: A > 0 (0 > 0) is FALSE. Loop terminates.
7. OUTPUT C -> Outputs 33.

Marking scheme

Award marks as follows (Max 6):
- 1 mark for correct initial values: A=11, B=3, C=0.
- 1 mark for correct first iteration: C=3, A=5, B=6.
- 1 mark for correct second iteration: C=9, A=2, B=12.
- 1 mark for correct third iteration: A=1, B=24 (C unchanged/not repeated).
- 1 mark for correct fourth iteration: C=33, A=0, B=48.
- 1 mark for correct output value: 33.
Question 2 · Short Answer
6 marks
A logic circuit is represented by the following Boolean expression:

\( X = (\text{NOT } A \text{ AND } B) \text{ OR } (B \text{ NAND } C) \)

Complete the truth table for this expression:

| A | B | C | Workspace (Intermediate evaluations) | X |
|---|---|---|---|---|
| 0 | 0 | 0 | | |
| 0 | 0 | 1 | | |
| 0 | 1 | 0 | | |
| 0 | 1 | 1 | | |
| 1 | 0 | 0 | | |
| 1 | 0 | 1 | | |
| 1 | 1 | 0 | | |
| 1 | 1 | 1 | | |
Show answer & marking scheme

Worked solution

Let us evaluate each row:
1. A=0, B=0, C=0: (NOT A AND B) = (1 AND 0) = 0. (B NAND C) = 0 NAND 0 = 1. X = 0 OR 1 = 1.
2. A=0, B=0, C=1: (NOT A AND B) = 0. (B NAND C) = 0 NAND 1 = 1. X = 0 OR 1 = 1.
3. A=0, B=1, C=0: (NOT A AND B) = (1 AND 1) = 1. (B NAND C) = 1 NAND 0 = 1. X = 1 OR 1 = 1.
4. A=0, B=1, C=1: (NOT A AND B) = (1 AND 1) = 1. (B NAND C) = 1 NAND 1 = 0. X = 1 OR 0 = 1.
5. A=1, B=0, C=0: (NOT A AND B) = (0 AND 0) = 0. (B NAND C) = 0 NAND 0 = 1. X = 0 OR 1 = 1.
6. A=1, B=0, C=1: (NOT A AND B) = 0. (B NAND C) = 0 NAND 1 = 1. X = 0 OR 1 = 1.
7. A=1, B=1, C=0: (NOT A AND B) = (0 AND 1) = 0. (B NAND C) = 1 NAND 0 = 1. X = 0 OR 1 = 1.
8. A=1, B=1, C=1: (NOT A AND B) = (0 AND 1) = 0. (B NAND C) = 1 NAND 1 = 0. X = 0 OR 0 = 0.

Marking scheme

Award marks as follows:
- 1 mark for correct evaluation of (NOT A AND B) for all rows.
- 1 mark for correct evaluation of (B NAND C) for all rows.
- 4 marks for the final outputs (X):
- All 8 outputs correct = 4 marks
- 6 to 7 outputs correct = 3 marks
- 4 to 5 outputs correct = 2 marks
- 2 to 3 outputs correct = 1 mark
- Less than 2 outputs correct = 0 marks
Question 3 · Short Answer
6 marks
A database table named STARS is used to store astronomical data.
The table structure is:
- `StarID` (Text, e.g., 'ST001')
- `Name` (Text, e.g., 'Sirius')
- `Constellation` (Text, e.g., 'Canis Major')
- `Magnitude` (Real, e.g., -1.46)
- `Distance` (Integer, e.g., 9)
- `VisibleEye` (Boolean, e.g., TRUE)

a) Identify which field should be chosen as the primary key and justify your choice. [2 marks]
b) Write a SQL query to display the Name, Constellation, and Distance of all stars where the Distance is less than 50 and VisibleEye is TRUE, sorted in ascending order of Distance. [4 marks]
Show answer & marking scheme

Worked solution

a) The `StarID` is the only suitable field for a primary key because it guarantees a unique identifier for each record. Other fields like `Name` or `Constellation` can have duplicates.
b) The SQL query needs to retrieve specific fields (`Name`, `Constellation`, `Distance`), filter using a comparison condition (`Distance < 50`) and a boolean match (`VisibleEye = TRUE`), and sort results sequentially (`ORDER BY Distance ASC`).

Marking scheme

Part a (Max 2 marks):
- 1 mark for identifying StarID.
- 1 mark for justifying that it contains unique data to uniquely identify each record.

Part b (Max 4 marks):
- 1 mark for: SELECT Name, Constellation, Distance
- 1 mark for: FROM STARS
- 1 mark for: WHERE Distance < 50 AND VisibleEye = TRUE (accept: = 1 or simply AND VisibleEye)
- 1 mark for: ORDER BY Distance (ASC) (accept ORDER BY on its own as ascending is default)
Question 4 · Short Answer
6 marks
Write a pseudocode algorithm to find the highest score in a 1D array of 100 integers called `Scores`, and also count how many times this highest score occurs in the array.

Your algorithm should:
- Initialise any variables used.
- Loop through the entire array.
- Find the maximum value.
- Keep track of the number of times this maximum value occurs.
- Output the highest score and its occurrence count.
Show answer & marking scheme

Worked solution

We initialise the search using the first element of the array: `Highest <- Scores[1]` and set our duplicate count to 1. We then iterate from index 2 to 100. If we encounter a score greater than `Highest`, we update `Highest` and reset the occurrences count to 1. If we find a score equal to `Highest`, we increment the count. Finally, we output the values.

Marking scheme

Award marks as follows (Max 6):
- 1 mark: Correct variable declarations and initialising `Highest` with first array element and `Count` with 1 (or equivalent logic).
- 1 mark: Correct loop structure checking from index 2 to 100 (or 1 to 100).
- 1 mark: Comparing array elements using `>` (e.g. `Scores[i] > Highest`).
- 1 mark: Resetting `Count` to 1 and updating `Highest` inside the greater-than conditional statement.
- 1 mark: Checking equality (e.g. `ELSEIF Scores[i] = Highest`) and incrementing `Count` by 1.
- 1 mark: Outputting both the highest score and count values after the loop ends.
Question 5 · Short Answer
6 marks
A program is required to search for a specific student's name in a text file named 'students.txt'. The file contains one name per line.

Write a pseudocode algorithm that:
1. Prompts the user and inputs the student name to search for.
2. Opens the file 'students.txt' for reading.
3. Reads each name from the file and checks if it matches the input name.
4. Stops reading if the name is found or the end of the file is reached.
5. Closes the file.
6. Outputs 'Found' if the student name is in the file, otherwise outputs 'Not Found'.
Show answer & marking scheme

Worked solution

We begin by requesting the search target. We open 'students.txt' for reading. A loop condition combined with an end-of-file check and a 'Found' boolean ensures we do not over-read. Each record is processed. The file is closed afterwards to release resources, and an appropriate message is output.

Marking scheme

Award marks as follows (Max 6):
- 1 mark: Prompting user and saving to a search variable, and initializing boolean flag (e.g., `Found <- FALSE`).
- 1 mark: Correct use of `OPEN` keyword specifying 'students.txt' and READ mode.
- 1 mark: Correct loop with `NOT EOF("students.txt")` check.
- 1 mark: Reading from the file using correct file syntax (e.g., `READFILE "students.txt", CurrentName`).
- 1 mark: Match check conditional statement and closing the file (`CLOSEFILE "students.txt"`).
- 1 mark: Outputting 'Found' or 'Not Found' depending on state of the search flag.
Question 6 · Short Answer
6 marks
An online system requires users to set a password. The password must meet two validation rules:
1. It must be at least 8 characters long.
2. It must not contain any space characters (" ").

Write a pseudocode function `ValidatePassword(Password : STRING) RETURNS BOOLEAN` that checks if the input parameter 'Password' meets these rules. It must return `TRUE` if both rules are satisfied, and `FALSE` otherwise. Use standard IGCSE pseudocode syntax.
Show answer & marking scheme

Worked solution

The function evaluates length validation using `LENGTH(Password) >= 8`. It then loops through every single character from index 1 to the length of the string to find any occurrence of a space character. If any space is found, the space safety flag is invalidated. The function returns TRUE only if both flags are true.

Marking scheme

Award marks as follows (Max 6):
- 1 mark: Correct Function header with parameter definition and returning a BOOLEAN.
- 1 mark: Correct check of the length of the string using standard function `LENGTH(Password) >= 8`.
- 1 mark: Correct loop configuration to iterate from index 1 to length of password.
- 1 mark: Correct isolation/extraction of single characters (e.g., `SUBSTRING(Password, i, 1)` or array indexing syntax).
- 1 mark: Correct comparison of each character to " " and setting a flag or returning FALSE.
- 1 mark: Correct conditional returns (`RETURN TRUE` or `RETURN FALSE`) and matching `ENDFUNCTION` statement.
Question 7 · Short Answer
6 marks
A change-dispensing machine only accepts and dispenses change in $10 and $5 notes.

Write a pseudocode algorithm that:
1. Prompts and inputs the amount of change to be given (an integer).
2. Validates the input change to ensure it is greater than 0 AND is a multiple of 5 (using loop validation).
3. Calculates the minimum number of $10 notes and then $5 notes needed to make up that amount of change.
4. Outputs the count of $10 notes and $5 notes needed.

(Note: Use standard MOD and DIV arithmetic operators.)
Show answer & marking scheme

Worked solution

The validation block uses a `REPEAT...UNTIL` construct that forces the user to input a positive integer value that is fully divisible by 5 (`Change MOD 5 = 0`).
Tens are calculated using integer division (`DIV 10`). The leftover amount is then calculated using the modulo operator (`MOD 10`). Finally, Fives are calculated from the remaining change using integer division (`DIV 5`), and the results are printed.

Marking scheme

Award marks as follows (Max 6):
- 1 mark: Use of a valid post-assertion validation loop (e.g. `REPEAT...UNTIL`) or pre-assertion loop (`WHILE`).
- 1 mark: Correct logical conditions for validation: `Change > 0` AND `Change MOD 5 = 0` (or equivalent math).
- 1 mark: Use of `DIV` operator with 10 to calculate tens: `Tens <- Change DIV 10`.
- 1 mark: Use of `MOD` operator with 10 to update the remainder of change: `Change <- Change MOD 10` (or manual calculation).
- 1 mark: Use of `DIV` operator with 5 to calculate fives: `Fives <- Change DIV 5`.
- 1 mark: Correct output statement(s) showing both variables clearly.
Question 8 · Short Answer
6 marks
An algorithm is written in pseudocode using nested loops as shown below:

```text
DECLARE Outer, Inner, Temp : INTEGER
FOR Outer <- 1 TO 3
FOR Inner <- 1 TO Outer
Temp <- Outer * Inner
OUTPUT Temp
ENDFOR
ENDFOR
```

Complete the trace table below to show the execution of this algorithm.

| Outer | Inner | Temp | Output |
|---|---|---|--------|
| | | | |
Show answer & marking scheme

Worked solution

Let's trace the loop boundaries:
- When Outer = 1: Inner loop runs from 1 to 1. Temp = 1 * 1 = 1. Outputs 1.
- When Outer = 2: Inner loop runs from 1 to 2.
- Inner = 1: Temp = 2 * 1 = 2. Outputs 2.
- Inner = 2: Temp = 2 * 2 = 4. Outputs 4.
- When Outer = 3: Inner loop runs from 1 to 3.
- Inner = 1: Temp = 3 * 1 = 3. Outputs 3.
- Inner = 2: Temp = 3 * 2 = 6. Outputs 6.
- Inner = 3: Temp = 3 * 3 = 9. Outputs 9.

Marking scheme

Award marks as follows (Max 6):
- 1 mark: First row correct (Outer=1, Inner=1, Temp=1, Output=1).
- 1 mark: Second row correct (Outer=2, Inner=1, Temp=2, Output=2).
- 1 mark: Third row correct (Outer=2, Inner=2, Temp=4, Output=4).
- 1 mark: Fourth row correct (Outer=3, Inner=1, Temp=3, Output=3).
- 1 mark: Fifth row correct (Outer=3, Inner=2, Temp=6, Output=6).
- 1 mark: Sixth row correct (Outer=3, Inner=3, Temp=9, Output=9).
Question 9 · Short Answer
6 marks
An automatic greenhouse ventilation fan (F) is switched on (F = 1) if:
- The temperature is high (T = 1) AND the humidity is high (H = 1)
OR
- The manual override switch is ON (M = 1) AND the temperature is NOT high (T = 0)

(a) Write a Boolean logic expression for this system using the inputs T, H, M and output F. [2]

(b) Complete the truth table below for the greenhouse ventilation system. [4]

| T | H | M | F |
|---|---|---|---|
| 0 | 0 | 0 | |
| 0 | 0 | 1 | |
| 0 | 1 | 0 | |
| 0 | 1 | 1 | |
| 1 | 0 | 0 | |
| 1 | 0 | 1 | |
| 1 | 1 | 0 | |
| 1 | 1 | 1 | |
Show answer & marking scheme

Worked solution

(a) The Boolean expression for the system is:
F = (T AND H) OR (M AND NOT T)
(Alternative correct form: F = (T AND H) OR (NOT T AND M))

(b) Tracing the truth table values:
- Row 1: T=0, H=0, M=0 -> (0 AND 0) OR (0 AND 1) -> 0 OR 0 = 0
- Row 2: T=0, H=0, M=1 -> (0 AND 0) OR (1 AND 1) -> 0 OR 1 = 1
- Row 3: T=0, H=1, M=0 -> (0 AND 1) OR (0 AND 1) -> 0 OR 0 = 0
- Row 4: T=0, H=1, M=1 -> (0 AND 1) OR (1 AND 1) -> 0 OR 1 = 1
- Row 5: T=1, H=0, M=0 -> (1 AND 0) OR (0 AND 0) -> 0 OR 0 = 0
- Row 6: T=1, H=0, M=1 -> (1 AND 0) OR (1 AND 0) -> 0 OR 0 = 0
- Row 7: T=1, H=1, M=0 -> (1 AND 1) OR (0 AND 0) -> 1 OR 0 = 1
- Row 8: T=1, H=1, M=1 -> (1 AND 1) OR (1 AND 0) -> 1 OR 0 = 1

Completed Truth Table:
| T | H | M | F |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 1 |
| 0 | 1 | 0 | 0 |
| 0 | 1 | 1 | 1 |
| 1 | 0 | 0 | 0 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 1 |
| 1 | 1 | 1 | 1 |

Marking scheme

Part (a) [2 marks]:
- 1 mark for (T AND H)
- 1 mark for (M AND NOT T) combined with OR
Accept standard logic notation like F = (T ∧ H) ∨ (M ∧ T).

Part (b) [4 marks]:
- 4 marks for all 8 outputs correct (0, 1, 0, 1, 0, 0, 1, 1)
- 3 marks for 6 or 7 outputs correct
- 2 marks for 4 or 5 outputs correct
- 1 mark for 2 or 3 outputs correct
Question 10 · Short Answer
6 marks
Perform a trace table for the following pseudocode algorithm.

```
DECLARE X, Y, Z, Count AS INTEGER
X <- 2
Y <- 15
Z <- 0
Count <- 1
WHILE Y > X DO
IF Y MOD 2 = 0 THEN
Z <- Z + X
ELSE
Z <- Z + Y
ENDIF
X <- X * 2
Y <- Y - 3
Count <- Count + 1
ENDWHILE
```

Complete the trace table below. [6]

| X | Y | Z | Count |
|---|---|---|-------|
| | | | |
| | | | |
| | | | |
| | | | |
Show answer & marking scheme

Worked solution

Let us trace the execution of the pseudocode step-by-step:

1. Initial state:
- X = 2, Y = 15, Z = 0, Count = 1

2. First loop iteration (Condition: 15 > 2 is True):
- Since 15 MOD 2 != 0 (it is 1), the ELSE branch is taken: Z = 0 + 15 = 15
- X = 2 * 2 = 4
- Y = 15 - 3 = 12
- Count = 1 + 1 = 2

3. Second loop iteration (Condition: 12 > 4 is True):
- Since 12 MOD 2 = 0, the THEN branch is taken: Z = 15 + 4 = 19
- X = 4 * 2 = 8
- Y = 12 - 3 = 9
- Count = 2 + 1 = 3

4. Third loop iteration (Condition: 9 > 8 is True):
- Since 9 MOD 2 != 0, the ELSE branch is taken: Z = 19 + 9 = 28
- X = 8 * 2 = 16
- Y = 9 - 3 = 6
- Count = 3 + 1 = 4

5. Fourth check (Condition: 6 > 16 is False):
- The loop terminates.

Completed Trace Table:
| X | Y | Z | Count |
|---|---|---|-------|
| 2 | 15| 0 | 1 |
| 4 | 12| 15| 2 |
| 8 | 9 | 19| 3 |
| 16| 6 | 28| 4 |

Marking scheme

- 1 mark for correct initial values row: X=2, Y=15, Z=0, Count=1
- 1 mark for correct sequence in column X: (4, 8, 16)
- 1 mark for correct sequence in column Y: (12, 9, 6)
- 1 mark for correct sequence in column Count: (2, 3, 4)
- 2 marks for correct sequence in column Z: (15, 19, 28)
- Deduct 1 mark for each incorrect entry in column Z up to a maximum of 2.
Question 11 · subjective
15 marks
An agricultural farm uses a computer system to track the weight of fruit harvested by 10 pickers over a 5-day working week (Monday to Friday).

Write an algorithm, in pseudocode, that meets the following requirements:
- Inputs and stores the names of the 10 pickers in a 1D array `PickerName[1:10]`.
- Inputs the weight of fruit harvested (in kg) by each picker for each of the 5 days, storing the values in a 2D array `HarvestWeight[1:10, 1:5]`.
- Validates each daily weight input to ensure it is greater than or equal to 0.0 and less than or equal to 100.0. If the input is invalid, an error message is displayed and the user is prompted to re-enter the weight until a valid value is entered.
- Calculates and outputs:
- The total weekly weight harvested by each picker, accompanied by their name.
- The average daily weight harvested per person-day across the entire farm (i.e. the total weight of all fruit harvested divided by 50).
- The name of the picker who harvested the greatest total weight of fruit during the week.

You must use pseudocode and declare any variables you use.
Assume that all total weekly weights are unique so there is no tie for the picker with the greatest weight.
Show answer & marking scheme

Worked solution

The algorithm is designed systematically in four main phases:

1. **Declarations & Initialization**:
- Appropriate 1D arrays are declared for the names of the pickers (`PickerName[1:10]`) and their calculated weekly totals (`PickerTotals[1:10]`).
- A 2D array (`HarvestWeight[1:10, 1:5]`) is declared to hold 5 days of records for each of the 10 pickers.
- Loop variables (`i`, `j`), a tracking index for the maximum weight holder (`MaxIndex`), and a boolean validation flag (`Valid`) are declared.

2. **Inputting and Validating Data**:
- A single loop is run first to prompt and store the 10 picker names.
- Nested loops are utilized: the outer loop (`i` from 1 to 10) controls the picker, while the inner loop (`j` from 1 to 5) controls the daily weight entries.
- Within the inner loop, a validation loop (`REPEAT...UNTIL`) ensures that only valid weights between `0.0` and `100.0` (inclusive) are stored. If invalid data is entered, a corrective prompt is re-displayed.
- The accepted valid weights are added to the overall daily farm total (`TotalWeight`) and the individual picker's total (`PickerTotals[i]`).

3. **Finding the Maximum and Printing Individual Totals**:
- A final loop processes the totals for all 10 pickers. It prints each picker's total weekly weight and checks if their total exceeds the current registered maximum (`MaxWeight`). If it does, `MaxWeight` is updated and their index `i` is stored in `MaxIndex`.

4. **Final Calculations and Outputs**:
- The overall average is computed by dividing the accumulated `TotalWeight` by the total number of logs (50 person-days).
- The picker of the week's name is obtained via `PickerName[MaxIndex]` and printed.

Marking scheme

Marks are allocated as follows (Max 15 marks):

**Variable Declarations (1 Mark)**
- 1 mark: Explicitly declaring all arrays (including bounds and types) and primitive variables used in the algorithm.

**Inputting Names (2 Marks)**
- 1 mark: Using a loop to input 10 picker names.
- 1 mark: Storing the inputs correctly in the 1D array `PickerName`.

**Nested Loops structure (2 Marks)**
- 1 mark: Correct outer loop (from 1 to 10) and inner loop (from 1 to 5) to handle 10 pickers and 5 days.
- 1 mark: Correctly indexing the 2D array using the loop counters (e.g., `HarvestWeight[i, j]`).

**Validation (3 Marks)**
- 1 mark: Using a post-assertion / pre-assertion loop structure (e.g., `REPEAT...UNTIL` or `WHILE...ENDWHILE`) for input validation.
- 1 mark: Correct conditional range check logic (e.g., `< 0` or `> 100`).
- 1 mark: Printing an error message and prompting for re-entry on invalid input.

**Calculations and Totals (3 Marks)**
- 1 mark: Accumulating the total daily weight for each individual picker.
- 1 mark: Accumulating the grand total weight across all pickers and days.
- 1 mark: Correctly calculating the overall average daily weight (dividing the grand total by 50).

**Finding the Maximum / Picker of the Week (2 Marks)**
- 1 mark: Initializing the maximum comparison variable and using an `IF` statement inside a loop to find the maximum total weight.
- 1 mark: Storing the index or name of the picker associated with that maximum weight.

**Outputs (2 Marks)**
- 1 mark: Printing the individual weekly total weight for each of the 10 pickers alongside their names.
- 1 mark: Printing the overall average and the "Picker of the Week" name and total weight.

Wondering how well you actually know this?

Thinka is an AI practice app for DSE students — unlimited questions, instant auto-marking, and detailed step-by-step solutions. 100,000+ students use it to confirm they actually know it, not just think they do.

Want more questions like this? Practice unlimited on Thinka — instant answers included.

Start Practising Free