Cambridge IGCSE · Thinka-original Practice Paper

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

Thinka Jun 2024 (V1) Cambridge International A Level-Style Mock — Computer Science (0478)

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

Paper 11: Computer Systems Theory

Answer all questions. Calculators must not be used. Total marks: 75.
9 Question · 75 marks
Question 1 · short answer
4 marks
A computer is transmitting a block of data. A checksum is used to detect errors during this transmission.

Describe how a checksum is calculated, transmitted, and used to detect whether transmission errors have occurred.
Show answer & marking scheme

Worked solution

The checksum method involves:
1. The sender applying an algorithm to the block of data to generate a numerical checksum value.
2. This value is transmitted alongside the data block.
3. The receiver applies the identical algorithm to the incoming data block to generate its own checksum.
4. The receiver compares the computed checksum with the transmitted checksum. Any discrepancy indicates that data corruption occurred during transmission.

Marking scheme

1 mark for each correct point, up to a maximum of 4 marks:
- Sender applies an algorithm to calculate a checksum value from the data block [1]
- The calculated checksum is appended/sent with the data [1]
- Receiver calculates a checksum from the received data using the same algorithm [1]
- Receiver compares the transmitted checksum with their calculated checksum [1]
- If they do not match, an error is detected / retransmission is requested [1]
Question 2 · short answer
4 marks
Phishing and pharming are two cyber security threats that target users to obtain confidential data.

Explain two key differences between phishing and pharming.
Show answer & marking scheme

Worked solution

Phishing relies on social engineering, typically sending spam emails or direct messages with a link to a fraudulent website. Pharming is a technical attack that exploits DNS hijacking or local hosts file manipulation to redirect users from a legitimate site to a fake site automatically.

Marking scheme

Up to 4 marks total. 2 marks per fully explained difference:
Difference 1:
- Phishing uses an email/SMS/communication containing a link to direct the user to a fake website [1]
- Pharming redirects the user to a fake website by installing malware on their device or poisoning DNS servers [1]
Difference 2:
- Phishing requires active user interaction (e.g. clicking on a link in an email) [1]
- Pharming automatically redirects the user even when they type in the correct/legitimate web address [1]
Question 3 · short answer
4 marks
The fetch-decode-execute cycle describes how a computer retrieves and executes program instructions.

Describe the role of the Program Counter (PC) and the Memory Address Register (MAR) during the fetch stage of this cycle.
Show answer & marking scheme

Worked solution

During the fetch stage:
1. The PC holds the address of the next instruction.
2. The address stored in the PC is copied to the MAR.
3. The PC is incremented to point to the next instruction in sequence.
4. The MAR uses the address bus to access memory to retrieve the instruction.

Marking scheme

Max 4 marks total (up to 2 marks for PC and up to 2 marks for MAR):
Program Counter (PC):
- Holds the memory address of the next instruction to be fetched [1]
- Copies this address to the MAR at the start of the fetch stage [1]
- Increments (by 1) to point to the next instruction [1]
Memory Address Register (MAR):
- Receives/holds the address of the instruction being fetched [1]
- Sends this address along the address bus to RAM/main memory [1]
Question 4 · short answer
4 marks
A developer is implementing data encryption to secure communication across a network.

State two characteristics of symmetric encryption and two characteristics of asymmetric encryption.
Show answer & marking scheme

Worked solution

Symmetric encryption utilizes a single secret key for both encryption and decryption, meaning sender and receiver must safely share the same key. Asymmetric encryption uses a public key (openly shared to encrypt) and a matching private key (kept secret to decrypt), providing better security at the cost of slower processing speeds.

Marking scheme

Max 4 marks total.
Symmetric encryption (any two, max 2 marks):
- Uses a single/same key to encrypt and decrypt the data [1]
- Requires secure key distribution/exchange before communication begins [1]
- Generally faster/less computationally demanding [1]
Asymmetric encryption (any two, max 2 marks):
- Uses two mathematically linked keys: a public key and a private key [1]
- The public key is used for encryption and the private key is used for decryption (or vice versa) [1]
- The private key is never shared, eliminating key distribution risks [1]
- Generally slower/more computationally intensive than symmetric [1]
Question 5 · long structured explanation
7 marks
A user connects to a secure online banking website using HTTPS. Explain how Secure Socket Layer (SSL) or Transport Layer Security (TLS) is used to establish a secure connection between the user's browser and the bank's server. Your explanation should describe the roles of keys, digital certificates, and the steps involved in the handshake process.
Show answer & marking scheme

Worked solution

1. The browser requests a secure connection (HTTPS) from the web server. 2. The server sends its SSL/TLS certificate, which includes the server's public key, to the browser. 3. The browser validates the certificate against a list of trusted Certificate Authorities (CAs). 4. Once validated, the browser creates a one-time symmetric session key. 5. The browser encrypts this session key using the server's public key and transmits it back. 6. The server uses its private key to decrypt the session key. 7. All subsequent data transmitted between the browser and server is encrypted and decrypted using this shared symmetric session key.

Marking scheme

Award up to 7 marks from the following: 1 mark: Browser requests a secure connection. 1 mark: Server sends its digital certificate containing the public key. 1 mark: Browser verifies the digital certificate with a trusted Certificate Authority (CA). 1 mark: Browser generates a symmetric session key. 1 mark: Browser encrypts the session key using the server's public key. 1 mark: Server decrypts the session key using its private key. 1 mark: Subsequent communication is encrypted using symmetric encryption with the session key. [Accept references to SSL/TLS handshake steps. Max 7 marks.]
Question 6 · long structured explanation
7 marks
The Von Neumann architecture uses a Fetch-Decode-Execute cycle to process program instructions. Describe in detail the stages involved in the Fetch part of this cycle. In your response, clearly state how the Program Counter (PC), Memory Address Register (MAR), Memory Data Register (MDR), and Current Instruction Register (CIR) are used.
Show answer & marking scheme

Worked solution

During the Fetch stage: 1. The PC contains the address of the next instruction to be fetched. 2. This address is copied from the PC to the MAR. 3. The PC is incremented by 1 so that it points to the address of the next sequential instruction. 4. A read signal is sent, and the instruction stored at the memory location currently in the MAR is retrieved. 5. This instruction is transferred from memory to the MDR. 6. The instruction is copied from the MDR to the CIR.

Marking scheme

Award up to 7 marks from the following: 1 mark: PC holds the address of the next instruction. 1 mark: Address is copied from PC to MAR. 1 mark: PC is incremented (by 1). 1 mark: Address is sent to memory via the address bus. 1 mark: Instruction is retrieved from memory and sent via the data bus. 1 mark: Instruction is loaded into the MDR. 1 mark: Instruction is copied from MDR to CIR. [Max 7 marks.]
Question 7 · long structured explanation
7 marks
An industrial monitoring system needs to transmit data from sensors located 1.5 kilometers away back to a central control unit. Compare serial simplex and parallel half-duplex transmission modes. Explain why serial simplex transmission is more suitable for this specific scenario than parallel half-duplex, referring to transmission distance, potential interference, synchronization issues, and cost.
Show answer & marking scheme

Worked solution

Definitions: - Serial simplex: data is sent one bit at a time, sequentially, over a single communication channel, in one direction only. - Parallel half-duplex: multiple bits are sent simultaneously over multiple channels, in both directions but not at the exact same time. Suitability analysis: - Distance/Skewing: Over a 1.5 km distance, parallel transmission would experience skewing (bits arriving at slightly different times due to different wire resistances), making data reconstruction impossible. Serial does not suffer from skewing. - Interference/Crosstalk: Parallel lines experience electromagnetic interference (crosstalk) over long distances, corrupting signals. Serial has no adjacent lines to cause this. - Cost: Laying parallel cables (multiple wires) over 1.5 km is extremely expensive. Serial requires only one channel/wire, making it cost-effective. - Simplex suitability: The sensors only need to output data to the central unit (one-way), so two-way communication (half-duplex) is unnecessary and wasteful.

Marking scheme

Award up to 7 marks from the following: 1 mark: Defines serial simplex (one bit at a time, single wire, one-way). 1 mark: Defines parallel half-duplex (multiple bits at a time, multiple wires, two-way but not simultaneous). 1 mark: Identifies that parallel transmission suffers from skewing over 1.5 km. 1 mark: Identifies that parallel transmission suffers from crosstalk/interference. 1 mark: Explains that serial is much cheaper to install over 1.5 km because it uses a single wire/channel. 1 mark: Explains that simplex is sufficient because sensor transmission is strictly one-way (sensor to controller). 1 mark: Explains that serial maintains signal integrity better over long distances. [Max 7 marks.]
Question 8 · trace / flowchart schematic
4 marks
An algorithm is represented by the following flowchart:

```
[ Start ]


[ Count ← 0 ]
[ Max ← -1 ]


►► < Is Count < 4? > ───(No)───► [ Output Max ] ──► [ Stop ]
▲ │
│ (Yes)
│ │
│ ▼
│ [ Input Num ]
│ │
│ ▼
│ < Is Num > Max? > ───(No)───┐
│ │ │
│ (Yes) │
│ │ │
│ ▼ │
│ [ Max ← Num ] │
│ │ │
│ ▼ │
└── [ Count ← Count + 1 ] ◄─────┘
```

Complete the trace table for the algorithm using the following input data:
`15, 42, 23, 8`

| Count | Max | Num | OUTPUT |
| :---: | :---: | :---: | :---: |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
Show answer & marking scheme

Worked solution

To trace the flowchart step by step:
1. We initialize `Count` to `0` and `Max` to `-1`.
2. Since `Count` (0) is less than 4, we branch to 'Yes' and input the first value, `Num = 15`.
3. `Num > Max` (15 > -1) is true, so `Max` is updated to `15`.
4. `Count` is incremented by 1 to become `1`.
5. Since `Count` (1) is less than 4, we branch to 'Yes' and input the second value, `Num = 42`.
6. `Num > Max` (42 > 15) is true, so `Max` is updated to `42`.
7. `Count` is incremented by 1 to become `2`.
8. Since `Count` (2) is less than 4, we branch to 'Yes' and input the third value, `Num = 23`.
9. `Num > Max` (23 > 42) is false, so we follow the 'No' branch, bypassing the update to `Max`.
10. `Count` is incremented by 1 to become `3`.
11. Since `Count` (3) is less than 4, we branch to 'Yes' and input the fourth value, `Num = 8`.
12. `Num > Max` (8 > 42) is false, so we follow the 'No' branch, bypassing the update to `Max`.
13. `Count` is incremented by 1 to become `4`.
14. Now `Count < 4` is false (4 < 4 is false). We branch to 'No', output the current value of `Max` (which is `42`), and terminate the program.

This yields the completed trace table matching the final state.

Marking scheme

Marks are awarded as follows (total 4 marks):
- 1 mark: Correct initial values of `Count = 0` and `Max = -1` and correct inputs for `Num` (15, 42, 23, 8) in sequence.
- 1 mark: Correct updates to `Max` (updated to 15, then 42, and no other values written in that column).
- 1 mark: Correct sequential increment of `Count` (from 1, 2, 3, up to 4).
- 1 mark: Correct final output of `42` in the OUTPUT column on the final row.
Question 9 · logical conversion scenario
34 marks
A smart automated greenhouse uses an 8-bit microcontroller to monitor and control its internal environment.

An 8-bit status register, named REG_STATUS, stores system flags where each bit represents a specific state or sensor input:
- Bit 7: Heating system status (1 = ON, 0 = OFF)
- Bit 6: Ventilation fan status (1 = ON, 0 = OFF)
- Bit 5: Irrigation valve status (1 = OPEN, 0 = CLOSED)
- Bit 4: High humidity warning (1 = WARNING, 0 = NORMAL)
- Bit 3: Low temperature warning (1 = WARNING, 0 = NORMAL)
- Bit 2: Carbon dioxide levels high (1 = HIGH, 0 = NORMAL)
- Bit 1: Light sensor status (1 = DAYLIGHT, 0 = DARK)
- Bit 0: Security alarm status (1 = ARMED, 0 = DISARMED)

Note: The bits are ordered from left to right (Bit 7 is the Most Significant Bit, Bit 0 is the Least Significant Bit).

(a) The current value stored in REG_STATUS is represented by the Hexadecimal value A5.
(i) Convert the Hexadecimal value A5 into an 8-bit binary pattern. [2]
(ii) Convert the Hexadecimal value A5 into an unsigned denary integer. [2]
(iii) A separate temperature sensor reports a value of -42 as an 8-bit signed integer using two's complement representation. Convert -42 into its 8-bit binary representation. Show your working. [4]

(b) During a system reset procedure, two 8-bit status bytes are added together.
Perform binary addition for the following two unsigned 8-bit binary numbers:
01101100 + 10100101
(i) Write down your binary addition working, showing any carry bits, and the final 8-bit binary result. [4]
(ii) State whether an overflow error has occurred. Explain your answer with reference to the capacity of the 8-bit register. [2]

(c) A register holding the light intensity level contains the binary pattern 00111100 (denary 60).
(i) Perform a logical shift left by 2 places on the binary pattern 00111100. State the resulting 8-bit binary pattern. [2]
(ii) State the denary equivalent of your answer to part (c)(i). Explain the mathematical effect of performing a logical shift left by 2 places on an unsigned binary integer, and state any technical limitation that may occur when performing logical shifts. [4]

(d) Explain two reasons why system programmers prefer to use hexadecimal rather than binary to represent memory addresses and data values in the debugging terminal. [4]

(e) The microcontroller needs to check and modify specific flags in REG_STATUS using bitwise logic.
(i) Identify the logic gate operation and write down an 8-bit binary mask that can be used to check if the Ventilation fan (Bit 6) is currently ON, without altering any other bits in the register. Explain how the microcontroller interprets the output of this operation. [4]
(ii) Identify the logic gate operation and write down an 8-bit binary mask that can be used to force turn OFF the Heating system (Bit 7) and the Irrigation valve (Bit 5) simultaneously, while leaving all other flags unchanged. Show the resulting 8-bit binary pattern if this operation is applied to the initial status value of A5 (10100101). [6]
Show answer & marking scheme

Worked solution

Part (a):
(i) To convert A5 to binary, convert each hexadecimal nibble separately:
- A in hex is 10 in denary, which is 1010 in binary.
- 5 in hex is 5 in denary, which is 0101 in binary.
Combining them yields 10100101.
(ii) To convert A5 to denary:
\( (10 \times 16^1) + (5 \times 16^0) = 160 + 5 = 165 \).
Alternatively, using the binary pattern 10100101:
\( 128 + 32 + 4 + 1 = 165 \).
(iii) To represent -42 using 8-bit two's complement:
1. Write positive 42 in binary: 00101010.
2. Invert (flip) all bits: 11010101.
3. Add 1 to the result: 11010101 + 1 = 11010110.
Checking: \( -128 + 64 + 16 + 4 + 2 = -42 \).

Part (b):
(i) Perform binary addition:
01101100
+ 10100101
--------
Carries: 11001000
Sum: 100010001
Since we only have an 8-bit register, the 8-bit result is 00010001.
(ii) Yes, an overflow error has occurred. The sum of 108 and 165 is 273. The maximum value that can be represented by an 8-bit unsigned integer is \( 2^8 - 1 = 255 \). Because 273 is greater than 255, a 9th bit is generated which cannot fit in the 8-bit register, causing the most significant carry-out bit to be lost.

Part (c):
(i) A logical shift left by 2 places on 00111100 moves all bits two places to the left, discarding the two leftmost bits and padding the rightmost positions with 0s:
00111100 -> 11110000.
(ii) Binary 11110000 converted to denary is \( 128 + 64 + 32 + 16 = 240 \).
A logical shift left by n places multiplies the number by \( 2^n \). Therefore, shifting left by 2 places multiplies the value by \( 2^2 = 4 \) (indeed, \( 60 \times 4 = 240 \)).
The main limitation of this shift is that if any '1' bit is shifted past the boundary of the register (the MSB), it is lost, resulting in an overflow error and producing an incorrect arithmetic result.

Part (d):
Any two valid reasons from:
- Hexadecimal is much more compact and shorter than binary (requires only 2 characters instead of 8 bits), making it easier for humans to read and write.
- Programmers are less likely to make transcription or typing errors when working with hexadecimal codes compared to long strings of zeros and ones.
- It is extremely quick and simple to convert between hexadecimal and binary because exactly 4 bits (a nibble) correspond directly to 1 hexadecimal digit.

Part (e):
(i) To check if a specific bit (Bit 6) is set without modifying other bits, we use the bitwise AND operation with a mask that has a '1' at the target position and '0's elsewhere.
Mask: 01000000.
Logic Operation: AND.
Explanation: The controller performs (REG_STATUS AND 01000000). If the output matches 01000000 (or is non-zero), the bit was 1 (Ventilation fan is ON). If the output is 00000000, the bit was 0 (Ventilation fan is OFF).
(ii) To force bits to 0 (turn off) while leaving other bits unchanged, we use a bitwise AND operation with a mask that has '0's at the target positions (Bit 7 and Bit 5) and '1's everywhere else.
Mask: 01011111.
Logic Operation: AND.
Applying this to the register value A5 (10100101):
10100101 (A5)
AND
01011111 (Mask)
= 00000101 (Result)
Both Bit 7 and Bit 5 have been successfully cleared to 0, while all other bits remain unchanged.

Marking scheme

Part (a): [8 Marks total]
- (i) 1 mark for correct upper nibble (1010), 1 mark for correct lower nibble (0101). [2]
- (ii) 1 mark for correct conversion method shown (e.g. 10 * 16 + 5 or binary column weights 128+32+4+1), 1 mark for correct final answer (165). [2]
- (iii) 1 mark for representing +42 in binary (00101010). 1 mark for inverting bits (11010101). 1 mark for adding 1 (11010110). 1 mark for correct final 8-bit pattern (11010110). [4]

Part (b): [6 Marks total]
- (i) 1 mark for indicating correct carries. 2 marks for showing correct binary addition steps. 1 mark for the correct 8-bit result (00010001). [4]
- (ii) 1 mark for stating that overflow has occurred. 1 mark for explanation (e.g., the sum is 273 which exceeds the 8-bit capacity limit of 255, meaning a 9th bit is required which cannot be stored). [2]

Part (c): [6 Marks total]
- (i) 1 mark for shifting digits left. 1 mark for padding the two rightmost empty slots with 0s to give 11110000. [2]
- (ii) 1 mark for denary value (240). 1 mark for stating it multiplies the number by 4 (or shifts by 2 power of 2). 2 marks for describing the limitation (if a '1' is shifted out of the MSB, it is lost / causes an overflow error / invalidates the multiplication). [4]

Part (d): [4 Marks total]
- Max 2 marks per reason explained (1 mark for identifying the benefit, 1 mark for explanation/expansion). Max 2 reasons.
- Reason 1: Easier to read/write/remember (1) because it is shorter/more compact than binary (1).
- Reason 2: Fewer transcription/input errors made by programmers (1) because there are fewer characters to type and check (1).
- Reason 3: Direct/easy conversion (1) because 1 hex digit corresponds exactly to 4 binary bits / a nibble (1).

Part (e): [10 Marks total]
- (i) 1 mark for identifying AND operation. 1 mark for correct mask (01000000). 2 marks for explanation (1 mark for stating that if the result is 01000000 / non-zero, the fan is ON; 1 mark for stating that if the result is 00000000 / zero, the fan is OFF). [4]
- (ii) 1 mark for identifying AND operation. 2 marks for correct mask (01011111) (accept 1 mark for partially correct mask with only one 0 in the correct position). 1 mark for setting up the calculation (10100101 AND 01011111). 2 marks for correct final binary pattern (00000101) (award 1 mark if only one target bit was correctly cleared and others remained unchanged). [6]

Paper 21: Algorithms, Programming and Logic

Answer all questions. Use of pseudocode or high-level programming code is mandatory where requested. Total marks: 75.
10 Question · 80 marks
Question 1 · concept identify
3 marks
Identify the programming construct (Sequence, Selection, or Iteration) represented by each of the following pseudocode fragments. Fragment 1: OUTPUT 'Enter age' followed by INPUT Age followed by Fare <- 10. Fragment 2: WHILE Counter < 10 DO Counter <- Counter + 1 ENDWHILE. Fragment 3: IF Score > 50 THEN Grade <- 'Pass' ELSE Grade <- 'Fail' ENDIF.
Show answer & marking scheme

Worked solution

Fragment 1 performs statements one after another without branching or looping, which is a Sequence. Fragment 2 uses a WHILE loop to repeat instructions, which is Iteration. Fragment 3 uses an IF-THEN-ELSE structure to choose a path based on a condition, which is Selection.

Marking scheme

1 mark for correctly identifying Fragment 1 as Sequence. 1 mark for correctly identifying Fragment 2 as Iteration. 1 mark for correctly identifying Fragment 3 as Selection.
Question 2 · concept identify
3 marks
Identify the most appropriate basic data type for storing each of the following values in a program. Value 1: The number of students attending a class (e.g. 28). Value 2: The price of a laptop in dollars (e.g. 899.99). Value 3: A student's letter grade (e.g. 'A').
Show answer & marking scheme

Worked solution

Value 1 represents a whole number count, which must be stored as an Integer. Value 2 contains a fractional part representing cents, which must be stored as a Real (or Float). Value 3 represents a single alphanumeric character, which is best stored as a Char (Character) or a String.

Marking scheme

1 mark for Integer (accept Integer/Int). 1 mark for Real (accept Real/Float/Double/Decimal). 1 mark for Char (accept Char/Character/String).
Question 3 · concept identify
3 marks
Identify whether each of the following scenarios is an example of Validation or Verification. Scenario 1: A user is asked to enter their password twice to ensure they typed it correctly. Scenario 2: A system checks if an entered date of birth is in the past and represents a logical age. Scenario 3: A user compares data entered on a screen with the original paper document to check for transcription errors.
Show answer & marking scheme

Worked solution

Scenario 1 is double entry, which is a method of Verification used to ensure that data is entered accurately. Scenario 2 uses logical rules (range and reasonableness checks) to confirm the data is reasonable and follows specified rules, which is Validation. Scenario 3 is visual check, which is a method of Verification.

Marking scheme

1 mark for identifying Scenario 1 as Verification. 1 mark for identifying Scenario 2 as Validation. 1 mark for identifying Scenario 3 as Verification.
Question 4 · written
8 marks
An algorithm is written in pseudocode to find the highest score and count how many students achieved this highest score out of a class of 30 students. The scores are positive integers. | | 01 HighScore <- 0 | 02 Count <- 0 | 03 StudentCount <- 1 | 04 REPEAT | 05 INPUT Score | 06 IF Score > HighScore | 07 THEN | 08 HighScore <- Score | 09 Count <- Count + 1 | 10 ELSE | 11 IF Score <- HighScore | 12 THEN | 13 Count <- Count + 1 | 14 ENDIF | 15 ENDIF | 16 StudentCount <- StudentCount + 1 | 17 UNTIL StudentCount = 30 | 18 OUTPUT "The highest score is ", HighScore, " and was achieved by ", StudentCount, " students." | | Identify the four errors in this pseudocode. For each error, state the line number, describe the error, and write the corrected line of pseudocode.
Show answer & marking scheme

Worked solution

Error 1 occurs on line 09. When a new maximum score is found, the running tally of students achieving this score must be reset to 1 instead of continuing to increment. Correct line: Count <- 1. | Error 2 occurs on line 11. An assignment operator '<-' is incorrectly used inside an IF condition instead of the equality comparison operator '='. Correct line: IF Score = HighScore. | Error 3 occurs on line 17. Because StudentCount starts at 1 and is incremented inside the loop before the UNTIL check, the loop will exit when StudentCount equals 30, meaning only 29 iterations are processed. Correct line: UNTIL StudentCount = 31 or UNTIL StudentCount > 30. | Error 4 occurs on line 18. The output message prints StudentCount (which is the loop counter) instead of the calculated Count variable. Correct line: OUTPUT "The highest score is ", HighScore, " and was achieved by ", Count, " students."

Marking scheme

Award 1 mark for each correctly identified error and its description, up to a maximum of 4 marks. | Award 1 mark for each corresponding corrected line of pseudocode, up to a maximum of 4 marks. | | Error 1: Line 09 | Description: Count incremented instead of reset when a new max is found. | Correction: Count <- 1 | | Error 2: Line 11 | Description: Assignment operator used instead of comparison operator. | Correction: IF Score = HighScore (Accept: IF Score == HighScore) | | Error 3: Line 17 | Description: Loop only runs 29 times instead of 30. | Correction: UNTIL StudentCount = 31 (Accept: UNTIL StudentCount > 30) | | Error 4: Line 18 | Description: Outputs StudentCount instead of Count. | Correction: OUTPUT "The highest score is ", HighScore, " and was achieved by ", Count, " students."
Question 5 · written
8 marks
The following pseudocode function FindValue is intended to search a 1D array NumArray (which contains 100 integers indexed from 1 to 100) for a target integer SearchVal. | | The function must: | - count and output the total number of times SearchVal appears in the array. | - return the array index of the first occurrence of SearchVal. | - return -1 if SearchVal is not found in the array. | | The pseudocode contains several logical errors. | | FUNCTION FindValue(SearchVal : INTEGER) RETURNS INTEGER | DECLARE Index, FirstPos : INTEGER | FirstPos <- 0 | FOR Index <- 1 TO 100 | IF NumArray[Index] = SearchVal | THEN | FirstPos <- Index | ENDIF | NEXT Index | IF FirstPos = 0 | THEN | RETURN -1 | ELSE | RETURN FirstPos | ENDIF | ENDFUNCTION | | (a) Identify three logical errors in the given pseudocode. [3 marks] | (b) Rewrite the complete, corrected pseudocode for the function FindValue so that it performs as intended and is efficient. [5 marks]
Show answer & marking scheme

Worked solution

Part (a): | 1. The code assigns FirstPos <- Index every time a match is found. Consequently, if the value appears multiple times, FirstPos gets overwritten with the last position instead of keeping the first position. | 2. The code completely lacks any counting variable to keep track of the number of matches. | 3. The code does not output the count of occurrences. | | Part (b): | To fix this, we introduce a MatchCount variable. Since we must count all occurrences, we must complete the full loop of 100 iterations. To ensure FirstPos only stores the first occurrence, we check if FirstPos is still 0 before updating it. Finally, we output MatchCount and return the correct value.

Marking scheme

Part (a): Award 1 mark per identified logical error up to 3 marks: | - Overwrites first position / returns last occurrence instead of first. | - No counting mechanism / no counter variable. | - Total count is not output. | | Part (b): Award marks for corrected pseudocode (Max 5): | - 1 mark: Declaring and initializing MatchCount to 0. | - 1 mark: Incrementing MatchCount inside the IF condition. | - 1 mark: Guarding FirstPos update so it only updates on the first match (e.g., IF FirstPos = 0 THEN FirstPos <- Index). | - 1 mark: OUTPUT MatchCount after the loop. | - 1 mark: Correctly returning -1 if FirstPos is 0, else returning FirstPos.
Question 6 · logic gate table & expression trace
9.5 marks
An automated safety system for a greenhouse monitors three physical variables using sensors:
- Soil moisture sensor, S (outputs 1 if soil is dry, 0 if wet)
- Temperature sensor, T (outputs 1 if high, 0 if normal)
- Humidity sensor, H (outputs 1 if high, 0 if normal)

The greenhouse alarm system, A, must trigger (A = 1) if:
- The soil is dry AND the temperature is high, OR
- The temperature is high AND the humidity is NOT high.

(a) Write a Boolean logic expression that represents this greenhouse alarm system. [2.5 marks]

(b) Complete the truth table below for the alarm system output A: [4 marks]

| S | T | H | A |
|---|---|---|---|
| 0 | 0 | 0 | |
| 0 | 0 | 1 | |
| 0 | 1 | 0 | |
| 0 | 1 | 1 | |
| 1 | 0 | 0 | |
| 1 | 0 | 1 | |
| 1 | 1 | 0 | |
| 1 | 1 | 1 | |

(c) A technician wants to implement this circuit using only standard logic gates (AND, OR, NOT). Identify the minimum count of each of these three gates required if the expression is built exactly as written in your answer to part (a) without any further algebraic simplification. [3 marks]
Show answer & marking scheme

Worked solution

Part (a): The problem details are as follows:
- 'The soil is dry AND the temperature is high' translates to: \(S \text{ AND } T\)
- 'The humidity is NOT high' translates to: \(\text{NOT } H\)
- 'The temperature is high AND the humidity is NOT high' translates to: \(T \text{ AND NOT } H\)
- Combining these with the OR condition yields the final expression: \(A = (S \text{ AND } T) \text{ OR } (T \text{ AND NOT } H)\)

Part (b):
- For \(S=0, T=0, H=0\): \((0 \text{ AND } 0) \text{ OR } (0 \text{ AND NOT } 0) = 0 \text{ OR } 0 = 0\)
- For \(S=0, T=0, H=1\): \((0 \text{ AND } 0) \text{ OR } (0 \text{ AND NOT } 1) = 0 \text{ OR } 0 = 0\)
- For \(S=0, T=1, H=0\): \((0 \text{ AND } 1) \text{ OR } (1 \text{ AND NOT } 0) = 0 \text{ OR } 1 = 1\)
- For \(S=0, T=1, H=1\): \((0 \text{ AND } 1) \text{ OR } (1 \text{ AND NOT } 1) = 0 \text{ OR } 0 = 0\)
- For \(S=1, T=0, H=0\): \((1 \text{ AND } 0) \text{ OR } (0 \text{ AND NOT } 0) = 0 \text{ OR } 0 = 0\)
- For \(S=1, T=0, H=1\): \((1 \text{ AND } 0) \text{ OR } (0 \text{ AND NOT } 1) = 0 \text{ OR } 0 = 0\)
- For \(S=1, T=1, H=0\): \((1 \text{ AND } 1) \text{ OR } (1 \text{ AND NOT } 0) = 1 \text{ OR } 1 = 1\)
- For \(S=1, T=1, H=1\): \((1 \text{ AND } 1) \text{ OR } (1 \text{ AND NOT } 1) = 1 \text{ OR } 0 = 1\)

Part (c):
Evaluating the expression: \(A = (S \text{ AND } T) \text{ OR } (T \text{ AND NOT } H)\):
- The sub-expression \(\text{NOT } H\) requires exactly 1 NOT gate.
- The sub-expressions \(S \text{ AND } T\) and \(T \text{ AND (NOT } H)\) require 2 separate AND gates.
- The central \(\text{OR}\) joining the two sub-expressions requires 1 OR gate.

Marking scheme

Part (a) [2.5 marks]:
- 0.5 marks for correct term (S AND T)
- 0.5 marks for correct term (NOT H)
- 0.5 marks for correct term (T AND NOT H)
- 1.0 mark for correctly combining both terms with OR
- Note: Accept alternative notation such as (S . T) + (T . H')

Part (b) [4 marks]:
- 0.5 marks for each correctly evaluated row of the output column A. (8 rows * 0.5 = 4 marks total)

Part (c) [3 marks]:
- 1.0 mark for correctly identifying 1 NOT gate
- 1.0 mark for correctly identifying 2 AND gates
- 1.0 mark for correctly identifying 1 OR gate
Question 7 · logic gate table & expression trace
9.5 marks
An industrial logic system uses three inputs (A, B, and C). The system connections are specified below:
- P is the output of a NOT gate where the input is B.
- Q is the output of an OR gate where the inputs are A and P.
- R is the output of an AND gate where the inputs are B and C.
- X is the final output of an XOR gate where the inputs are Q and R.

(a) Write the complete Boolean expression for the output X using standard Boolean operators (AND, OR, NOT, XOR). [2.5 marks]

(b) Complete the truth table below showing the values for the intermediate outputs P, Q, and R, as well as the final output X. [7 marks]

| A | B | C | P | Q | R | 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

Part (a):
1. Deriving intermediate equations from description:
- \(P = \text{NOT } B\)
- \(Q = A \text{ OR } P = A \text{ OR (NOT } B)\)
- \(R = B \text{ AND } C\)
2. Final Output \(X\):
- \(X = Q \text{ XOR } R = (A \text{ OR (NOT } B)) \text{ XOR } (B \text{ AND } C)\)

Part (b):
Let's trace each combination:
- Row 1 (0,0,0):
\(P = \text{NOT } 0 = 1\);
\(Q = 0 \text{ OR } 1 = 1\);
\(R = 0 \text{ AND } 0 = 0\);
\(X = 1 \text{ XOR } 0 = 1\).
- Row 2 (0,0,1):
\(P = \text{NOT } 0 = 1\);
\(Q = 0 \text{ OR } 1 = 1\);
\(R = 0 \text{ AND } 1 = 0\);
\(X = 1 \text{ XOR } 0 = 1\).
- Row 3 (0,1,0):
\(P = \text{NOT } 1 = 0\);
\(Q = 0 \text{ OR } 0 = 0\);
\(R = 1 \text{ AND } 0 = 0\);
\(X = 0 \text{ XOR } 0 = 0\).
- Row 4 (0,1,1):
\(P = \text{NOT } 1 = 0\);
\(Q = 0 \text{ OR } 0 = 0\);
\(R = 1 \text{ AND } 1 = 1\);
\(X = 0 \text{ XOR } 1 = 1\).
- Row 5 (1,0,0):
\(P = \text{NOT } 0 = 1\);
\(Q = 1 \text{ OR } 1 = 1\);
\(R = 0 \text{ AND } 0 = 0\);
\(X = 1 \text{ XOR } 0 = 1\).
- Row 6 (1,0,1):
\(P = \text{NOT } 0 = 1\);
\(Q = 1 \text{ OR } 1 = 1\);
\(R = 0 \text{ AND } 1 = 0\);
\(X = 1 \text{ XOR } 0 = 1\).
- Row 7 (1,1,0):
\(P = \text{NOT } 1 = 0\);
\(Q = 1 \text{ OR } 0 = 1\);
\(R = 1 \text{ AND } 0 = 0\);
\(X = 1 \text{ XOR } 0 = 1\).
- Row 8 (1,1,1):
\(P = \text{NOT } 1 = 0\);
\(Q = 1 \text{ OR } 0 = 1\);
\(R = 1 \text{ AND } 1 = 1\);
\(X = 1 \text{ XOR } 1 = 0\).

Marking scheme

Part (a) [2.5 marks]:
- 0.5 marks for defining P = NOT B
- 0.5 marks for Q = A OR P (or A OR NOT B)
- 0.5 marks for R = B AND C
- 1.0 mark for correctly combining Q and R using XOR (X = Q XOR R)

Part (b) [7 marks]:
- 1.5 marks for correct Column P (all 8 values correct; award 1.0 mark if 6-7 values are correct; 0.5 marks if 4-5 are correct; otherwise 0)
- 1.5 marks for correct Column Q (all 8 values correct; award 1.0 mark if 6-7 values are correct; 0.5 marks if 4-5 are correct; otherwise 0)
- 2.0 marks for correct Column R (all 8 values correct; award 1.5 marks if 6-7 values are correct; 1.0 mark if 4-5 are correct; 0.5 marks if 2-3 are correct; otherwise 0)
- 2.0 marks for correct Column X (all 8 values correct; award 1.5 marks if 6-7 values are correct; 1.0 mark if 4-5 are correct; 0.5 marks if 2-3 are correct; otherwise 0)
Question 8 · database
6 marks
A database table, BIKE_RENTAL, is used to keep track of bicycles available for hire at a rental shop. The table has the following fields: BikeID (text), BikeType (text), DailyRate (currency), Available (boolean), and LastServiceDate (date). (a) Identify the field that would be most suitable as the primary key and state a reason for your choice. [2 marks] (b) Write an SQL query to display the BikeID, BikeType, and DailyRate for all bikes that have a BikeType of 'Mountain' and are currently Available (value is TRUE). The output should be sorted in descending order of DailyRate. [4 marks]
Show answer & marking scheme

Worked solution

Part (a): To uniquely identify each row in a database table, a primary key is required. Fields like BikeType, DailyRate, Available, and LastServiceDate are not guaranteed to be unique (multiple bikes can be Mountain bikes, have the same rate, or be serviced on the same day). Therefore, BikeID is chosen as the primary key because it assigns a completely unique code to each individual bicycle. Part (b): Writing the SQL query requires four clauses: 1. SELECT clause to specify the projected columns (BikeID, BikeType, DailyRate). 2. FROM clause to identify the source table (BIKE_RENTAL). 3. WHERE clause to filter records where BikeType is 'Mountain' AND Available is TRUE. 4. ORDER BY clause to sort the results by DailyRate in descending order (DESC).

Marking scheme

Part (a) [2 marks total]: - 1 mark for identifying 'BikeID' as the primary key. - 1 mark for a valid explanation, e.g., it contains unique values for each record / uniquely identifies each bicycle. Part (b) [4 marks total]: - 1 mark: SELECT BikeID, BikeType, DailyRate (must contain all three correct fields, separated by commas). - 1 mark: FROM BIKE_RENTAL. - 1 mark: WHERE BikeType = 'Mountain' AND Available = TRUE (accept Available = 'TRUE', Available = Yes, or Available = 1; accept logical AND). - 1 mark: ORDER BY DailyRate DESC (accept DESCENDING).
Question 9 · long-response
15 marks
An athletic club needs a program to record and analyze the sprint times of their athletes during a 100-meter training session. Write an algorithm in pseudocode or high-level program code that meets the following requirements: 1. Prompt and input the number of athletes. This value must be validated to ensure it is between 5 and 30 inclusive. 2. For each athlete, input and store their name and their sprint time (in seconds). The sprint time must be validated to ensure it is between 8.0 and 25.0 seconds inclusive. Use parallel one-dimensional arrays to store the names and times. 3. Calculate and output: - The average sprint time of all athletes. - The name and sprint time of the fastest athlete (the one with the lowest time). - The total number of athletes who completed the run in under 12.0 seconds, along with the percentage this represents of the total group. You must use clear variable names and include comments to explain how your code works.
Show answer & marking scheme

Worked solution

DECLARE Names : ARRAY[1:30] OF STRING; DECLARE Times : ARRAY[1:30] OF REAL; DECLARE NumAthletes, CountUnder12, Index : INTEGER; DECLARE AvgTime, LowestTime, TotalTime, Percentage : REAL; DECLARE FastestName : STRING; REPEAT OUTPUT "Enter the number of athletes (5 to 30): "; INPUT NumAthletes UNTIL NumAthletes >= 5 AND NumAthletes <= 30; TotalTime <- 0.0; CountUnder12 <- 0; LowestTime <- 999.0; FOR Index <- 1 TO NumAthletes OUTPUT "Enter name for athlete ", Index, ": "; INPUT Names[Index]; REPEAT OUTPUT "Enter 100m sprint time in seconds: "; INPUT Times[Index] UNTIL Times[Index] >= 8.0 AND Times[Index] <= 25.0; TotalTime <- TotalTime + Times[Index]; IF Times[Index] < 12.0 THEN CountUnder12 <- CountUnder12 + 1 ENDIF; IF Times[Index] < LowestTime THEN LowestTime <- Times[Index]; FastestName <- Names[Index] ENDIF; NEXT Index; AvgTime <- TotalTime / NumAthletes; Percentage <- (CountUnder12 / NumAthletes) * 100; OUTPUT "Average sprint time: ", AvgTime, " seconds"; OUTPUT "Fastest athlete: ", FastestName, " with a time of ", LowestTime, " seconds"; OUTPUT "Athletes under 12.0 seconds: ", CountUnder12; OUTPUT "Percentage under 12.0 seconds: ", Percentage, "%"

Marking scheme

Validation of Number of Athletes (Max 3 marks): - 1 mark: Prompt and input the number of athletes. - 1 mark: Use of a post-assertion / validation loop (e.g., REPEAT...UNTIL or WHILE). - 1 mark: Correct validation logic (between 5 and 30 inclusive). Data Entry and Parallel Arrays (Max 3 marks): - 1 mark: Loop that repeats exactly the number of times entered by the user. - 1 mark: Input and store athlete name in a 1D array. - 1 mark: Input and store sprint time in a parallel 1D array. Validation of Sprint Times (Max 2 marks): - 1 mark: Loop used to ensure the time entry is re-prompted if invalid. - 1 mark: Correct validation range logic (between 8.0 and 25.0 inclusive). Calculations and Performance Analysis (Max 5 marks): - 1 mark: Keeping a running total of all sprint times inside the loop. - 1 mark: Correctly calculating the average after the loop concludes. - 1 mark: Checking for the fastest athlete (finding the minimum time) using a conditional statement inside the loop. - 1 mark: Correctly updating and saving the corresponding athlete's name along with the minimum time. - 1 mark: Counting how many athletes ran under 12.0 seconds. Outputs and Code Quality (Max 2 marks): - 1 mark: Correctly calculating and outputting the percentage of athletes under 12.0 seconds. - 1 mark: Meaningful variable names and clear comments used throughout the program.
Question 10 · long-response
15 marks
An athletic club needs a program to record and analyze the sprint times of their athletes during a 100-meter training session. Write an algorithm in pseudocode or high-level program code that meets the following requirements: 1. Prompt and input the number of athletes. This value must be validated to ensure it is between 5 and 30 inclusive. 2. For each athlete, input and store their name and their sprint time (in seconds). The sprint time must be validated to ensure it is between 8.0 and 25.0 seconds inclusive. Use parallel one-dimensional arrays to store the names and times. 3. Calculate and output: - The average sprint time of all athletes. - The name and sprint time of the fastest athlete (the one with the lowest time). - The total number of athletes who completed the run in under 12.0 seconds, along with the percentage this represents of the total group. You must use clear variable names and include comments to explain how your code works.
Show answer & marking scheme

Worked solution

DECLARE Names : ARRAY[1:30] OF STRING; DECLARE Times : ARRAY[1:30] OF REAL; DECLARE NumAthletes, CountUnder12, Index : INTEGER; DECLARE AvgTime, LowestTime, TotalTime, Percentage : REAL; DECLARE FastestName : STRING; REPEAT OUTPUT "Enter the number of athletes (5 to 30): "; INPUT NumAthletes UNTIL NumAthletes >= 5 AND NumAthletes <= 30; TotalTime <- 0.0; CountUnder12 <- 0; LowestTime <- 999.0; FOR Index <- 1 TO NumAthletes OUTPUT "Enter name for athlete ", Index, ": "; INPUT Names[Index]; REPEAT OUTPUT "Enter 100m sprint time in seconds: "; INPUT Times[Index] UNTIL Times[Index] >= 8.0 AND Times[Index] <= 25.0; TotalTime <- TotalTime + Times[Index]; IF Times[Index] < 12.0 THEN CountUnder12 <- CountUnder12 + 1 ENDIF; IF Times[Index] < LowestTime THEN LowestTime <- Times[Index]; FastestName <- Names[Index] ENDIF; NEXT Index; AvgTime <- TotalTime / NumAthletes; Percentage <- (CountUnder12 / NumAthletes) * 100; OUTPUT "Average sprint time: ", AvgTime, " seconds"; OUTPUT "Fastest athlete: ", FastestName, " with a time of ", LowestTime, " seconds"; OUTPUT "Athletes under 12.0 seconds: ", CountUnder12; OUTPUT "Percentage under 12.0 seconds: ", Percentage, "%"

Marking scheme

Validation of Number of Athletes (Max 3 marks): - 1 mark: Prompt and input the number of athletes. - 1 mark: Use of a post-assertion / validation loop (e.g., REPEAT...UNTIL or WHILE). - 1 mark: Correct validation logic (between 5 and 30 inclusive). Data Entry and Parallel Arrays (Max 3 marks): - 1 mark: Loop that repeats exactly the number of times entered by the user. - 1 mark: Input and store athlete name in a 1D array. - 1 mark: Input and store sprint time in a parallel 1D array. Validation of Sprint Times (Max 2 marks): - 1 mark: Loop used to ensure the time entry is re-prompted if invalid. - 1 mark: Correct validation range logic (between 8.0 and 25.0 inclusive). Calculations and Performance Analysis (Max 5 marks): - 1 mark: Keeping a running total of all sprint times inside the loop. - 1 mark: Correctly calculating the average after the loop concludes. - 1 mark: Checking for the fastest athlete (finding the minimum time) using a conditional statement inside the loop. - 1 mark: Correctly updating and saving the corresponding athlete's name along with the minimum time. - 1 mark: Counting how many athletes ran under 12.0 seconds. Outputs and Code Quality (Max 2 marks): - 1 mark: Correctly calculating and outputting the percentage of athletes under 12.0 seconds. - 1 mark: Meaningful variable names and clear comments used throughout the program.

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