Cambridge IAS-Level · thinka-original Practice Paper

2026 Cambridge IAS-Level Computer Science (9618) Practice Paper with Answers

Thinka Jun 2026 (V3) Cambridge International AS Level-Style Mock — Computer Science (9618)

150 marks210 mins2026
An original Thinka practice paper modelled on the structure and difficulty of the Jun 2026 (V3) Cambridge International AS Level Computer Science (9618) paper. Not affiliated with or reproduced from Cambridge.

Paper 1: Theory Fundamentals

Answer all questions. Calculators must not be used. Write answers clearly in the spaces provided.
9 Question · 75 marks
Question 1 · short-answer
4 marks
Complete the sentences about digital representations of images and sound by writing the correct technical term in each space.

(i) The smallest individual picture element of a bitmap image that can be independently assigned a colour is a ....................................................

(ii) The number of bits used to represent the colour of an individual pixel in a bitmap graphic is the ....................................................

(iii) In sound recording, the number of audio samples captured per second is referred to as the ....................................................

(iv) The number of bits allocated to store the amplitude value of each individual sound sample is the ....................................................
Show answer & marking scheme

Worked solution

(i) Pixel: A pixel (picture element) is the smallest addressable discrete component of a bitmap image.
(ii) Colour depth: Also termed bit depth, it defines the number of bits allocated per pixel to specify its colour value.
(iii) Sampling rate: The frequency at which analogue sound amplitudes are measured per second (measured in Hertz, Hz).
(iv) Sampling resolution: The bit depth/precision specifying the number of bits allocated to encode each sampled amplitude level.

Marking scheme

1 mark per correct technical term:
(i) Pixel // Picture element [1]
(ii) Colour depth // Bit depth [1]
(iii) Sampling rate // Sample rate // Sampling frequency [1]
(iv) Sampling resolution // Sample resolution // Audio bit depth // Sample size [1]
Question 2 · short-answer
4 marks
Identify the CPU register described by each of the following statements.

(i) Holds the memory address of the next instruction waiting to be fetched from main storage: ....................................................

(ii) Holds data that has been read from, or is waiting to be written to, a memory location: ....................................................

(iii) Holds the binary instruction currently undergoing decoding and execution: ....................................................

(iv) A general-purpose register that stores intermediate results produced during arithmetic and logical processing: ....................................................
Show answer & marking scheme

Worked solution

(i) Program Counter (PC): Increments automatically during the fetch phase to point to the subsequent instruction in memory.
(ii) Memory Data Register (MDR): Interfaces with the data bus to hold data fetched from RAM or prepared for a write operation.
(iii) Current Instruction Register (CIR): Stores the fetched instruction while the Control Unit decodes the opcode and operand.
(iv) Accumulator (ACC): Serves as the primary working register in the ALU where mathematical and logical evaluation outputs are temporarily held.

Marking scheme

1 mark for each correctly identified register (abbreviations or full names accepted):
(i) Program Counter // PC [1]
(ii) Memory Data Register // MDR // Memory Buffer Register // MBR [1]
(iii) Current Instruction Register // CIR [1]
(iv) Accumulator // ACC [1]
Question 3 · theory
13 marks
A field research station records environmental audio clips and high-resolution photographs of wildlife.

(a) The audio clips are recorded digitally.

(i) Explain the terms sampling rate and sampling resolution in the context of digital sound recording.

Sampling rate:
................................................................................................................................................................
................................................................................................................................................................

Sampling resolution:
................................................................................................................................................................
................................................................................................................................................................
[4]

(ii) An audio recording has the following properties:
- Sampling rate: 40,000 Hz
- Sampling resolution: 16 bits
- Number of channels: 2 (stereo)
- Duration: 64 seconds

Calculate the file size of the uncompressed audio recording in kibibytes (KiB). Show your working.

Working:
................................................................................................................................................................
................................................................................................................................................................

File size: .................................................... KiB
[3]

(b) The station also captures bitmap images.

Explain why a bitmap image file requires a file header and state two items of data typically stored in the file header.

Explanation:
................................................................................................................................................................
................................................................................................................................................................

Item 1: ........................................................................................................................................................

Item 2: ........................................................................................................................................................
[3]

(c) The research team decides to store their media files in cloud storage rather than exclusively on local secondary storage.

Explain two benefits and one drawback of using cloud storage for these media files.

Benefit 1:
................................................................................................................................................................
................................................................................................................................................................

Benefit 2:
................................................................................................................................................................
................................................................................................................................................................

Drawback:
................................................................................................................................................................
................................................................................................................................................................
[3]
Show answer & marking scheme

Worked solution

(a)(i)
Sampling rate:
- The number of sound samples (measurements of amplitude) taken per unit of time / per second.
- Measured in Hertz (Hz) / determines the maximum frequency that can be accurately represented.

Sampling resolution:
- The number of bits used to encode / store each sample value.
- Determines the dynamic range / number of discrete amplitude levels available for quantisation.

(a)(ii)
1. Total bits = Sampling rate × Sampling resolution × Channels × Duration
\(\text{Total bits} = 40\,000 \times 16 \times 2 \times 64 = 81\,920\,000\text{ bits}\)
2. Convert to bytes:
\(\text{Total bytes} = 40\,000 \times 2 \times 2 \times 64 = 5\,120\,000\text{ bytes}\)
3. Convert to Kibibytes (KiB) by dividing by 1024:
\(\text{Size in KiB} = \frac{5\,120\,000}{1024} = 5000\text{ KiB}\)

(b)
Explanation:
- The file header contains metadata that informs the application / operating system how the raw pixel byte stream is structured so that the image can be decoded and displayed properly.
Items of data (any two):
- Image dimensions (width and height in pixels)
- Colour depth / bit depth
- File size / header size
- Type of compression (if used)
- Offset to the start of pixel data

(c)
Benefits (any two):
- Accessibility: Files can be accessed by researchers from anywhere with an Internet connection.
- Redundancy / Backup: Cloud providers offer automated backups and disaster recovery, protecting research data against local hardware failure or loss.
- Scalability: Easy to increase storage capacity on demand as more media files are gathered, without investing in physical storage hardware.
- Collaboration: Easy sharing of files across multiple researchers / teams.

Drawback (any one):
- Requires a reliable / high-speed internet connection; without it, accessing or uploading large media files is impossible or slow.
- Ongoing subscription costs over time.
- Security / privacy risks associated with storing sensitive research data on third-party servers.

Marking scheme

(a)(i) Max 4 marks:
Sampling rate:
- MP1: Number of sound samples / amplitude measurements taken per second / unit time. [1]
- MP2: Measured in Hertz (Hz) // higher rate gives closer reproduction of original wave. [1]
Sampling resolution:
- MP3: Number of bits used to represent / store each sample. [1]
- MP4: Determines the number of discrete amplitude / quantisation levels available. [1]

(a)(ii) Max 3 marks:
- MP1: Correct calculation of total bits or bytes \(40\,000 \times 16 \times 2 \times 64\) or \(5\,120\,000\) bytes. [1]
- MP2: Division by 1024 (or \(8 \times 1024\) if starting from bits). [1]
- MP3: Correct final answer: 5000 (KiB). [1]
(Allow full marks for correct answer with working; allow 2 marks max if 5000 is given without working)

(b) Max 3 marks:
- MP1: Explanation that header stores metadata needed by software to correctly interpret / reconstruct / display the pixel data. [1]
- MP2 & MP3: Any two valid header contents [1 mark each, max 2]:
- Image dimensions / width and height / image resolution
- Colour depth / bit depth / bits per pixel
- File size / header size
- Compression type
- Offset to raw pixel data
(Reject: author name, date taken unless qualified as EXIF data, generic filename)

(c) Max 3 marks:
- MP1: First valid benefit explained (e.g. remote access from any location, automatic backups / disaster recovery, easy scalability). [1]
- MP2: Second valid benefit explained. [1]
- MP3: Valid drawback explained (e.g. dependent on reliable/fast internet connection to upload/download large media files, ongoing subscription costs, potential security/data privacy risks on third-party servers). [1]
Question 4 · theory
17 marks
SoundCraft Repairs is a specialist workshop that restores and repairs acoustic musical instruments. Details of repair jobs, clients, technicians, and work logs are recorded in a relational database.

(a) (i) State what is meant by referential integrity in a relational database. [2]

(ii) Explain one problem caused by data redundancy in a file-based approach compared to a relational database. [2]

(b) The workshop initially records job assignments using the following table in First Normal Form (1NF):

WORK_LOG(JobID, TechnicianID, JobDate, ClientID, ClientName, ClientPhone, TechName, TechRate, HoursSpent)

Primary Key: (JobID, TechnicianID)

(i) Explain why the WORK_LOG table is not in Second Normal Form (2NF). [2]

(ii) Normalise the data into Third Normal Form (3NF).

Write the database schema for the tables in 3NF using the format:
TableName(Attribute1, Attribute2, ...)

Underline all primary key attributes and clearly identify all foreign key attributes. [5]

(c) (i) Write a Data Definition Language (DDL) SQL script to create a table named TECHNICIAN. The table must contain the following fields:
- TechnicianID: fixed-length character string of 5 characters, primary key
- TechName: variable-length character string of up to 40 characters
- TechRate: real/floating-point number
- IsCertified: boolean value [3]

(ii) Write a Data Manipulation Language (DML) SQL script to display the JobID, TechName, and HoursSpent for all records where HoursSpent is strictly greater than 4.0. The results must be sorted in descending order of HoursSpent. [3]
Show answer & marking scheme

Worked solution

(a) (i)
- Referential integrity is a database property ensuring that relationships between tables remain consistent / valid.
- A foreign key value in a referencing table must match an existing primary key value in the referenced table (or be NULL) // Ensures there are no orphan records.

(ii)
- When the same data item is stored in multiple places, updating an item in one location but not another causes data inconsistency / update anomalies.
- Redundant data wastes secondary storage space / requires unnecessary duplicate data entry.

(b) (i)
- A table is in 2NF if it is in 1NF and contains no partial dependencies (every non-key attribute is fully functionally dependent on the entire primary key).
- In WORK_LOG, non-key attributes depend on only part of the composite primary key (JobID, TechnicianID):
* JobDate, ClientID, ClientName, ClientPhone depend only on JobID.
* TechName, TechRate depend only on TechnicianID.

(ii)
In 2NF, tables are split to remove partial dependencies:
- JOB(JobID, JobDate, ClientID, ClientName, ClientPhone)
- TECHNICIAN(TechnicianID, TechName, TechRate)
- JOB_ASSIGNMENT(JobID, TechnicianID, HoursSpent)

In 3NF, transitive dependencies are removed (ClientName and ClientPhone depend on ClientID, which depends on JobID):

3NF Database Schema:
CLIENT(ClientID, ClientName, ClientPhone)
Primary Key: ClientID

REPAIR_JOB(JobID, JobDate, ClientID)
Primary Key: JobID
Foreign Key: ClientID references CLIENT(ClientID)

TECHNICIAN(TechnicianID, TechName, TechRate)
Primary Key: TechnicianID

JOB_ASSIGNMENT(JobID, TechnicianID, HoursSpent)
Primary Key: (JobID, TechnicianID)
Foreign Keys: JobID references REPAIR_JOB(JobID), TechnicianID references TECHNICIAN(TechnicianID)

(c) (i)
CREATE TABLE TECHNICIAN (
TechnicianID CHARACTER(5),
TechName VARCHAR(40),
TechRate REAL,
IsCertified BOOLEAN,
PRIMARY KEY (TechnicianID)
);

(c) (ii)
SELECT JOB_ASSIGNMENT.JobID, TECHNICIAN.TechName, JOB_ASSIGNMENT.HoursSpent
FROM JOB_ASSIGNMENT
INNER JOIN TECHNICIAN ON JOB_ASSIGNMENT.TechnicianID = TECHNICIAN.TechnicianID
WHERE JOB_ASSIGNMENT.HoursSpent > 4.0
ORDER BY JOB_ASSIGNMENT.HoursSpent DESC;

Marking scheme

(a) (i) 1 mark per point to max 2:
- Foreign key value in one table must match an existing primary key value in the related/referenced table // Foreign key must reference a valid record [1]
- Prevents orphan records / maintains consistency across linked tables [1]

(a) (ii) 1 mark for identification of problem, 1 mark for explanation:
- Data inconsistency / update anomaly [1]
- ...because updating a field in one file requires manual updates in all other files containing that data, and omitting an update leads to conflicting records [1]
OR
- Wasted storage space [1]
- ...because duplicate copies of identical attributes/records are stored repeatedly across files [1]

(b) (i) 1 mark per point to max 2:
- Definition: Non-key attributes are dependent on only part of the composite primary key / there are partial dependencies [1]
- Specific context: JobDate / ClientID / ClientName / ClientPhone depend only on JobID // TechName / TechRate depend only on TechnicianID [1]

(b) (ii) Max 5 marks:
- CLIENT table correct with ClientID as PK [1]
- REPAIR_JOB table correct with JobID as PK and ClientID as FK [1]
- TECHNICIAN table correct with TechnicianID as PK [1]
- JOB_ASSIGNMENT (linking) table correct with composite PK (JobID, TechnicianID) and HoursSpent [1]
- All primary keys clearly underlined and foreign keys identified across all four tables [1]

(c) (i) 1 mark per point to max 3:
- CREATE TABLE TECHNICIAN (...) with correct syntax and closing semicolon [1]
- Correct attribute names and standard SQL data types: TechnicianID CHARACTER(5) / CHAR(5), TechName VARCHAR(40), TechRate REAL / FLOAT / DECIMAL / NUMERIC, IsCertified BOOLEAN [1]
- PRIMARY KEY (TechnicianID) correctly declared [1]

(c) (ii) 1 mark per point to max 3:
- SELECT JobID, TechName, HoursSpent FROM JOB_ASSIGNMENT / WORK_LOG (with correct table prefixing or unqualified if unambiguous) [1]
- INNER JOIN TECHNICIAN ON ... / WHERE ... = ... AND HoursSpent > 4.0 [1]
- ORDER BY HoursSpent DESC (accept table-prefixed attribute) [1]
Question 5 · structured
10 marks
A software company is developing a new desktop financial application.

(a) The application uses Dynamic Link Library (DLL) files.

(i) Describe the role of a Dynamic Link Library (DLL) file. [2]

(ii) State two benefits of using DLL files instead of static program libraries. [2]

(b) The software developers write the program source code using an Integrated Development Environment (IDE).

Identify two debugging features provided by an IDE. Explain how each feature assists the programmer in locating or correcting errors. [4]

Feature 1:
Explanation:

Feature 2:
Explanation:

(c) The operating system on the user's computer includes several utility programs to manage storage media.

Describe the function of each of the following utilities:

(i) Disk defragmenter [1]

(ii) Disk repair utility [1]
Show answer & marking scheme

Worked solution

(a) (i) A Dynamic Link Library (DLL) contains pre-compiled modules/subroutines that are loaded into memory and dynamically linked to an executing application at run-time rather than during compilation.

(ii) Benefits of DLLs:
- Multiple programs can share a single copy of the DLL in RAM, conserving primary memory.
- Modular updates: fixes and updates can be applied to the DLL without recompiling or relinking the main application executable.
- Reduces executable file size on disk as library code is not embedded directly in the binary.

(b) Debugging features:
- Breakpoint: Sets a marker in code where execution pauses automatically, allowing the programmer to view current register/variable values and evaluate program state.
- Single stepping (Step into / Step over): Runs the program line by line under user control, allowing the programmer to observe control flow and pinpoint the exact line where an error occurs.
- Watch window / Variable inspection: Displays real-time values of specified variables as execution progresses, making it easy to identify when a variable takes an incorrect value.

(c) (i) Disk defragmenter: Rearranges the blocks/fragments of files spread across non-contiguous areas on a magnetic hard disk into contiguous sectors, decreasing drive head movement and speeding up file access.
(ii) Disk repair utility: Scans the file system for corrupted sectors/file table entries, attempts to recover readable information, and marks defective sectors to prevent future data write operations to them.

Marking scheme

(a)(i) Max 2 marks:
- Contains pre-compiled routines / code modules / procedures [1]
- Linked/loaded at run-time / only loaded into memory when required (not at compile time) [1]

(a)(ii) 1 mark for each valid benefit (Max 2):
- Conserves main memory / RAM (as multiple programs share one copy in memory) [1]
- Updates/bug fixes can be made to the DLL without recompiling the main program [1]
- Reduces disk space / smaller executable file size [1]
- Code reusability across different applications [1]

(b) 1 mark for identifying the feature, 1 mark for valid explanation of its debugging role (Max 4):
- Breakpoint [1]: Pauses execution at a specific line of code to allow checking of variable/register contents at that point [1]
- Stepping / Single stepping [1]: Executes code one line/instruction at a time so the programmer can observe the flow of execution / changes to data after each line [1]
- Watch window / Variable watch [1]: Continuously tracks and displays the value of selected variables as the code runs [1]
- Variable tracing / Inspector [1]: Allows the programmer to hover over/examine current variable contents during pause [1]
(Accept: Stack trace / Call stack [1] with valid explanation [1])
(Reject: Syntax highlighting / Auto-complete as they are presentation/coding features, not debugging features)

(c)(i) 1 mark for:
- Rearranges non-contiguous file fragments / clusters so that files are stored in contiguous sectors // reduces read/write head movement [1]

(c)(ii) 1 mark for:
- Checks disk for errors / bad sectors / corrupted file tables AND fixes them / marks bad sectors so they are not used [1]
Question 6 · none
0 marks
Question 7 · structured
8 marks
(a) Represent the denary value \(-75\) as an 8-bit signed integer in two's complement form. Show your working.

(b) Two 8-bit signed two's complement binary integers are given:

\[\text{Integer } P = 01011000_2\]
\[\text{Integer } Q = 00111101_2\]

(i) Add the two binary integers \(P\) and \(Q\). Show your working.

(ii) State whether an overflow error has occurred in this addition. Justify your answer.

(c) (i) Convert the denary integer \(438\) into Binary Coded Decimal (BCD).

(ii) State one reason or situation where BCD is used instead of standard binary representation.
Show answer & marking scheme

Worked solution

(a) Working:
- Denary +75 in 8-bit binary: \(01001011_2\)
- Invert all bits (one's complement): \(10110100_2\)
- Add 1: \(10110100_2 + 1 = 10110101_2\)
(Alternatively: place values \(-128 + 32 + 16 + 4 + 1 = -75\) gives \(10110101_2\)).

(b) (i)
01011000 (88)
+ 00111101 (61)
------------
10010101
Carries: bit positions 6 and 7 carry forward to bit 8.
Binary sum = \(10010101_2\)

(ii)
- Overflow: Yes.
- Justification: Adding two positive numbers (MSB = 0) resulted in a negative value (MSB = 1) // The sum (149) exceeds the maximum representable value (+127) for an 8-bit signed two's complement number.

(c) (i)
Each denary digit is converted to a 4-bit binary group:
- 4 = 0100
- 3 = 0011
- 8 = 1000
BCD = \(0100\ 0011\ 1000_2\)

(ii)
- Used to drive digital 7-segment displays / digital clocks where each decimal digit is displayed separately.
- Used in financial and accounting applications to eliminate rounding errors caused by converting decimal fractions to binary.

Marking scheme

(a) [2 marks]
- 1 mark for correct working (e.g. showing +75 as 01001011 and inverting / adding 1, or correct place-value calculation).
- 1 mark for final binary value: 10110101.

(b)(i) [2 marks]
- 1 mark for evidence of binary addition with carries shown.
- 1 mark for correct sum: 10010101.

(b)(ii) [2 marks]
- 1 mark for stating that overflow occurred / Yes.
- 1 mark for valid justification: addition of two positive numbers gives a negative result // result (+149) is outside the allowable range (-128 to +127) // carry into sign bit without carry out.

(c)(i) [1 mark]
- 1 mark for 010000111000 / 0100 0011 1000.

(c)(ii) [1 mark]
- 1 mark for any valid use case:
- Driving digital / 7-segment displays / digital clocks / meters.
- Financial / currency calculations (to prevent fractional decimal rounding errors).
- Easy conversion directly to/from character-based representations.
Question 8 · short_answer
9 marks
An embedded processor in an automated sorting system uses assembly language instructions to process sensor readings and manage data storage.

(a) Explain the difference between direct addressing and indirect addressing.

(b) The main memory of the processor holds the following contents at the specified addresses:

$$\begin{array}{|c|c|}
\hline
\textbf{Memory address} & \textbf{Contents} \\
\hline
200 & 204 \\
\hline
201 & 15 \\
\hline
202 & 48 \\
\hline
203 & 201 \\
\hline
204 & 72 \\
\hline
\end{array}$$

The Index Register (IX) currently contains the denary value 2.

State the denary value loaded into the Accumulator (ACC) after the execution of each of the following independent instructions:

(i) `LDD 201`

(ii) `LDI 200`

(iii) `LDX 201`

(c) A status register representing 8 digital inputs contains the binary byte value:

$$\text{B}11010110$$

Bit positions are numbered 7 (most significant bit) down to 0 (least significant bit).

(i) State an assembly instruction, using an immediate binary or hexadecimal operand, to mask and test bit 4 while setting all other bits to 0.

(ii) The processor executes the instruction `LSL #3` on the original contents of the Accumulator (`B11010110`).

1. State the binary value stored in the Accumulator after this instruction is executed.

2. Explain the intended mathematical effect of performing a logical shift left by 3 bits on an unsigned binary integer, and state why this mathematical effect produces an incorrect result for `B11010110`.
Show answer & marking scheme

Worked solution

(a)
- Direct addressing: The operand specified in the instruction is the actual memory address where the data/value to be used is stored.
- Indirect addressing: The operand is a memory address that contains the memory address of the data to be used (a pointer to the data).

(b)
(i) `LDD 201`: Directly loads the content of memory address 201 -> 15.
(ii) `LDI 200`: Finds the address at location 200 (which is 204), then loads the content at address 204 -> 72.
(iii) `LDX 201`: Adds the value of the Index Register (IX = 2) to the base address 201 to get effective address $201 + 2 = 203$, then loads the content of address 203 -> 201.

(c)
(i) Bit 4 corresponds to position $2^4$, which is binary `00010000` (hex `&10` or denary 16). The bitwise operation is `AND #B00010000` (or `AND #&10`).
(ii)
1. Shifting `11010110` left by 3 places:
- Shift 1: `10101100`
- Shift 2: `01011000`
- Shift 3: `10110000`
Binary value = `10110000` (or `B10110000`).
2. Mathematical effect: A logical left shift by 3 places multiplies the unsigned integer value by $2^3$ (or by 8).
Reason for incorrect result: Significant bits (two 1s) are shifted out of the register on the left / overflow occurs / the product exceeds the 8-bit storage capacity.

Marking scheme

(a) 1 mark per point (max 2):
- MP1: Direct addressing uses the operand as the memory address containing the data / value to be used.
- MP2: Indirect addressing uses the operand as an address which holds the address of the data / pointer to the operand address.

(b) 1 mark for each correct value (max 3):
(i) 15 [1]
(ii) 72 [1]
(iii) 201 [1]

(c)(i) 1 mark:
- `AND #B00010000` // `AND #&10` // `AND #16` [1]

(c)(ii)
1. 1 mark:
- `10110000` // `B10110000` [1]

2. 1 mark per point (max 2):
- MP1: Multiplies the number by 8 // multiplies the number by $2^3$ [1]
- MP2: (Arithmetic) overflow occurs // most significant bits (1s) are shifted out/lost // the result cannot be represented in an 8-bit register [1]
Question 9 · Hardware Transducers & Internal Buffering
10 marks
An automated bioreactor maintains optimal growth conditions for bacterial cultures by monitoring temperature and regulating an electrical heating element.

(a) The bioreactor system incorporates sensors, actuators, and converter hardware.

(i) State what is meant by a transducer in the context of this system.
[1]

(ii) Describe the role of both an Analogue-to-Digital Converter (ADC) and a Digital-to-Analogue Converter (DAC) in the operation of this bioreactor system.
[3]

(iii) Explain whether this system is classified as a monitoring system or a control system.
[2]

(b) High-precision sensor readings are transmitted at regular intervals from the bioreactor hardware interface to the processor.

(i) Explain why an internal buffer is required during the transfer of data from the sensor interface to main memory.
[2]

(ii) Describe how double buffering is used to manage the stream of incoming sensor readings efficiently.
[2]
Show answer & marking scheme

Worked solution

(a) (i) A transducer is a device that converts physical energy / properties from one form to another (e.g. converting temperature into an electrical signal or an electrical signal into heat / mechanical movement).

(ii) Role of ADC and DAC:
- The temperature sensor generates a continuous analogue signal (electrical voltage/current).
- The ADC converts this continuous analogue signal into discrete digital data / binary values so the processor / computer can process it.
- If adjustments are required, the processor sends digital signals which the DAC converts into an analogue control signal (voltage/current) to drive the heating element / actuator.

(iii) Classification:
- It is a control system.
- Reason: The system does not merely observe / record data (monitoring); it acts upon the sensor data to alter the physical environment (by turning on/adjusting the heater) using feedback without needing manual user intervention.

(b) (i) Why a buffer is required:
- There is a speed mismatch between the data transmission rate of the sensor interface (slower) and the processing speed of the CPU / memory access speed (faster).
- The buffer temporarily holds incoming sensor data so that data is not lost and the CPU is free to perform other tasks until a full block is ready to be transferred.

(ii) How double buffering works:
- Two buffers (Buffer 1 and Buffer 2) are used alternately.
- While one buffer is being filled with incoming data from the sensor interface, the second buffer is being emptied / processed by the CPU.
- Once the active filling buffer is full and the active processing buffer is emptied, their roles are swapped (using pointers), preventing the input stream from having to halt.

Marking scheme

(a) (i) 1 mark for:
- A device that converts physical / non-electrical energy/properties to electrical signals (or vice versa) // converts energy from one form to another.

(ii) 1 mark per bullet to max 3:
- Sensor produces continuous analogue data / signals.
- ADC converts analogue signal/voltage into digital/binary data so the CPU/microprocessor can process it.
- DAC converts digital output / commands from the processor into an analogue signal / voltage.
- To operate / power / regulate the actuator / heating element.

(iii) 1 mark for identification + 1 mark for justification (max 2):
- It is a control system (1)
- Output affects the input / system takes action / uses feedback to regulate the temperature automatically (1)
[Note: Reject monitoring system]

(b) (i) 1 mark per bullet to max 2:
- Compensates for the difference in speed / operational speed mismatch between the peripheral / interface and the processor / RAM.
- Allows data to be held temporarily so processor does not have to wait for slow input device // prevents loss of data.

(ii) 1 mark per bullet to max 2:
- Buffer A is filled with incoming sensor data while Buffer B is being read / processed by the CPU (or vice versa).
- Once Buffer A is full, the roles switch / pointers swap so the stream is continuous without data transmission pausing.

Ready to test yourself?

Turn these notes into exam-style practice. Get unlimited AI questions on this topic with instant marking and explanations.

Practise This Topic

Paper 2: Fundamental Problem-solving and Programming Skills

Answer all questions. Refer to the provided pseudocode Insert for built-in functions and operator definitions.
8 Question · 75 marks
Question 1 · Pseudocode Construct Analysis
2 marks
A procedure contains the following pseudocode algorithm to calculate the sum of positive integers entered by a user until a terminating value of -1 is entered:

```
DECLARE Value : INTEGER
DECLARE Total : INTEGER
Total <- 0
REPEAT
INPUT Value
IF Value > 0 THEN
Total <- Total + Value
ENDIF
UNTIL Value = -1
```

Explain why a pre-condition loop (`WHILE ... ENDWHILE`) is more appropriate than this post-condition loop (`REPEAT ... UNTIL`) if there may be no data values to process.
Show answer & marking scheme

Worked solution

In a post-condition loop (`REPEAT ... UNTIL`), the termination condition is evaluated at the end of the iteration, meaning the loop body is guaranteed to execute at least once. If no valid data is available and the terminating value (`-1`) is entered immediately, the loop still executes its body unnecessarily.

In contrast, a pre-condition loop (`WHILE ... ENDWHILE`) tests the condition prior to entering the loop. If the initial input is `-1`, the condition evaluates to FALSE immediately and the loop body is bypassed entirely, preventing redundant execution and unnecessary checks.

Marking scheme

1 mark per bullet point to a maximum of 2 marks:
- A post-condition loop (`REPEAT ... UNTIL`) always executes at least once // tests the condition after the loop body has executed.
- A pre-condition loop (`WHILE ... ENDWHILE`) tests the condition before entry / at the start of the loop.
- With a pre-condition loop, if the terminating value / `-1` is given initially, the loop body will not execute at all // avoids unnecessary execution when there is no data to process.
Question 2 · Variable Logic & IDE Debugging
6 marks
A programmer uses an Integrated Development Environment (IDE) to write, test, and debug a modular program.

(a) Describe how each of the following IDE debugging facilities assists the programmer in locating logic errors:

(i) Breakpoint

[2]

(ii) Variable watch (watchpoint)

[2]

(b) The program contains both global and local variables.

Explain the difference between a global variable and a local variable with reference to both:
• scope (accessibility)
• lifetime (existence in memory)

[2]
Show answer & marking scheme

Worked solution

(a) (i) Breakpoint:
1 mark for identifying that it halts/pauses execution at a designated point/statement.
1 mark for explaining that it enables inspection of variable values / memory / program state at that point.

(ii) Variable watch:
1 mark for identifying that it monitors/displays the value of chosen variable(s).
1 mark for explaining that it tracks updates/changes to the variable value dynamically as the program runs / during single-stepping.

(b) Differences between global and local variables:
1 mark for scope: Global variable is accessible/visible everywhere in the program, whereas a local variable is only accessible within the module/function/procedure where it is declared.
1 mark for lifetime: Global variable persists for the entire program execution, whereas a local variable only exists in memory while the module/function/procedure is executing (destroyed on return/exit).

Marking scheme

(a)(i) 1 mark per point to max 2:
- Causes the program to pause / halt execution at a specific line / instruction [1]
- Allows the programmer to inspect variable values / environment state at that specific moment [1]

(a)(ii) 1 mark per point to max 2:
- Continuously displays / monitors the value of a chosen variable / expression [1]
- Allows the programmer to observe how the variable's value changes dynamically as execution proceeds / line-by-line [1]

(b) 1 mark per point to max 2:
- Scope: Global is accessible from any module / anywhere in the program, whereas local is only accessible within the subroutine / block in which it is declared [1]
- Lifetime: Global exists / retains its value for the duration of the entire program run, whereas local is created upon subroutine entry and destroyed / deallocated upon subroutine termination [1]
Question 3 · theory
11 marks
A software development company has been contracted to develop a new smart-ticketing and payment system for a metropolitan transport network.

(a) The development team is considering whether to use the Waterfall life cycle model or Rapid Application Development (RAD).

(i) Describe two key characteristics of the Waterfall model. [2]

(ii) Explain one advantage and one disadvantage of using Rapid Application Development (RAD) instead of the Waterfall model for this project. [4]

(b) During the testing phase of the development life cycle, several testing strategies are employed.

(i) State the difference between alpha testing and beta testing. [2]

(ii) Explain the purpose of using a stub during integration testing. [1]

(c) After the software has been deployed, ongoing maintenance is required. Identify the specific type of software maintenance represented in each of the following scenarios:

- Scenario 1: The system is modified to support updated national banking security regulations for contactless transactions.
- Scenario 2: A new reporting feature is added that allows passengers to download monthly travel expenditure summaries as PDF documents. [2]
Show answer & marking scheme

Worked solution

(a) (i)
- Linear / sequential progression through stages (analysis, design, coding, testing, maintenance).
- Each stage must be fully completed and documented before the next stage begins / difficult to return to a previous stage once completed.

(a) (ii)
Advantage:
- Early and regular delivery of working prototypes allows clients/users to provide feedback, ensuring the final product closely matches user expectations and changing needs.

Disadvantage:
- Requires continuous, active user involvement and commitment throughout the project; if users cannot commit time, the project can stall.

(b) (i)
- Alpha testing: Carried out in-house by developers or internal quality assurance testers in a simulated environment before any external release.
- Beta testing: Carried out by actual end-users / external target audience in a real operating environment prior to general release to find unexpected bugs.

(b) (ii)
- A stub is a temporary placeholder / dummy subroutine that simulates the behaviour of an uncompleted module (returning predefined values), allowing higher-level modules to be tested independently.

(c)
- Scenario 1: Adaptive maintenance
- Scenario 2: Perfective maintenance

Marking scheme

(a)(i) 1 mark per valid point (max 2):
- Linear / sequential progression / stages follow one after another.
- Each stage has defined outputs / must be completed before the next stage starts.
- Requirements are clearly defined/frozen at the start of the project.
- Difficult / expensive to go back to previous stages once completed.

(a)(ii) 1 mark for identifying advantage + 1 mark for explanation; 1 mark for identifying disadvantage + 1 mark for explanation (max 4):
- Advantage: Rapid prototyping / frequent iterations [1] ALLOWS early user feedback / easier adaptation to changing user requirements [1].
- Disadvantage: High dependency on user collaboration [1] REQUIRES significant time commitment from stakeholders / delays occur if users are unavailable [1].
// Disadvantage: Poor modular design/documentation risks [1] DUE TO emphasis on rapid delivery rather than comprehensive design documentation [1].

(b)(i) 1 mark for alpha testing, 1 mark for beta testing (max 2):
- Alpha testing: Tested in-house / by development team / simulated environment [1].
- Beta testing: Tested by real end-users / target audience / in actual live operating environment [1].

(b)(ii) 1 mark for explanation (max 1):
- Acts as a placeholder / dummy routine with predetermined outputs for a sub-module that is not yet developed, enabling higher-level modules to be tested.

(c) 1 mark each (max 2):
- Scenario 1: Adaptive (maintenance) [1]
- Scenario 2: Perfective (maintenance) [1]
Question 4 · Structured English Step Formulation
4 marks
An automated package drop-box calculates shipping fees for customer parcels.

The algorithm must perform the following operations:
1. Prompt the user to input the parcel weight in kilograms.
2. Validate the weight so that it is strictly greater than 0 and less than or equal to 20.0 kg. The prompt and input must be repeated until a valid weight is entered.
3. Prompt and input whether fragile handling is requested (entering 'Y' or 'N').
4. Calculate the shipping fee:
- If the weight is less than or equal to 5.0 kg, the fee is 6.00.
- If the weight is greater than 5.0 kg, the fee is 6.00 plus 1.50 for every kilogram over 5.0 kg.
5. If fragile handling is 'Y', add an additional surcharge of 3.50 to the fee.
6. Output the total shipping fee.

Write an algorithm to meet these requirements using Structured English.
Show answer & marking scheme

Worked solution

A valid Structured English algorithm should show clear sequential, selective, and iterative control structures:

```text
REPEAT
PROMPT "Enter parcel weight in kg: "
INPUT Weight
UNTIL Weight > 0 AND Weight <= 20.0

PROMPT "Is fragile handling required (Y/N)? "
INPUT FragileOption

IF Weight <= 5.0 THEN
Fee <- 6.00
ELSE
Fee <- 6.00 + (Weight - 5.0) * 1.50
ENDIF

IF FragileOption = 'Y' THEN
Fee <- Fee + 3.50
ENDIF

OUTPUT "Total shipping fee is: ", Fee
```

Marking scheme

1 mark for each of the following (max 4 marks):
- MP1: Loop construct (pre-condition / post-condition) repeatedly prompting and inputting weight until weight > 0 and <= 20.0.
- MP2: Prompting and inputting the fragile option ('Y'/'N').
- MP3: Selection structure (IF...THEN...ELSE) correctly calculating base fee (6.00 for <= 5.0, and 6.00 + (Weight - 5.0) * 1.50 for > 5.0).
- MP4: Checking if fragile option is 'Y' to add surcharge of 3.50 AND outputting the final fee.
Question 5 · standard
11 marks
A distribution depot records parcel dispatches in a sequential text file named `ParcelLog.txt`.

Each line of the file represents one parcel and contains a 14-character fixed-length string with the following structure:

- Characters 1 to 6: Parcel ID (e.g. `"PK9021"`)
- Characters 7 to 9: Destination airport code (e.g. `"DXB"`)
- Characters 10 to 13: Parcel weight in kilograms with one decimal place (e.g. `"07.5"`)
- Character 14: Status flag (`'P'` for In Transit, `'D'` for Delivered, `'H'` for On Hold)

Example line: `"PK9021DXB07.5P"`

(a) A module is designed to inspect a parcel record and extract its weight. The module receives the 14-character string as a parameter.

State whether this parameter should be passed by value (`BYVAL`) or by reference (`BYREF`), and justify your choice. [2]

(b) Write pseudocode for a procedure `GenerateTransitReport`.

The procedure must:
- take two parameters passed by value: a 3-character STRING `TargetDest` and a REAL `MinWeight`
- open the file `ParcelLog.txt` in read mode
- read each line from the file until the end of the file is reached
- extract the Parcel ID, Destination code, Weight, and Status flag from each line
- convert the extracted weight string to a REAL value using the built-in function `STRING_TO_NUM()`
- check if the record meets all of the following criteria:
- Destination code matches `TargetDest`
- Status flag is `'P'`
- Converted weight is greater than or equal to `MinWeight`
- for every matching record, output the Parcel ID and the weight
- count the total number of matching parcels
- close the file
- if one or more matching parcels are found, output the total count with a suitable message; otherwise, output a message indicating that no matching parcels were found. [9]
Show answer & marking scheme

Worked solution

(a)
- Mode: `BYVAL` / By value [1]
- Justification: The module only needs to read/process the value of the record without changing the original string in the calling environment / prevents accidental modification of the original data. [1]

(b)
```text
PROCEDURE GenerateTransitReport(BYVAL TargetDest : STRING, BYVAL MinWeight : REAL)
DECLARE CurrentLine : STRING
DECLARE ParcelID : STRING
DECLARE DestCode : STRING
DECLARE WeightStr : STRING
DECLARE WeightVal : REAL
DECLARE StatusFlag : STRING
DECLARE MatchCount : INTEGER

MatchCount <- 0
OPENFILE "ParcelLog.txt" FOR READ

WHILE NOT EOF("ParcelLog.txt") DO
READFILE "ParcelLog.txt", CurrentLine
ParcelID <- MID(CurrentLine, 1, 6)
DestCode <- MID(CurrentLine, 7, 3)
WeightStr <- MID(CurrentLine, 10, 4)
StatusFlag <- MID(CurrentLine, 14, 1)

WeightVal <- STRING_TO_NUM(WeightStr)

IF DestCode = TargetDest AND StatusFlag = "P" AND WeightVal >= MinWeight THEN
OUTPUT "Parcel ID: ", ParcelID, " Weight: ", WeightVal
MatchCount <- MatchCount + 1
ENDIF
ENDWHILE

CLOSEFILE "ParcelLog.txt"

IF MatchCount > 0 THEN
OUTPUT "Total matching parcels in transit: ", MatchCount
ELSE
OUTPUT "No matching parcels found."
ENDIF
ENDPROCEDURE
```

Marking scheme

(a) [Total: 2 marks]
- 1 mark: `BYVAL` / By value
- 1 mark: Valid justification (e.g. only needs to read/inspect data // original value in the calling routine must not be altered // no return/update of original variable required)

(b) [Total: 9 marks]
- MP1: Correct procedure header with parameters `TargetDest : STRING` and `MinWeight : REAL` declared `BYVAL` (and corresponding `ENDPROCEDURE`).
- MP2: Initialisation of match counter to 0 before the loop.
- MP3: Correct file opening in `READ` mode AND closing `CLOSEFILE` outside the loop.
- MP4: Pre-condition or post-condition loop checking `EOF("ParcelLog.txt")` correctly.
- MP5: Reading line from file using `READFILE`.
- MP6: Correct substring extraction for all fields using `MID` (`MID(..., 1, 6)`, `MID(..., 7, 3)`, `MID(..., 10, 4)`, `MID(..., 14, 1)`).
- MP7: Correct conversion of weight substring to `REAL` using `STRING_TO_NUM`.
- MP8: Correct logical condition combining destination check, status flag check (`='P'`), and weight threshold check (`>= MinWeight`), incrementing counter and outputting ID and weight on match.
- MP9: Correct selection after the loop to output the total count with a message OR output a "no matching parcels found" message when count is 0.
Question 6 · theory
13 marks
An art exhibition uses a linked list to store a collection of artwork titles in alphabetical order.

The linked list is implemented using a 1D array of records of type `ArtNode` with a lower bound of 1 and an upper bound of 7.

The record structure and pointers are defined as follows:

```text
TYPE ArtNode
DECLARE Title : STRING
DECLARE NextPointer : INTEGER
ENDTYPE

DECLARE GalleryList : ARRAY[1:7] OF ArtNode
DECLARE HeadPointer : INTEGER
DECLARE FreePointer : INTEGER
```

The current contents of `GalleryList`, `HeadPointer`, and `FreePointer` are shown in the following diagram:

```text
HeadPointer: 5
FreePointer: 3

Index | Title | NextPointer
------+--------------+------------
1 | "Monet" | 4
2 | "DaVinci" | 1
3 | "" | 6
4 | "Picasso" | 0
5 | "Botticelli" | 2
6 | "" | 7
7 | "" | 0
```
(Note: A `NextPointer` value of 0 indicates a null pointer.)

(a) (i) State what is represented by a null pointer in this linked list. [1]

(ii) Describe the purpose of `FreePointer`. [2]

(b) (i) List the artwork titles in the order they are visited when the linked list is traversed from the `HeadPointer`. [2]

(ii) The node containing "DaVinci" (at index 2) is deleted from the linked list and added back to the free list.

State the updated values of:
- `GalleryList[5].NextPointer`
- `GalleryList[2].NextPointer`
- `FreePointer`
- `HeadPointer` [2]

(c) Describe the algorithm to insert a new artwork title, `NewTitle`, into its correct alphabetical position in the linked list. Assume there is at least one free node available. [4]

(d) Explain one advantage and one disadvantage of implementing a linked list using a static 1D array rather than dynamic memory allocation. [2]
Show answer & marking scheme

Worked solution

### Part (a)(i)
A null pointer (value 0) indicates the end of the list / that there are no subsequent nodes.

### Part (a)(ii)
`FreePointer` stores the index of the first available/empty node in the array. It enables the program to identify where new data can be stored without searching through the entire array and maintains the free space list.

### Part (b)(i)
Traversing the list starting from `HeadPointer = 5`:
1. Index 5: `"Botticelli"` -> points to 2
2. Index 2: `"DaVinci"` -> points to 1
3. Index 1: `"Monet"` -> points to 4
4. Index 4: `"Picasso"` -> points to 0 (end of list)

Order: Botticelli, DaVinci, Monet, Picasso.

### Part (b)(ii)
Deleting "DaVinci" (Index 2):
- The node before index 2 in the list is index 5 (`"Botticelli"`), which previously pointed to 2. It must now bypass index 2 and point to index 1 (`"Monet"`): `GalleryList[5].NextPointer = 1`.
- The deleted node at index 2 is added to the front of the free list. Its next pointer must point to the previous head of the free list (`3`): `GalleryList[2].NextPointer = 3`.
- `FreePointer` now points to index 2: `FreePointer = 2`.
- `HeadPointer` remains unchanged: `HeadPointer = 5`.

### Part (c)
Step-by-step algorithm to insert `NewTitle`:
1. Check `FreePointer` to find the index of the next available node (`NewNodeIndex <- FreePointer`), then update `FreePointer` to `GalleryList[NewNodeIndex].NextPointer`.
2. Assign `GalleryList[NewNodeIndex].Title <- NewTitle`.
3. Search for the insertion location by traversing the list from `HeadPointer` using two pointers (`CurrentPointer` and `PreviousPointer`) until `GalleryList[CurrentPointer].Title > NewTitle` or `CurrentPointer = 0`.
4. If inserting at the start of the list (`CurrentPointer = HeadPointer`), set `GalleryList[NewNodeIndex].NextPointer <- HeadPointer` and update `HeadPointer <- NewNodeIndex`.
5. Otherwise, set `GalleryList[NewNodeIndex].NextPointer <- CurrentPointer` and set `GalleryList[PreviousPointer].NextPointer <- NewNodeIndex`.

### Part (d)
- Advantage: Memory allocation is fixed/static and contiguous, preventing runtime memory allocation failures and making implementation simpler in languages lacking built-in pointer types.
- Disadvantage: Array size is static/fixed, so the linked list has a fixed maximum capacity (cannot grow dynamically beyond 7 elements / risk of overflow) or wastes memory if the array is under-utilised.

Marking scheme

### (a)(i) [1 Mark]
- 1 mark: Points to no node // indicates the end of the list / end of free list.

### (a)(ii) [2 Marks]
- 1 mark: Identifies/stores the index of the first available (empty) element/node in the array.
- 1 mark: Links all unused nodes together into a free list / enables new items to be added without searching the entire array.

### (b)(i) [2 Marks]
- 2 marks: All four correct in exact order: Botticelli, DaVinci, Monet, Picasso.
(1 mark if 3 out of 4 correct in order or 1 omission/extra)

### (b)(ii) [2 Marks]
- 1 mark: `GalleryList[5].NextPointer = 1` AND `HeadPointer = 5`
- 1 mark: `GalleryList[2].NextPointer = 3` AND `FreePointer = 2`

### (c) [4 Marks]
1 mark per valid point (max 4):
- MP1: Remove a node from the free list using `FreePointer` and advance `FreePointer` to the next free node.
- MP2: Store `NewTitle` in the allocated node.
- MP3: Traverse the linked list using two pointers / track current and previous node until the correct alphabetical position or end of list is found.
- MP4: If inserting at the beginning, update `HeadPointer` to point to the new node and set the new node's pointer to the old head node.
- MP5: If inserting between nodes / at the end, set the new node's pointer to point to the current node and update the previous node's pointer to point to the new node.

### (d) [2 Marks]
- 1 mark for Advantage: Memory is allocated in a single contiguous block // Easy to implement in languages without pointer/reference types // No dynamic memory allocation overhead.
- 1 mark for Disadvantage: Fixed maximum size (risk of overflow / list full error) // Memory is wasted if many elements remain unused.
Question 7 · Algorithm Tracing & Purpose Deduction
9 marks
A programmer designs an algorithm to analyse continuous sequences of sensor readings stored in an array.

The function `ScanData` is written in pseudocode as follows:

```pseudocode
FUNCTION ScanData(Items : ARRAY[1:6] OF INTEGER, Threshold : INTEGER) RETURNS INTEGER
DECLARE Ptr, Count, Sum, Result : INTEGER
Ptr <- 1
Count <- 0
Sum <- 0
Result <- -1

REPEAT
IF Items[Ptr] >= Threshold THEN
Sum <- Sum + Items[Ptr]
Count <- Count + 1
ELSE
IF Count > 0 THEN
OUTPUT "Run length: ", Count
Count <- 0
ENDIF
ENDIF
Ptr <- Ptr + 1
UNTIL Ptr > 6

IF Count > 0 THEN
OUTPUT "Run length: ", Count
ENDIF

IF Sum > 0 THEN
Result <- Sum
ENDIF

RETURN Result
ENDFUNCTION
```

The 1D array `ReadingList` contains the following elements:

| Index | 1 | 2 | 3 | 4 | 5 | 6 |
| :--- | :---: | :---: | :---: | :---: | :---: | :---: |
| Value | 12 | 18 | 25 | 8 | 30 | 20 |

(a) Complete the trace table for the function call `ScanData(ReadingList, 15)`.

| Ptr | Threshold | Items[Ptr] | Sum | Count | OUTPUT | Result |
| :--- | :--- | :--- | :--- | :--- | :--- | :--- |
| 1 | 15 | | 0 | 0 | | -1 |
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |

[6]

(b) State the purpose of:

(i) the variable `Count`.

[1]

(ii) the function `ScanData`.

[1]

(c) State the value returned by `ScanData` if every element in the array is strictly less than `Threshold`.

[1]
Show answer & marking scheme

Worked solution

### (a) Trace Table

| Ptr | Threshold | Items[Ptr] | Sum | Count | OUTPUT | Result |
| :---: | :---: | :---: | :---: | :---: | :---: | :---: |
| 1 | 15 | | 0 | 0 | | -1 |
| | | 12 | | | | |
| 2 | | 18 | 18 | 1 | | |
| 3 | | 25 | 43 | 2 | | |
| 4 | | 8 | | 0 | Run length: 2 | |
| 5 | | 30 | 73 | 1 | | |
| 6 | | 20 | 93 | 2 | | |
| 7 | | | | | Run length: 2 | 93 |

Function returns: `93`

### (b)
(i) `Count` tracks the number of consecutive data elements that are greater than or equal to `Threshold`.
(ii) Calculates and returns the sum of all elements that meet or exceed `Threshold`, and outputs the length of each consecutive group/run of such elements.

### (c)
`-1`

Marking scheme

(a) Trace table [6 marks maximum]
- MP1: Correct initial values for `Ptr` (1), `Threshold` (15), `Sum` (0), `Count` (0), and `Result` (-1).
- MP2: Correct `Items[Ptr]` values (12, 18, 25, 8, 30, 20) accessed in sequence and `Ptr` incremented up to 7.
- MP3: Correct updates to `Sum` (18, 43, 73, 93).
- MP4: Correct updates and resets to `Count` (1, 2, then reset to 0 at Ptr=4, then 1, 2).
- MP5: Correct first `OUTPUT` ("Run length: 2") when `Ptr = 4` / `Items[4] = 8`.
- MP6: Correct post-loop `OUTPUT` ("Run length: 2"), `Result` updated to 93, and function returning 93.

(b)(i) Purpose of Count [1 mark]
- 1 mark for: Counts the number of consecutive elements that meet or exceed the threshold // measures the length of each contiguous run of qualifying values.

(b)(ii) Purpose of ScanData [1 mark]
- 1 mark for: Calculates and returns the total sum of all values in the array that are greater than or equal to `Threshold` (and displays the lengths of consecutive runs).

(c) Return value for no qualifying elements [1 mark]
- 1 mark for: `-1`.
Question 8 · structured
19 marks
A marine conservation station uses autonomous sensor pods deployed across an offshore reserve to monitor water conditions. The reserve is divided into an 8 by 12 spatial grid consisting of 8 sectors (rows 1 to 8) and 12 zones per sector (columns 1 to 12).

(a) Define a composite user-defined data type named `SensorPod` using pseudocode. The record must contain the following fields:
- `PodID` to store an alphanumeric identifier (e.g. "POD-084")
- `Depth` to store the operating depth in metres with decimal precision
- `BatteryLevel` to store the remaining battery percentage as a whole number
- `Active` to indicate whether the pod is currently broadcasting data
[4]

(b) Write a pseudocode statement to declare a 2D array named `GridPods` capable of storing a `SensorPod` record for each grid location across the 8 sectors and 12 zones.
[2]

(c) (i) The subroutines in this system can receive arrays either by value (`BYVAL`) or by reference (`BYREF`).
Explain one difference between passing an array parameter `BYVAL` compared to passing it `BYREF` in terms of memory usage and program execution.
[2]

(c) (ii) Write pseudocode for a function named `FindLowBattery`.

The function takes three parameters:
- `Grid` : the 2D array of `SensorPod` records
- `TargetSector` : an integer representing the sector (row) to search (1 to 8)
- `MinBattery` : an integer representing a threshold battery level

The function must:
1. Search through all 12 zones within the specified `TargetSector`.
2. For each pod in that sector that is active (`Active` is `TRUE`) and has a `BatteryLevel` strictly less than `MinBattery`:
- Output its `PodID` and `Depth` on a single line separated by a space.
- Increment a count of matching low-battery pods.
3. Return the total count of low-battery pods identified.
[8]

(d) The battery level of a sensor pod is recorded as an integer from 0 to 100 inclusive. When testing the `MinBattery` validation routines, different types of test data are used.

Identify three types of test data and give an example value for each type that could be used to test an input requiring a valid battery percentage (0 to 100).
[3]
Show answer & marking scheme

Worked solution

(a)
```text
TYPE SensorPod
DECLARE PodID : STRING
DECLARE Depth : REAL
DECLARE BatteryLevel : INTEGER
DECLARE Active : BOOLEAN
ENDTYPE
```

(b)
```text
DECLARE GridPods : ARRAY[1:8, 1:12] OF SensorPod
```

(c) (i)
Passing an array `BYVAL` creates a duplicate copy of the entire array in memory, which uses more memory/execution overhead, whereas passing `BYREF` passes only the memory address/pointer to the existing array, which uses less memory and avoids copying overhead.

(c) (ii)
```text
FUNCTION FindLowBattery(Grid : ARRAY[1:8, 1:12] OF SensorPod, TargetSector : INTEGER, MinBattery : INTEGER) RETURNS INTEGER
DECLARE Zone : INTEGER
DECLARE LowCount : INTEGER

LowCount <- 0

FOR Zone <- 1 TO 12
IF Grid[TargetSector, Zone].Active = TRUE AND Grid[TargetSector, Zone].BatteryLevel < MinBattery THEN
OUTPUT Grid[TargetSector, Zone].PodID & " " & NUM_TO_STR(Grid[TargetSector, Zone].Depth)
LowCount <- LowCount + 1
ENDIF
NEXT Zone

RETURN LowCount
ENDFUNCTION
```
(Note: Comma-separated output such as `OUTPUT Grid[TargetSector, Zone].PodID, Grid[TargetSector, Zone].Depth` is also fully acceptable in Cambridge pseudocode standard).

(d)
- Normal test data: e.g. 50 (any value between 1 and 99)
- Boundary / Extreme test data: e.g. 0 or 100
- Abnormal / Erroneous test data: e.g. -5, 105, or "fifty"

Marking scheme

(a) 1 mark for each of the following (max 4):
- MP1: Correct record definition header and terminator (`TYPE SensorPod` ... `ENDTYPE`)
- MP2: `DECLARE PodID : STRING`
- MP3: `DECLARE Depth : REAL`
- MP4: `DECLARE BatteryLevel : INTEGER` AND `DECLARE Active : BOOLEAN`

(b) 1 mark for each of the following (max 2):
- MP1: `DECLARE GridPods : ARRAY[1:8, 1:12]` (accept `ARRAY[1:8, 1:12]` or `ARRAY[1:8][1:12]`)
- MP2: `OF SensorPod`

(c) (i) 1 mark for each of the following (max 2):
- MP1: `BYVAL` makes a complete copy of the array / data structure in memory.
- MP2: `BYREF` passes the memory address/reference directly, saving memory / faster execution // changes to array elements inside the subroutine affect the original array in `BYREF` but not in `BYVAL`.

(c) (ii) 1 mark for each of the following (max 8):
- MP1: Correct `FUNCTION` header with parameter declarations and `RETURNS INTEGER`
- MP2: Initialising a counter variable to 0
- MP3: Count-controlled loop iterating from 1 to 12 (columns/zones)
- MP4: Correct 2D array indexing using `TargetSector` as row and loop counter as column
- MP5: Conditional check testing `Active = TRUE` AND `BatteryLevel < MinBattery`
- MP6: Correct access of record fields using dot notation (e.g. `.Active`, `.BatteryLevel`, `.PodID`, `.Depth`)
- MP7: `OUTPUT` of `PodID` and `Depth` on matching condition
- MP8: Incrementing counter and `RETURN` statement before `ENDFUNCTION`

(d) 1 mark for each complete pair of type and suitable example (max 3):
- Normal: any integer between 1 and 99 (inclusive)
- Boundary / Extreme / Limit: 0 or 100
- Abnormal / Erroneous: any integer < 0, integer > 100, non-numeric string, or empty input

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? Practise unlimited on thinka, instant answers included.

Start Practising Free