Cambridge IAS-Level · PastPaper.sampleTitle

MetadataPastPaper.sampleTitle

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

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

Paper 11: Theory Fundamentals

Answer all questions. Calculators must not be used.
23 PastPaper.question · 75.01 PastPaper.marks
PastPaper.question 1 · Logic Diagram Construction & Matching
1.5 PastPaper.marks
A logic circuit needs to be constructed for the boolean expression: \(X = \overline{A \cdot B} \oplus C\). The circuit is described as follows: Inputs A and B are the inputs to Gate 1. The output of Gate 1 and input C are the inputs to Gate 2. The output of Gate 2 is the final output X. Identify the names of Gate 1 and Gate 2.
PastPaper.showAnswers

PastPaper.workedSolution

The term \(\overline{A \cdot B}\) represents a NAND operation on inputs A and B, which corresponds to Gate 1. The \(\oplus\) symbol represents an exclusive-OR (XOR) operation between the output of Gate 1 and C, which corresponds to Gate 2.

PastPaper.markingScheme

0.5 marks for correctly identifying Gate 1 as NAND (or NOT AND). 1.0 mark for correctly identifying Gate 2 as XOR (or EOR / Exclusive OR).
PastPaper.question 2 · Logic Diagram Construction & Matching
1.5 PastPaper.marks
A logic diagram is constructed with two inputs, P and Q. Input Q is connected to a NOT gate. The output of this NOT gate and the direct input P are connected to a 2-input NOR gate to produce the final output Y. Write the boolean expression for Y, and calculate the output value of Y when P = 0 and Q = 0.
PastPaper.showAnswers

PastPaper.workedSolution

The output of the NOT gate is \(\overline{Q}\). This and P are inputs to a NOR gate, giving the boolean expression \(Y = \overline{P + \overline{Q}}\). Substituting P = 0 and Q = 0 gives \(\overline{0 + \overline{0}} = \overline{0 + 1} = \overline{1} = 0\).

PastPaper.markingScheme

0.5 marks for the correct boolean expression (accept equivalents such as \(\overline{P} \cdot Q\)). 1.0 mark for the correct output value of 0.
PastPaper.question 3 · Embedded and Storage System Analysis
3.6 PastPaper.marks
A smart refrigerator contains an embedded system. The system allows the user to configure custom temperature settings for different compartments, and these preferences must be preserved even when the refrigerator is unplugged from the mains power supply. Explain why Electrically Erasable Programmable Read-Only Memory (EEPROM) is used to store these user settings rather than RAM or traditional ROM.
PastPaper.showAnswers

PastPaper.workedSolution

To store user preferences in an embedded device like a smart refrigerator, the storage medium must satisfy two conditions: it must retain data when power is disconnected (non-volatile), and it must allow the data to be modified when the user changes their preferences (writeable). RAM is volatile, meaning it loses all stored data when the refrigerator is powered off or unplugged, making it unsuitable. Traditional ROM is non-volatile but is read-only; its contents are hardcoded during manufacture and cannot be altered by the user. EEPROM combines both necessary characteristics: it is non-volatile (retaining settings without power) and electrically erasable/re-programmable, allowing the controller to write new temperature settings whenever the user modifies them.

PastPaper.markingScheme

1 mark: Explaining that RAM is volatile and would lose the user preferences when the refrigerator is powered down or unplugged. 1 mark: Explaining that traditional ROM is read-only / immutable and therefore cannot be updated with new user preferences. 1 mark: Explaining that EEPROM is non-volatile, ensuring settings are retained without power. 1 mark: Explaining that EEPROM can be written to/reprogrammed electronically, allowing user updates to be saved.
PastPaper.question 4 · Embedded and Storage System Analysis
3.6 PastPaper.marks
An automated weather monitoring station is deployed in a remote, high-altitude environment subject to extreme cold temperatures and heavy physical vibrations. The system continuously records sensor data every minute. State whether a Solid-State Drive (SSD) or a Magnetic Hard Disk Drive (HDD) is more suitable as the secondary storage medium for this station, and justify your choice with three distinct reasons.
PastPaper.showAnswers

PastPaper.workedSolution

A Solid-State Drive (SSD) is far superior to a Magnetic Hard Disk Drive (HDD) for this specific deployment. HDDs contain spinning magnetic platters and moving read/write heads. In an environment with heavy vibrations, these heads can crash onto the platters, causing physical damage and data loss. SSDs use flash memory and have no moving parts, making them robust against shock and vibration. Additionally, remote stations rely on limited power sources (like solar panels or batteries); SSDs require less power because they do not have to drive an electric motor to spin platters. Finally, the mechanical components and lubricants in HDDs can fail or seize up in extreme cold, whereas silicon-based flash memory operates reliably in a much wider temperature range.

PastPaper.markingScheme

1 mark: Correctly identifying SSD as the suitable medium. 1 mark: Identifying that SSDs have no moving parts, making them highly resistant to physical vibration/shock. 1 mark: Identifying that SSDs consume less power, which is critical for remote/solar-powered operation. 1 mark: Identifying that SSDs are more reliable in extreme cold because they lack mechanical parts/lubricants that can fail.
PastPaper.question 5 · Embedded and Storage System Analysis
3.6 PastPaper.marks
A modern digital camera features a 'burst mode' that captures 20 high-resolution images in rapid succession (within two seconds). The camera's internal architecture includes both high-speed RAM and a removable SD card (Flash memory). Describe the different roles that RAM and the SD card play during the capture and saving of a burst of images.
PastPaper.showAnswers

PastPaper.workedSolution

When capturing a rapid burst of high-resolution images, the volume of data produced is extremely large and generated too quickly for the SD card's write speeds. RAM, being high-speed primary storage, acts as a temporary buffer. The camera's sensor dumps the raw image data directly into the RAM buffer almost instantaneously, ensuring the user can continue taking photos without lag. Once the burst is complete, the camera's controller gradually reads the image data from the volatile RAM, processes/compresses it, and writes it to the SD card. The SD card is non-volatile flash memory, which ensures the photos are permanently stored and will not be lost when the camera is powered down.

PastPaper.markingScheme

1 mark: Explaining that RAM acts as a temporary buffer to temporarily hold the captured image data. 1 mark: Explaining that RAM is used because its write speeds are much faster than those of the SD card, preventing lag during capture. 1 mark: Explaining that the SD card is non-volatile secondary storage. 1 mark: Explaining that the SD card's role is to permanently save the files from the RAM buffer so they survive power-off states.
PastPaper.question 6 · Embedded and Storage System Analysis
3.6 PastPaper.marks
Solid-State Drives (SSDs) utilize NAND flash memory. Explain how the structural organization of NAND flash memory (pages and blocks) results in a 'read-erase-modify-write' cycle when updating existing data, and state how this cycle impacts the drive's lifespan.
PastPaper.showAnswers

PastPaper.workedSolution

In NAND flash memory, the storage is organized into pages (typically 4KB) which are grouped into larger blocks (typically 256KB or 512KB). While the controller can read and write data to individual pages, it cannot overwrite an existing page directly because flash memory cells must be erased before they can be rewritten. Crucially, erasure can only be performed on entire blocks, not individual pages. To update a single page of data, the SSD must perform a 'read-erase-modify-write' cycle: it reads all pages in the block containing the target page into RAM, erases the entire physical block on the flash chip, modifies the target page in RAM, and then writes the entire block back to the flash memory. This causes 'write amplification', meaning more data is physically written than was requested. Because floating-gate transistors in NAND flash degrade physically with each write/erase cycle, this process accelerates wear and reduces the drive's write endurance (lifespan).

PastPaper.markingScheme

1 mark: Explaining that read/write operations occur at the page level, but erase operations can only occur at the block level. 1 mark: Describing the process: the block containing the data must be read to RAM, the physical block erased, and the modified data written back. 1 mark: Explaining the concept of write amplification (writing more data than requested). 1 mark: Linking this repetitive erase/write process to the physical degradation of flash memory cells, which reduces the drive's overall lifespan.
PastPaper.question 7 · Embedded and Storage System Analysis
3.6 PastPaper.marks
A designer is developing a commercial video surveillance system that records continuous 1080p high-definition video from 8 security cameras 24/7. Explain three reasons why a Magnetic Hard Disk Drive (HDD) is far more suitable than an optical storage system (such as rewritable Blu-ray discs) for this recording system.
PastPaper.showAnswers

PastPaper.workedSolution

A magnetic HDD is vastly superior to optical storage for continuous 24/7 video surveillance for three key reasons: First, data throughput. Recording 8 continuous high-definition video feeds requires high write speeds and random access performance to handle concurrent writes; optical drives have low write speeds and long seek times, which would cause buffer overflows. Second, storage capacity. HD footage from 8 cameras generates hundreds of gigabytes daily. A single HDD can easily store 8TB to 18TB of data, whereas a standard Blu-ray disc stores only 25GB to 50GB, requiring impractical constant disc-swapping. Third, durability and automation. Security systems use loop-recording where the oldest footage is continuously overwritten. HDDs handle millions of write cycles seamlessly, whereas rewritable optical discs wear out rapidly after a few thousand cycles and cannot be managed as automated, maintenance-free storage pools.

PastPaper.markingScheme

1 mark: Explaining that HDDs have much faster write speeds and higher data transfer rates to handle multiple simultaneous HD video streams. 1 mark: Explaining that HDDs provide much larger storage capacities (terabytes) needed for massive quantities of continuous footage. 1 mark: Explaining that HDDs allow seamless, automated circular overwriting of old data and have higher write endurance than rewritable optical discs, which require physical replacement or wear out quickly.
PastPaper.question 8 · short_answer
2.5 PastPaper.marks
A programmer is developing a software application in a high-level language. State two reasons why the programmer would use an interpreter rather than a compiler during the development and debugging stage of this application.
PastPaper.showAnswers

PastPaper.workedSolution

During the development phase, an interpreter is highly advantageous because: 1. It translates and executes code line-by-line. If a runtime error is encountered, execution stops immediately at that line, allowing the programmer to identify the exact location of the bug. 2. There is no need to compile the entire source code into machine code before running it. This saves time and allows the developer to test small, incremental changes instantly.

PastPaper.markingScheme

Award up to 2.5 marks: - 1 mark: For explaining that errors are reported immediately / execution stops at the error line (making debugging easier). - 1 mark: For explaining that there is no need to wait for a complete compilation process to run/test the program (faster development cycle). - 0.5 marks: For explicitly contrasting this with a compiler (e.g., noting that a compiler requires compiling the entire program before execution or does not pinpoint the runtime execution point as easily).
PastPaper.question 9 · short_answer
2.5 PastPaper.marks
Once the high-level language program has been fully developed and tested, the software company decides to compile it before commercial distribution. Explain two reasons why a compiler is preferred over an interpreter for the final distribution of a commercial software product.
PastPaper.showAnswers

PastPaper.workedSolution

For commercial distribution, a compiler is preferred because: 1. It translates the entire high-level code into an independent executable machine code file. The user does not need to have the translator software installed on their system to run the program. 2. Since the source code is not distributed, the company's intellectual property is protected against unauthorized copying, modification, or reverse engineering. 3. The program runs much faster because the translation process has already been completed; it does not need to be translated line-by-line at runtime.

PastPaper.markingScheme

Award up to 2.5 marks: - 1 mark: For identifying that the source code is protected / not distributed, preventing unauthorized modification/theft. - 1 mark: For identifying that execution is faster (no runtime translation) or that the user does not need the translator/interpreter installed to run it. - 0.5 marks: For a clear comparative point highlighting the corresponding drawback of using an interpreter (e.g., an interpreter requires the source code to be shared, or requires the user to install the interpreter).
PastPaper.question 10 · Low-level Assembly Program & Dry Run
3.5 PastPaper.marks
An assembly language program is executed with the following initial states:
- Accumulator (ACC) is initially 0.
- Index Register (IX) contains the value 5.
- Memory address 100 contains 5.
- Memory address 101 contains 12.
- Memory address 102 contains 0.
- Memory address 103 contains 0.
- Memory address 105 contains 20.

The program instructions are:
LDD 100
ADD 101
STO 102
LDX 100
INC IX
DEC ACC
STO 103
END

Determine the final values in ACC, IX, memory address 102, and memory address 103 after the program has terminated. Show your working.
PastPaper.showAnswers

PastPaper.workedSolution

Let's trace the execution of the program step-by-step:
1. LDD 100: Loads the direct value from address 100 (which is 5) into the Accumulator. (ACC = 5)
2. ADD 101: Adds the value at address 101 (which is 12) to the Accumulator. (ACC = 5 + 12 = 17)
3. STO 102: Stores the current value of the Accumulator into memory address 102. (Address 102 = 17)
4. LDX 100: Uses indexed addressing. The effective address is calculated as the operand plus the contents of the Index Register: 100 + IX = 100 + 5 = 105. The value at memory address 105 (which is 20) is loaded into the Accumulator. (ACC = 20)
5. INC IX: Increments the Index Register by 1. (IX = 6)
6. DEC ACC: Decrements the Accumulator by 1. (ACC = 19)
7. STO 103: Stores the current value of the Accumulator into memory address 103. (Address 103 = 19)
8. END: The program terminates.

Final values:
ACC = 19
IX = 6
Address 102 = 17
Address 103 = 19

PastPaper.markingScheme

- 1.0 mark: Correct final value of Memory address 102 (17).
- 1.0 mark: Correct final value of Memory address 103 (19).
- 0.5 marks: Correct final value of ACC (19).
- 0.5 marks: Correct final value of IX (6).
- 0.5 marks: Clear working showing the correct calculation of the indexed address (100 + 5 = 105) for the LDX instruction.
PastPaper.question 11 · Low-level Assembly Program & Dry Run
3.5 PastPaper.marks
An assembly language program containing a loop is executed with the following initial states:
- Memory address 120 contains 0.
- Memory address 121 contains 2.

The program instructions are:
LOOP: LDD 120
ADD #10
STO 120
LDD 121
SUB #1
STO 121
CMP #0
JPN LOOP
END

Determine the final values in the Accumulator (ACC), memory address 120, and memory address 121 after the program has terminated. Show your working.
PastPaper.showAnswers

PastPaper.workedSolution

Let's trace the loop execution step-by-step:

First Iteration:
1. LDD 120: Loads the value from address 120 (0) into the Accumulator. (ACC = 0)
2. ADD #10: Adds the immediate value 10 to ACC. (ACC = 10)
3. STO 120: Stores 10 in memory address 120. (Address 120 = 10)
4. LDD 121: Loads the value from address 121 (2) into ACC. (ACC = 2)
5. SUB #1: Subtracts immediate value 1 from ACC. (ACC = 1)
6. STO 121: Stores 1 in memory address 121. (Address 121 = 1)
7. CMP #0: Compares ACC (1) with 0. The comparison result is not equal.
8. JPN LOOP: Jumps back to LOOP because the last comparison was not equal.

Second Iteration:
1. LDD 120: Loads the value from address 120 (10) into ACC. (ACC = 10)
2. ADD #10: Adds immediate value 10 to ACC. (ACC = 20)
3. STO 120: Stores 20 in memory address 120. (Address 120 = 20)
4. LDD 121: Loads the value from address 121 (1) into ACC. (ACC = 1)
5. SUB #1: Subtracts immediate value 1 from ACC. (ACC = 0)
6. STO 121: Stores 0 in memory address 121. (Address 121 = 0)
7. CMP #0: Compares ACC (0) with 0. The comparison result is equal.
8. JPN LOOP: Does not jump because the last comparison was equal.
9. END: The program terminates.

Final values:
ACC = 0
Address 120 = 20
Address 121 = 0

PastPaper.markingScheme

- 1.0 mark: Correct final value of Memory address 120 (20) with intermediate working showing it reached 10.
- 1.0 mark: Correct final value of Memory address 121 (0) with intermediate working showing it reached 1.
- 0.5 marks: Correct final value of ACC (0) at termination.
- 1.0 mark: Demonstrates clear understanding of the CMP and JPN instruction logic (correctly jumping once and exiting on the second comparison).
PastPaper.question 12 · Security & Network Protocol Evaluation
4 PastPaper.marks
Evaluate the suitability of symmetric encryption compared to asymmetric encryption for secure transmission of high-volume transaction data from a client application to a central database server.
PastPaper.showAnswers

PastPaper.workedSolution

Symmetric encryption uses a single shared key to both encrypt and decrypt data. Its main advantage is computational efficiency, making it very fast and suitable for high-volume transactions. However, its primary drawback is the key distribution problem: the key must be shared securely beforehand. Asymmetric encryption uses a public key for encryption and a private key for decryption. While it solves the key sharing issue, it is highly resource-intensive and slow, making it impractical for continuous high-volume streams. Therefore, the standard evaluation is to use a hybrid approach (such as SSL/TLS), where asymmetric encryption is used initially to securely agree upon a symmetric key, which is then used for the actual high-volume data transmission.

PastPaper.markingScheme

Award 1 mark per valid point, up to a maximum of 4 marks. Max 2 marks for symmetric evaluation, max 2 marks for asymmetric evaluation, and 1 mark for the synthesis/hybrid conclusion. [1 mark] Symmetric encryption is fast and computationally efficient, making it ideal for high volumes of data. [1 mark] Symmetric encryption has a key distribution security risk (the key must be shared securely). [1 mark] Asymmetric encryption is slow and resource-heavy, making it poor for encrypting raw high-volume data. [1 mark] Asymmetric encryption resolves key exchange risks since the private key is never transmitted. [1 mark] Best practice/hybrid solution uses asymmetric encryption to exchange a symmetric session key.
PastPaper.question 13 · Security & Network Protocol Evaluation
4 PastPaper.marks
A school network administrator wants to protect the school's internal network from unauthorized external access while also preventing students from accessing inappropriate websites. Explain how a firewall and a proxy server can be used together to meet these requirements.
PastPaper.showAnswers

PastPaper.workedSolution

The firewall and proxy server perform complementary roles. The firewall sits at the boundary of the school's network. It inspects incoming and outgoing IP packets and compares them against security policies. It blocks unauthorized access attempts from external networks (e.g., hacker scans or malicious traffic on closed ports). The proxy server, on the other hand, acts as an intermediary between the internal client computers and the internet. It masks internal IP addresses to provide anonymity. Crucially, it inspects application-layer web requests, comparing requested URLs against a blacklist of inappropriate websites and blocking access. It also caches frequently visited safe websites to reduce bandwidth usage.

PastPaper.markingScheme

Award 1 mark for each clear point up to 4 marks. [1 mark] Firewall monitors/filters incoming and outgoing network traffic based on rules. [1 mark] Firewall prevents unauthorized external users/hackers from accessing the internal network. [1 mark] Proxy server acts as an intermediary, hiding internal IP addresses from the public internet. [1 mark] Proxy server filters outbound requests by checking URLs against blacklists of inappropriate websites.
PastPaper.question 14 · Security & Network Protocol Evaluation
4 PastPaper.marks
Explain how digital signatures are used to ensure both the authenticity and the integrity of a digital contract sent via email.
PastPaper.showAnswers

PastPaper.workedSolution

To create a digital signature, the sender first inputs the digital contract into a cryptographic hash algorithm to produce a unique message digest. The sender then encrypts this digest using their private key; this encrypted digest is the digital signature. Upon receiving the email, the recipient decrypts the digital signature using the sender's public key to retrieve the original digest. This proves authenticity (non-repudiation) because only the owner of the matching private key could have encrypted it. The recipient then runs the received contract through the same hash algorithm to produce a new digest. If this new digest matches the decrypted digest, it proves integrity (the contract has not been modified during transmission).

PastPaper.markingScheme

Award 1 mark for each point up to 4 marks. [1 mark] Sender hashes the contract to generate a unique digest. [1 mark] Sender encrypts this digest with their private key to create the signature. [1 mark] Recipient decrypts the signature using the sender's public key (proving authenticity). [1 mark] Recipient hashes the document and compares the hashes; a match proves no alteration (integrity).
PastPaper.question 15 · Security & Network Protocol Evaluation
4 PastPaper.marks
A system transmits blocks of data across a noisy network. Compare the effectiveness of using a single-byte parity check against using a checksum for detecting transmission errors.
PastPaper.showAnswers

PastPaper.workedSolution

A single-byte parity check (even or odd) adds a single parity bit to a byte. It is highly limited because if an even number of bits flip (e.g., two bits change from 0 to 1) within the same byte, the parity remains unchanged, and the error goes undetected. It is only reliable for detecting a single bit flip. In contrast, a checksum is calculated by summing the binary values of all the bytes in a transmission block and appending the result. The receiver performs the same calculation on the block. A checksum is far more robust because it is highly unlikely that multiple arbitrary bit flips or transposition errors (where data is swapped) will result in the same mathematical sum, making checksums significantly more effective for noisy networks.

PastPaper.markingScheme

Award 1 mark for each point up to 4 marks. [1 mark] Parity check only successfully detects an odd number of bit errors (or a single bit flip). [1 mark] Parity check fails to detect errors if an even number of bits flip in the same byte. [1 mark] Checksum sums all the bytes in a block and transmits the value. [1 mark] Checksum is highly likely to detect multiple bit errors and byte transpositions across the entire block, making it superior for noisy environments.
PastPaper.question 16 · short-answer
3.75 PastPaper.marks
A library database contains an unnormalised relation to track book loans: LOAN_RECORD(MemberID, MemberName, (BookID, BookTitle, DateBorrowed, DateDue)*) where the asterisk indicates a repeating group of book borrowing details. Describe how this unnormalised relation is transformed into First Normal Form (1NF) and state the resulting 1NF database schema, clearly identifying the primary key(s).
PastPaper.showAnswers

PastPaper.workedSolution

To transition from UNF to 1NF: 1. Identify and remove the repeating group (BookID, BookTitle, DateBorrowed, DateDue). 2. Create a separate relation for the repeating group's attributes. 3. Form a composite primary key in the new relation by combining the primary key of the original relation (MemberID) with one or more fields from the repeating group to uniquely identify each row (BookID and DateBorrowed). 4. The original relation retains its primary key (MemberID) and non-repeating attributes. Schemas: MEMBER(MemberID, MemberName) Primary Key: MemberID. LOAN(MemberID, BookID, DateBorrowed, BookTitle, DateDue) Primary Key: (MemberID, BookID, DateBorrowed).

PastPaper.markingScheme

1.25 marks: Explanation of removing the repeating group and creating a separate table. 1.25 marks: Defining the correct tables: MEMBER and LOAN with correct fields. 1.25 marks: Correctly identifying MemberID as the primary key for MEMBER, and (MemberID, BookID, DateBorrowed) as the composite primary key for LOAN.
PastPaper.question 17 · short-answer
3.75 PastPaper.marks
A database table DELIVERY contains information about package shipments: DELIVERY(DeliveryID, CourierID, Weight, DeliveryStatus, DeliveryDate, DeliveryFee). Write an SQL query to display the CourierID and the total delivery fee (sum of DeliveryFee) for each courier. The query must only include deliveries where the DeliveryStatus is 'Completed', and only display rows for couriers whose total completed delivery fee is greater than 500.
PastPaper.showAnswers

PastPaper.workedSolution

The query requires: 1. SELECT clause with CourierID and the aggregate function SUM(DeliveryFee). 2. FROM clause specifying the DELIVERY table. 3. WHERE clause to filter individual rows where DeliveryStatus is 'Completed' before grouping. 4. GROUP BY clause to aggregate by CourierID. 5. HAVING clause to filter the grouped results where the aggregated sum is greater than 500. Code: SELECT CourierID, SUM(DeliveryFee) FROM DELIVERY WHERE DeliveryStatus = 'Completed' GROUP BY CourierID HAVING SUM(DeliveryFee) > 500;

PastPaper.markingScheme

1.00 mark: SELECT CourierID, SUM(DeliveryFee) FROM DELIVERY. 1.00 mark: WHERE DeliveryStatus = 'Completed'. 1.00 mark: GROUP BY CourierID. 0.75 marks: HAVING SUM(DeliveryFee) > 500.
PastPaper.question 18 · short-answer
3.75 PastPaper.marks
A retail database contains two tables: CUSTOMER(CustomerID, FirstName, LastName, Email, PostCode) and ORDER(OrderID, CustomerID, OrderDate, TotalAmount). The database designer wants to ensure that: 1. No order can be placed for a customer who does not exist in the CUSTOMER table. 2. Searching for customers by their PostCode is optimised for speed. State the exact database terms used for: (a) The database rule that prevents an order being linked to a non-existent customer. (b) The field CustomerID in the ORDER table. (c) An index created on the PostCode field to speed up queries.
PastPaper.showAnswers

PastPaper.workedSolution

(a) Referential integrity is a system of rules that ensures relationships between records in related tables are valid and that users do not accidentally delete or change related data. (b) CustomerID in the ORDER table acts as a Foreign Key because it refers to the primary key CustomerID in the CUSTOMER table. (c) An index created on a non-primary key field like PostCode to speed up data retrieval is known as a Secondary Key.

PastPaper.markingScheme

1.25 marks: (a) Referential integrity (Accept: referential integrity rule). 1.25 marks: (b) Foreign key (Accept: FK). 1.25 marks: (c) Secondary key (Accept: secondary index).
PastPaper.question 19 · short-answer
3.75 PastPaper.marks
A veterinary clinic database has a table PET_TREATMENT in Second Normal Form (2NF): PET_TREATMENT(TreatmentID, PetID, PetName, TreatmentCode, TreatmentDescription, Cost) where TreatmentID is the primary key. The following dependencies exist: TreatmentID determines PetID, TreatmentCode, and Cost; PetID determines PetName; TreatmentCode determines TreatmentDescription. Explain why PET_TREATMENT is not in Third Normal Form (3NF), and state the three normalised relations in 3NF, specifying their primary keys.
PastPaper.showAnswers

PastPaper.workedSolution

Explanation: A table is in 3NF if it is in 2NF and contains no transitive dependencies (where a non-key attribute depends on another non-key attribute). In PET_TREATMENT, PetName depends on PetID, and TreatmentDescription depends on TreatmentCode. Since PetID and TreatmentCode are not candidate keys of the table, these represent transitive dependencies, violating 3NF. Conversion: We remove these dependencies by creating separate tables. 1. PET(PetID, PetName) where PetID is the Primary Key. 2. TREATMENT(TreatmentCode, TreatmentDescription) where TreatmentCode is the Primary Key. 3. PET_TREATMENT(TreatmentID, PetID, TreatmentCode, Cost) where TreatmentID is the Primary Key, and PetID and TreatmentCode are Foreign Keys.

PastPaper.markingScheme

1.25 marks: Correct explanation of transitive dependency (non-key field depending on another non-key field) with reference to PetName depending on PetID or TreatmentDescription depending on TreatmentCode. 2.50 marks: Three correctly normalised relations with correct attributes and designated primary keys (0.83 marks per correct table and primary key specification).
PastPaper.question 20 · Written
3 PastPaper.marks
Perform the subtraction of the following 8-bit signed binary integers using two's complement. Show your working.

\(01011101_2 - 00101011_2\)
PastPaper.showAnswers

PastPaper.workedSolution

Step 1: Convert the binary number to be subtracted (\(00101011_2\)) into its negative equivalent using two's complement.
- Original binary: \(00101011\)
- One's complement (invert bits): \(11010100\)
- Two's complement (add 1): \(11010101\)

Step 2: Add the two's complement value to the first binary number:
```
01011101
+ 11010101
----------
(1)00110010
```

Step 3: Discard the carry bit beyond the 8th bit to get the final 8-bit result:
\(00110010_2\) (equivalent to 50 in denary).

PastPaper.markingScheme

- 1 mark for correctly converting the subtrahend to its two's complement form: \(11010101\).
- 1 mark for attempting to add the two binary values showing correct binary carry logic.
- 1 mark for the correct final 8-bit answer: \(00110010\).
PastPaper.question 21 · Topologies and IP Addressing Specs
2.67 PastPaper.marks
An organization's server has the IPv4 address \(192.168.100.74/26\).

Identify:
1. The subnet mask of this network in dotted decimal notation.
2. The network address (ID) of the subnet in dotted decimal notation.
PastPaper.showAnswers

PastPaper.workedSolution

1. The CIDR suffix of \(/26\) indicates that the first 26 bits of the subnet mask are set to 1. In octet form:
- Octet 1: 8 bits = 255
- Octet 2: 8 bits = 255
- Octet 3: 8 bits = 255
- Octet 4: 2 bits = \(128 + 64 = 192\)
This gives a subnet mask of \(255.255.255.192\).

2. To find the network ID, perform a bitwise AND operation between the fourth octet of the IP address (74) and the fourth octet of the subnet mask (192):
- 74 in binary: \(01001010_2\)
- 192 in binary: \(11000000_2\)
- Bitwise AND: \(01000000_2\) which equals 64 in decimal.
Therefore, the network address is \(192.168.100.64\).

PastPaper.markingScheme

Total: 2.67 marks (rounded/distributed as follows):
- 1 mark for correctly identifying the subnet mask as 255.255.255.192.
- 1.67 marks for correctly calculating the network ID as 192.168.100.64 (1 mark for showing/understanding the binary bitwise AND process, 0.67 marks for the correct final IP address).
PastPaper.question 22 · Topologies and IP Addressing Specs
2.67 PastPaper.marks
A school network administrator needs to connect 6 client workstations in a computer lab.

Calculate:
1. The number of physical cable connections required to connect these 6 workstations in a fully connected mesh topology.
2. The number of physical cable connections required to connect these 6 workstations in a star topology (assuming one cable per device to a central switch).

State one operational advantage of a fully connected mesh topology over a star topology.
PastPaper.showAnswers

PastPaper.workedSolution

1. The formula for the number of links in a fully connected mesh network of \(n\) nodes is \(\frac{n(n-1)}{2}\). For \(n = 6\): \(\frac{6 \times 5}{2} = 15\) links.
2. In a star topology, each of the \(n\) workstations has exactly one direct link to the central switch, resulting in \(n\) links. For \(n = 6\), this is 6 links.
3. Advantage: A mesh network does not suffer from a single point of central device failure (unlike the switch in a star topology) and has high redundancy; if one connection fails, packets can still find an alternative route.

PastPaper.markingScheme

Total: 2.67 marks
- 1 mark for correct calculation of mesh links (15).
- 1 mark for correct calculation of star links (6).
- 0.67 marks for identifying a valid advantage of a mesh network (e.g., redundancy, no central single point of failure, fault tolerance).
PastPaper.question 23 · Topologies and IP Addressing Specs
2.67 PastPaper.marks
1. State the size of an IPv6 address in bits.
2. Compress the following IPv6 address to its shortest standard representation using the rules of zero compression:
\(2001:0db8:0000:0000:0000:ff00:0042:8329\)
PastPaper.showAnswers

PastPaper.workedSolution

1. An IPv6 address consists of 128 bits.
2. Compression steps for \(2001:0db8:0000:0000:0000:ff00:0042:8329\):
- Remove leading zeros in each group: \(2001:db8:0:0:0:ff00:42:8329\)
- Replace the longest consecutive run of zero groups with double colons (\(::\)): \(2001:db8::ff00:42:8329\)

PastPaper.markingScheme

Total: 2.67 marks
- 1 mark for stating '128 bits'.
- 1.67 marks for the fully correct compressed IPv6 address '2001:db8::ff00:42:8329'. (Accept 1 mark partial credit if leading zeros were removed but the double-colon was omitted or misplaced).

Paper 21: Algorithmic Programming & Problem Solving

Answer all questions. Use standard pseudocode notation as defined in the insert.
17 PastPaper.question · 78.97 PastPaper.marks
PastPaper.question 1 · Data Type & Expression Evaluation
3.66 PastPaper.marks
The variables \(Word\), \(Num1\), and \(Num2\) are assigned values as follows in a pseudocode program:

```
Word <- "Cambridge9618"
Num1 <- 15
Num2 <- 4
```

Evaluate the following pseudocode expression. Show your intermediate steps.

`MID(Word, (Num1 MOD Num2) + 1, Num2 - 1) & NUM_TO_STR(Num1 DIV Num2)`
PastPaper.showAnswers

PastPaper.workedSolution

Let's evaluate each sub-expression step-by-step:

1. Evaluate the arithmetic inside the `MID` function parameters:
- `Num1 MOD Num2` = `15 MOD 4` = `3`
- `(Num1 MOD Num2) + 1` = `3 + 1` = `4` (This is the start index for `MID`)
- `Num2 - 1` = `4 - 1` = `3` (This is the length for `MID`)

2. Evaluate the `MID` function:
- `MID("Cambridge9618", 4, 3)` extracts a substring starting from index 4 with a length of 3 characters.
- Index 1: 'C', Index 2: 'a', Index 3: 'm', Index 4: 'b', Index 5: 'r', Index 6: 'i'.
- The resulting substring is `"bri"`.

3. Evaluate the second part of the concatenation:
- `Num1 DIV Num2` = `15 DIV 4` = `3`
- `NUM_TO_STR(3)` converts the integer to string `"3"`.

4. Concatenate the two results:
- `"bri" & "3"` = `"bri3"`.

PastPaper.markingScheme

1 mark: Correct evaluation of `MID` start index as 4 and length as 3.
1 mark: Correct extraction of `"bri"` from the string.
1 mark: Correct evaluation of `Num1 DIV Num2` as 3 and conversion to `"3"`.
0.66 marks: Correct final concatenated string `"bri3"` (must include quotes or be clearly represented as a string).

Accept: "bri3"
Reject: bri3 (without indicator of string), "bri 3"
PastPaper.question 2 · Data Type & Expression Evaluation
3.66 PastPaper.marks
The variables \(IsActive\), \(Code\), and \(Score\) are defined and initialized in a pseudocode program as follows:

```
DECLARE IsActive : BOOLEAN
DECLARE Code : CHAR
DECLARE Score : REAL

IsActive <- TRUE
Code <- 'D'
Score <- 14.5
```

Evaluate the following logical expression. Show your working, state the final value, and state its resulting data type.

`NOT(IsActive) OR (ASC(Code) > 66 AND INT(Score * 2) = 29)`
PastPaper.showAnswers

PastPaper.workedSolution

Let's evaluate each part of the compound conditional statement:

1. Evaluate `NOT(IsActive)`:
- `NOT(TRUE)` = `FALSE`

2. Evaluate the left side of the `AND` operator: `ASC(Code) > 66`:
- `Code` is `'D'`.
- Knowing the standard ASCII values (where 'A' is 65, 'B' is 66, 'C' is 67, 'D' is 68):
- `ASC('D')` = `68`
- `68 > 66` = `TRUE`

3. Evaluate the right side of the `AND` operator: `INT(Score * 2) = 29`:
- `Score * 2` = `14.5 * 2` = `29.0`
- `INT(29.0)` = `29`
- `29 = 29` = `TRUE`

4. Combine with the `AND` operator:
- `TRUE AND TRUE` = `TRUE`

5. Combine with the `OR` operator:
- `FALSE OR TRUE` = `TRUE`

6. Determine the data type:
- The final value `TRUE` belongs to the `BOOLEAN` data type.

PastPaper.markingScheme

1 mark: Correct evaluation of `NOT(IsActive)` as `FALSE`.
1 mark: Correct evaluation of `ASC(Code) > 66` as `TRUE` (by correctly mapping 'D' to 68).
1 mark: Correct evaluation of `INT(Score * 2) = 29` as `TRUE`.
0.66 marks: Correct final evaluation of `TRUE` with the correct data type of `BOOLEAN`.

Accept: True, TRUE, Boolean, BOOLEAN
PastPaper.question 3 · Data Type & Expression Evaluation
3.66 PastPaper.marks
The variables \(StrA\), \(StrB\), and \(Value\) are declared and assigned as follows:

```
DECLARE StrA : STRING
DECLARE StrB : STRING
DECLARE Value : REAL

StrA <- "Prog"
StrB <- "9618"
Value <- 4.5
```

Evaluate the following pseudocode expression, showing all intermediate steps:

`UCASE(LEFT(StrA, 2)) & NUM_TO_STR(INT(Value * 2)) & RIGHT(StrB, 2)`
PastPaper.showAnswers

PastPaper.workedSolution

Let's evaluate each sub-expression of the concatenation step-by-step:

1. Evaluate the first substring operation: `UCASE(LEFT(StrA, 2))`
- `LEFT("Prog", 2)` extracts the first 2 characters from the left: `"Pr"`.
- `UCASE("Pr")` converts the string to uppercase: `"PR"`.

2. Evaluate the arithmetic conversion: `NUM_TO_STR(INT(Value * 2))`
- `Value * 2` = `4.5 * 2` = `9.0`
- `INT(9.0)` extracts the integer part: `9`.
- `NUM_TO_STR(9)` converts the integer to string: `"9"`.

3. Evaluate the third substring operation: `RIGHT(StrB, 2)`
- `RIGHT("9618", 2)` extracts the last 2 characters from the right: `"18"`.

4. Concatenate all three parts:
- `"PR"` & `"9"` & `"18"` = `"PR918"`.

PastPaper.markingScheme

1 mark: Correct evaluation of `UCASE(LEFT(StrA, 2))` as `"PR"`.
1 mark: Correct evaluation of `NUM_TO_STR(INT(Value * 2))` as `"9"`.
1 mark: Correct evaluation of `RIGHT(StrB, 2)` as `"18"`.
0.66 marks: Correctly concatenated final string `"PR918"`.

Accept: "PR918"
Reject: PR918 (without double quotes), "Pr918", "PR9.018"
PastPaper.question 4 · written
3.5 PastPaper.marks
A developer is designing an algorithm to process a sequence of integers. The process is represented by the following flowchart logic:

1. Start
2. Initialize `EvenCount` to 0.
3. Input the first integer, `Num`.
4. If `Num` is less than 0, output `EvenCount` and stop the process.
5. If `Num` is not less than 0, check if `Num` is divisible by 2 with no remainder:
- If yes, increment `EvenCount` by 1.
- If no, do not change `EvenCount`.
6. Input the next integer, `Num`.
7. Go back to step 4.

Write the equivalent pseudocode for this flowchart using standard CIE pseudocode notation. You must use a `WHILE` loop structure.
PastPaper.showAnswers

PastPaper.workedSolution

To convert the flowchart logic systematically into a sequential `WHILE` loop:
1. Initialize the counter: `EvenCount <- 0`.
2. Perform an initial read of the loop variable: `INPUT Num`.
3. Evaluate the entry condition for the loop: Since the flowchart terminates when `Num < 0`, the loop must continue while `Num >= 0`. Thus, `WHILE Num >= 0 DO` is used.
4. Inside the loop, check if the number is even using the modulo operator: `IF Num MOD 2 = 0 THEN EvenCount <- EvenCount + 1 ENDIF`.
5. Before the end of the loop, prompt for the next input to update the loop condition: `INPUT Num`.
6. Once the loop terminates, output the final counter value: `OUTPUT EvenCount`.

PastPaper.markingScheme

- 1.0 Mark: Correct initialization of `EvenCount` to 0 AND the initial `INPUT Num` before the loop begins.
- 1.0 Mark: Correct loop syntax and logical condition (`WHILE Num >= 0 DO` matching with `ENDWHILE`) including the update state (`INPUT Num`) at the end of the loop body.
- 1.0 Mark: Correct selection logic to check if `Num` is even (`IF Num MOD 2 = 0 THEN` or equivalent) and incrementing `EvenCount`.
- 0.5 Mark: Correctly outputting `EvenCount` after the loop terminates.
PastPaper.question 5 · written
3.5 PastPaper.marks
A student's academic status is evaluated using a nested decision flowchart structure defined below:

- The program inputs two values: an integer `Score` and an integer `Attendance`.
- If `Score` is greater than or equal to 80:
- If `Attendance` is greater than or equal to 90, the program outputs "Grade A with Distinction".
- Otherwise, it outputs "Grade A".
- If `Score` is less than 80:
- If `Score` is greater than or equal to 50, the program outputs "Pass".
- Otherwise, it outputs "Fail".

Write the equivalent sequential pseudocode for this grading algorithm using nested `IF` statements according to standard CIE pseudocode notation.
PastPaper.showAnswers

PastPaper.workedSolution

The flowchart uses nested decisions, which translate to nested selection structures in pseudocode:
- The primary condition is `Score >= 80`.
- If this is true, the program immediately checks the nested condition `Attendance >= 90` to decide between outputting "Grade A with Distinction" and "Grade A".
- If the primary condition is false, the program falls back to the outer `ELSE` block, where a secondary nested condition checks `Score >= 50` to output either "Pass" or "Fail".

PastPaper.markingScheme

- 0.5 Marks: Correct input statements for `Score` and `Attendance`.
- 1.0 Mark: Correct outer conditional structure (`IF Score >= 80 THEN ... ELSE ... ENDIF`).
- 1.0 Mark: Correct nested structure under the `THEN` block for checking `Attendance >= 90` and outputting the correct messages.
- 1.0 Mark: Correct nested structure under the outer `ELSE` block for checking `Score >= 50` and outputting "Pass" or "Fail".
PastPaper.question 6 · ADT / Linked List Structural Specification
4 PastPaper.marks
A programmer is implementing a singly linked list as an abstract data type (ADT). The linked list is implemented using a 1D array of records named StudentList with indices from 1 to 100. Each node in the list stores a student's name (as text) and a pointer to the next node.

Write pseudocode to:
1. Define the record type ListNode.
2. Declare the array StudentList.
3. Declare the head pointer HeadPointer and the free list pointer FreePointer.
PastPaper.showAnswers

PastPaper.workedSolution

To define the record structure, we use the TYPE ... ENDTYPE block. The student's name should be declared as a STRING, and the pointer as an INTEGER.

```
TYPE ListNode
DECLARE StudentName : STRING
DECLARE NextPointer : INTEGER
ENDTYPE
```

Next, we declare the 1D array of type `ListNode` with the specified bounds 1 to 100:

```
DECLARE StudentList : ARRAY[1:100] OF ListNode
```

Finally, we declare the two pointer variables as integers:

```
DECLARE HeadPointer : INTEGER
DECLARE FreePointer : INTEGER
```

PastPaper.markingScheme

1 mark: Correct structure of `TYPE ListNode` ... `ENDTYPE` with both student name (STRING) and next pointer (INTEGER) fields.
1 mark: Correct declaration of the array `StudentList` as a 1D array of size `1:100` of type `ListNode`.
1 mark: Correct declaration of `HeadPointer` as an INTEGER.
1 mark: Correct declaration of `FreePointer` as an INTEGER.
PastPaper.question 7 · ADT / Linked List Structural Specification
4 PastPaper.marks
An ADT is used to implement a linked list that stores a music playlist. The linked list is implemented using a 1D array of records named Playlist which has space for 50 elements (indices 1 to 50). Each node in the array contains:
- A unique track ID (an integer)
- The play count (an integer)
- A pointer to the next track (an integer)

Write pseudocode to:
1. Define the record type TrackNode to store the data for a single track.
2. Declare the array Playlist.
3. Declare the start pointer variable StartPointer.
PastPaper.showAnswers

PastPaper.workedSolution

First, define the user-defined record type `TrackNode` with three integer fields:

```
TYPE TrackNode
DECLARE TrackID : INTEGER
DECLARE PlayCount : INTEGER
DECLARE NextPointer : INTEGER
ENDTYPE
```

Second, declare the 1D array `Playlist` holding 50 instances of this record:

```
DECLARE Playlist : ARRAY[1:50] OF TrackNode
```

Third, declare the start pointer variable:

```
DECLARE StartPointer : INTEGER
```

PastPaper.markingScheme

1 mark: Correct `TYPE TrackNode` ... `ENDTYPE` syntax structure.
1 mark: All three fields inside the record structure correctly declared as INTEGER.
1 mark: Correct array declaration for `Playlist` (1 to 50) of type `TrackNode`.
1 mark: Correct declaration of pointer `StartPointer` as an INTEGER.
PastPaper.question 8 · standard_function_writing
6 PastPaper.marks
A 1D array, `Scores`, contains 100 integer values representing test scores.

Write pseudocode for a function `AveragePass` that takes this array as a parameter.

The function must calculate and return the average score of all students who achieved a passing score of 50 or above. If no students achieved a passing score, the function must return -1.0.

Use standard CIE pseudocode notation for your answer.
PastPaper.showAnswers

PastPaper.workedSolution

Below is the step-by-step logic used in the algorithm:
1. **Function Header**: The function `AveragePass` is defined to accept a 1D array of 100 integers, returning a `REAL` value since an average can have decimal components.
2. **Variable Initialization**: A `Sum` accumulator and a `Count` tracker are both initialized to 0. An `Index` loop variable is declared.
3. **Looping**: A `FOR` loop iterates from 1 to 100 to process each element in the `Scores` array.
4. **Conditional Check**: Within the loop, an `IF` statement checks if the current index value is 50 or above.
5. **Accumulation**: If the threshold is met, the score is added to `Sum` and `Count` is incremented.
6. **Final Evaluation**: After the loop, we check if `Count` is greater than 0. If it is, the calculated average (`Sum / Count`) is returned. Otherwise, `-1.0` is returned to signal that no passing scores were found.

PastPaper.markingScheme

Award up to 6 marks for the following points:

1. **Function Header & Footer**: Correct declaration of function name, passing parameter correctly typed as an array of size 100, and correct return type `REAL` (plus matching `ENDFUNCTION`). (1 mark)
2. **Initialization**: Initialize accumulator variables (e.g., `Sum <- 0` and `Count <- 0`) before entering the loop. (1 mark)
3. **Loop**: A loop from 1 to 100 to check every item in the array. (1 mark)
4. **Conditional Statement**: Correct condition checking if array elements are greater than or equal to 50 (e.g., `IF Scores[Index] >= 50`). (1 mark)
5. **Running Calculations**: Correctly calculating `Sum` and incrementing `Count` within the conditional block. (1 mark)
6. **Result & Return**: Division-by-zero check (e.g., checking if `Count > 0`), returning correct calculated real value, and returning -1 (or -1.0) otherwise. (1 mark)
PastPaper.question 9 · Trace Table
4 PastPaper.marks
An algorithm is written to process an input string by iterating backwards and transforming characters.

```pseudocode
FUNCTION FunString(Str : STRING) RETURNS STRING
DECLARE Res : STRING
DECLARE i : INTEGER
DECLARE Ch : CHAR
Res <-- ""
i <-- LENGTH(Str)
WHILE i > 0
Ch <-- MID(Str, i, 1)
IF Ch >= 'a' AND Ch <= 'z' THEN
Res <-- Res & UCASE(Ch)
ELSE
Res <-- Res & "*"
ENDIF
i <-- i - 2
ENDWHILE
RETURN Res
ENDFUNCTION
```

Complete the trace table for the function call `FunString("pRaCtiCe")`.

| i | Ch | Res |
|---|----|-----|
| | | "" |
| | | |
| | | |
| | | |
| | | |
| | | |
PastPaper.showAnswers

PastPaper.workedSolution

Let us trace the execution of `FunString("pRaCtiCe")` step-by-step:

1. `Str` is "pRaCtiCe", which has a length of 8.
2. Initial states: `Res` is initialized to "", and `i` is set to 8.
3. **First iteration (i = 8)**:
- `i > 0` (8 > 0) is TRUE.
- `Ch` is the character at position 8: 'e'.
- 'e' is between 'a' and 'z' (lowercase), so we concatenate `UCASE('e')` ('E') to `Res`.
- `Res` becomes "E".
- `i` is updated to 8 - 2 = 6.
4. **Second iteration (i = 6)**:
- `i > 0` (6 > 0) is TRUE.
- `Ch` is the character at position 6: 'i'.
- 'i' is lowercase, so we concatenate `UCASE('i')` ('I') to `Res`.
- `Res` becomes "EI".
- `i` is updated to 6 - 2 = 4.
5. **Third iteration (i = 4)**:
- `i > 0` (4 > 0) is TRUE.
- `Ch` is the character at position 4: 'C'.
- 'C' is NOT lowercase (uppercase), so we concatenate "*" to `Res`.
- `Res` becomes "EI*".
- `i` is updated to 4 - 2 = 2.
6. **Fourth iteration (i = 2)**:
- `i > 0` (2 > 0) is TRUE.
- `Ch` is the character at position 2: 'R'.
- 'R' is NOT lowercase, so we concatenate "*" to `Res`.
- `Res` becomes "EI**".
- `i` is updated to 2 - 2 = 0.
7. **Termination**:
- `i > 0` (0 > 0) is FALSE.
- The loop terminates and the function returns "EI**".

Completed trace table:
| i | Ch | Res |
|---|----|-----|
| 8 | | "" |
| | 'e'| "E" |
| 6 | | |
| | 'i'| "EI"|
| 4 | | |
| | 'C'| "EI*"|
| 2 | | |
| | 'R'| "EI**"|
| 0 | | |

PastPaper.markingScheme

Award marks as follows:
- 1 mark: For row showing i = 8, Ch = 'e', and Res = "E"
- 1 mark: For row showing i = 6, Ch = 'i', and Res = "EI"
- 1 mark: For row showing i = 4, Ch = 'C', Res = "EI*" and i = 2, Ch = 'R', Res = "EI**"
- 1 mark: For showing i = 0 as the final state causing loop termination.
PastPaper.question 10 · Trace Table
4 PastPaper.marks
The following pseudocode function processes a string character by character.

```pseudocode
FUNCTION Process(Word : STRING) RETURNS STRING
DECLARE Out : STRING
DECLARE k : INTEGER
DECLARE Ch : CHAR
Out <-- ""
FOR k <-- 1 TO LENGTH(Word)
Ch <-- MID(Word, k, 1)
IF k MOD 3 = 1 THEN
Out <-- Out & Ch
ELSE
IF Ch = 'X' THEN
Out <-- Out & "?"
ELSE
Out <-- Out & LCASE(Ch)
ENDIF
ENDIF
ENDFOR
RETURN Out
ENDFUNCTION
```

Complete the trace table for the function call `Process("BoXCaR")`.

| k | Ch | k MOD 3 = 1 | Out |
|---|----|-------------|-----|
| | | | "" |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
PastPaper.showAnswers

PastPaper.workedSolution

Let us trace the algorithm character by character with `Word = "BoXCaR"`:

1. Initial state: `Out` is initialized to "".
2. **k = 1**:
- `Ch` is "B".
- `1 MOD 3 = 1` is TRUE.
- `Out` becomes `"" & "B"` = "B".
3. **k = 2**:
- `Ch` is "o".
- `2 MOD 3 = 1` is FALSE.
- `Ch` is not "X", so we lowercase `Ch` (still "o") and append to `Out`.
- `Out` becomes `"B" & "o"` = "Bo".
4. **k = 3**:
- `Ch` is "X".
- `3 MOD 3 = 1` is FALSE.
- `Ch` is "X", so we append "?" to `Out`.
- `Out` becomes `"Bo" & "?"` = "Bo?".
5. **k = 4**:
- `Ch` is "C".
- `4 MOD 3 = 1` is TRUE.
- `Out` becomes `"Bo?" & "C"` = "Bo?C".
6. **k = 5**:
- `Ch` is "a".
- `5 MOD 3 = 1` is FALSE.
- `Ch` is not "X", so we lowercase `Ch` and append.
- `Out` becomes `"Bo?C" & "a"` = "Bo?Ca".
7. **k = 6**:
- `Ch` is "R".
- `6 MOD 3 = 1` is FALSE.
- `Ch` is not "X", so we lowercase `Ch` ("r") and append.
- `Out` becomes `"Bo?Ca" & "r"` = "Bo?Car".

Completed trace table:
| k | Ch | k MOD 3 = 1 | Out |
|---|----|-------------|-----|
| | | | "" |
| 1 | 'B'| TRUE | "B" |
| 2 | 'o'| FALSE | "Bo"|
| 3 | 'X'| FALSE | "Bo?"|
| 4 | 'C'| TRUE | "Bo?C"|
| 5 | 'a'| FALSE | "Bo?Ca"|
| 6 | 'R'| FALSE | "Bo?Car"|

PastPaper.markingScheme

Award marks as follows:
- 1 mark: For correct trace of steps k = 1 and k = 2.
- 1 mark: For correct trace of step k = 3 showing substitution of 'X' with '?'.
- 1 mark: For correct trace of steps k = 4 and k = 5.
- 1 mark: For correct final step k = 6 and final correct value of `Out` as "Bo?Car".
PastPaper.question 11 · practical
4 PastPaper.marks
In engineering applications, comparing floating-point numbers for equality requires a precision tolerance to avoid rounding errors. Write a pseudocode function ValidateRightTriangle which takes three real numbers a, b, and c representing the side lengths of a triangle, where c is expected to be the longest side. The function must return TRUE if and only if all the following conditions are met: 1) All three lengths are greater than zero. 2) c is strictly greater than a, and c is strictly greater than b. 3) The three lengths satisfy the Pythagorean theorem \(a^2 + b^2 = c^2\) within a tolerance of less than 0.0001 (i.e., the absolute difference between \(a^2 + b^2\) and \(c^2\) is strictly less than 0.0001). Otherwise, the function must return FALSE. Do not use any built-in absolute value functions. Use standard CAIE AS Level pseudocode.
PastPaper.showAnswers

PastPaper.workedSolution

The function first validates that all lengths are positive and that c is the strictly longest side. It then calculates the difference between \(a^2 + b^2\) and \(c^2\). Since we cannot use a built-in absolute value function, we check if the difference is negative and multiply it by -1 to get the absolute difference. Finally, we check if this difference is strictly less than 0.0001.

PastPaper.markingScheme

1 Mark: Correct function header with parameters and return type. 1 Mark: Correct validation that all parameters are greater than 0, and c is greater than both a and b. 1 Mark: Correct calculation of squared differences and manual absolute value logic. 1 Mark: Correct tolerance comparison and returning appropriate BOOLEAN values.
PastPaper.question 12 · practical
4 PastPaper.marks
A geographic monitoring system checks if a sensor's coordinates \((x, y)\) lie within a circular range of radius r from a central base station \((cx, cy)\). Due to GPS precision limitations, a tolerance margin of 0.005 is permitted. Thus, the point is considered valid if its distance from the center is less than or equal to \(r + 0.005\). To maintain high performance and avoid floating-point square root errors, the system must perform this validation using squared values: \((x - cx)^2 + (y - cy)^2 \le (r + 0.005)^2\). Write a pseudocode function ValidateSensorLocation which takes five real numbers: x, y, cx, cy, and r. The function must: 1) Ensure the radius r is greater than zero. If not, return FALSE. 2) Calculate and compare the squared distance between the sensor and the base station against the squared allowed boundary (including the tolerance margin). 3) Return TRUE if the location is valid according to this constraint, and FALSE otherwise.
PastPaper.showAnswers

PastPaper.workedSolution

The function begins by checking if the radius r is positive. If r is valid, it calculates the squared distance between the points as \((x - cx)^2 + (y - cy)^2\). It then calculates the squared boundary as \((r + 0.005)^2\). Finally, it compares these two squared values and returns TRUE if the squared distance is less than or equal to the squared boundary, and FALSE otherwise.

PastPaper.markingScheme

1 Mark: Correct function header with appropriate parameters, types, and BOOLEAN return type. 1 Mark: Correct validation of radius range (r > 0). 1 Mark: Correct calculation of squared distance between coordinates. 1 Mark: Correct calculation of the squared allowed boundary with tolerance, followed by correct conditional comparison and return statements.
PastPaper.question 13 · Software Abstraction and Structure Chart Module Mapping
5.33 PastPaper.marks
A structure chart is used to model the architecture of a program designed to manage hotel bookings. The module ProcessBooking calls two sub-modules: GetRoomDetails and ComputeFinalBill. 1. GetRoomDetails is called with RoomNumber (String) passed from ProcessBooking. It returns RoomRate (Real) and IsAvailable (Boolean) to ProcessBooking. 2. ComputeFinalBill is called with RoomRate (Real) and NumNights (Integer) passed from ProcessBooking. It returns TotalCost (Real) to ProcessBooking. State the name of each parameter passed between ProcessBooking and its sub-modules, classify each parameter as either a data couple or a control couple, and describe the arrow symbol used to represent each in a standard structure chart.
PastPaper.showAnswers

PastPaper.workedSolution

1. Data couples: RoomNumber (String, input to GetRoomDetails), RoomRate (Real, output from GetRoomDetails and input to ComputeFinalBill), NumNights (Integer, input to ComputeFinalBill), and TotalCost (Real, output from ComputeFinalBill). 2. Control couple: IsAvailable (Boolean, output from GetRoomDetails). 3. Graphical representations: Data couples are represented by arrows with an open/unfilled circle at their tail. Control couples are represented by arrows with a solid/filled circle at their tail.

PastPaper.markingScheme

1 mark: Correctly identifying RoomNumber, RoomRate, NumNights, and TotalCost as data couples. 1 mark: Correctly identifying IsAvailable as a control couple. 1.5 marks: Describing the representation of a data couple as an arrow with an open circle at its tail. 1.5 marks: Describing the representation of a control couple as an arrow with a filled/solid circle at its tail.
PastPaper.question 14 · Software Abstraction and Structure Chart Module Mapping
5.33 PastPaper.marks
The following requirements are given for a temperature monitoring system: The main module MonitorSystem runs continuously. MonitorSystem repeatedly calls the module ReadSensor to obtain CurrentTemp. If CurrentTemp is greater than 50, MonitorSystem calls the module TriggerAlarm with CurrentTemp as a parameter. Otherwise, it calls the module LogNormalTemp with CurrentTemp. Describe how the following elements of this system are represented in a structure chart: 1. The repetition of calling ReadSensor. 2. The conditional calling of TriggerAlarm or LogNormalTemp. 3. The direction and type of parameters exchanged between MonitorSystem and ReadSensor.
PastPaper.showAnswers

PastPaper.workedSolution

1. Repetition (iteration) is shown by a curved arrow (loop) drawn across the connection line linking MonitorSystem to ReadSensor. 2. Selection (conditional calling) is shown by a small diamond symbol placed on the bottom edge of the parent module MonitorSystem where the connection lines to TriggerAlarm and LogNormalTemp originate. 3. Parameter passing: CurrentTemp is a data couple passed from ReadSensor to MonitorSystem, represented by an arrow pointing upwards (from child to parent) with an open (unfilled) circle at its tail.

PastPaper.markingScheme

1.5 marks: Describing the curved loop arrow around the connection line for iteration. 1.5 marks: Describing the diamond symbol at the base of the parent module for selection. 1.5 marks: Correctly identifying the direction (upwards/to parent) and type (data couple with open circle at tail) of the CurrentTemp parameter.
PastPaper.question 15 · Software Abstraction and Structure Chart Module Mapping
5.33 PastPaper.marks
A programmer writes the following pseudocode routine for an inventory management system: PROCEDURE ProcessInventory(ItemID : STRING, CostPrice : REAL) DECLARE SellingPrice : REAL DECLARE IsProfitable : BOOLEAN SellingPrice <- CalculateRetail(CostPrice) IsProfitable <- CheckProfitability(CostPrice, SellingPrice) IF IsProfitable = TRUE THEN CALL RecordItem(ItemID, SellingPrice) ENDIF ENDPROCEDURE Analyze this pseudocode and answer the following questions regarding its structure chart representation: 1. Identify the parent module and all its direct sub-modules. 2. List all parameters passed from the parent module to the sub-module CheckProfitability, including their data types, and state what is returned to the parent module. 3. State which visual symbol would be drawn on the connection line to RecordItem to indicate that its execution is conditional.
PastPaper.showAnswers

PastPaper.workedSolution

1. The parent module is ProcessInventory. The direct sub-modules called are CalculateRetail, CheckProfitability, and RecordItem. 2. Parameters passed to CheckProfitability: CostPrice (REAL) and SellingPrice (REAL). Value returned to parent: IsProfitable (BOOLEAN). 3. The visual symbol to indicate conditional execution (selection) is a small diamond shape drawn at the junction where the connection line to RecordItem connects to the parent module ProcessInventory.

PastPaper.markingScheme

1.5 marks: Correctly identifying ProcessInventory as the parent module and listing all three sub-modules. 2 marks: Listing CostPrice (REAL) and SellingPrice (REAL) as passed parameters, and IsProfitable (BOOLEAN) as the returned control parameter. 1.5 marks: Correctly identifying the diamond symbol on the connection line representing selection/conditional execution.
PastPaper.question 16 · Structured Question
8 PastPaper.marks
A text file 'Students.txt' contains records of students in a school. Each line of the file represents one student's record and is formatted as a single string containing fields separated by a hash character ('#'): ###. An example of a line from the file is: 'ST2345#John Doe#12C#65'. Write pseudocode for a procedure ProcessClass which takes two string parameters: SourceFile (the name of the file to read) and TargetClass (the class code to search for, e.g. '12C'). The procedure must: 1. Open the source file for reading and a new file 'Selected.txt' for writing. 2. Read the source file line by line until the end of the file is reached. 3. Parse each line to extract the StudentID, Name, ClassCode, and Mark. (Note: You may assume that each field contains no '#' characters). 4. Check if the ClassCode matches TargetClass. 5. If the class code matches, and the Mark (converted to an integer) is greater than or equal to 70, write a new line to 'Selected.txt' in the format: ::PASS. 6. Close both files. Use standard CAIE pseudocode. Assume standard string manipulation functions are available: MID(ThisString, start, length) and LENGTH(ThisString) and STR_TO_NUM(ThisString).
PastPaper.showAnswers

PastPaper.workedSolution

PROCEDURE ProcessClass(SourceFile : STRING, TargetClass : STRING) DECLARE Line, ID, Name, Class, MarkStr : STRING DECLARE Mark, i, FieldCount : INTEGER DECLARE CurrentChar : CHAR OPENFILE SourceFile FOR READ OPENFILE "Selected.txt" FOR WRITE WHILE NOT EOF(SourceFile) READFILE SourceFile, Line ID ← "" Name ← "" Class ← "" MarkStr ← "" FieldCount ← 1 FOR i ← 1 TO LENGTH(Line) CurrentChar ← MID(Line, i, 1) IF CurrentChar = '#' THEN FieldCount ← FieldCount + 1 ELSE IF FieldCount = 1 THEN ID ← ID & CurrentChar ELSEIF FieldCount = 2 THEN Name ← Name & CurrentChar ELSEIF FieldCount = 3 THEN Class ← Class & CurrentChar ELSEIF FieldCount = 4 THEN MarkStr ← MarkStr & CurrentChar ENDIF ENDIF ENDFOR IF Class = TargetClass THEN Mark ← STR_TO_NUM(MarkStr) IF Mark >= 70 THEN WRITEFILE "Selected.txt", ID & ":" & Name & ":PASS" ENDIF ENDIF ENDWHILE CLOSEFILE SourceFile CLOSEFILE "Selected.txt" ENDPROCEDURE

PastPaper.markingScheme

1 mark: Correct PROCEDURE header with two string parameters. 1 mark: Correctly opening 'SourceFile' for READ and 'Selected.txt' for WRITE. 1 mark: Correctly using a WHILE NOT EOF(SourceFile) loop to read all lines. 1 mark: Parsing the line character-by-character to extract individual fields using MID and counting '#' delimiters. 1 mark: Correctly extracting the ClassCode and MarkStr fields. 1 mark: Correctly converting MarkStr to an integer and checking if Class matches TargetClass and Mark >= 70. 1 mark: Correctly writing the output line in the format ID & ':' & Name & ':PASS' to 'Selected.txt'. 1 mark: Correctly closing both files at the end of the procedure.
PastPaper.question 17 · Structured Question
7 PastPaper.marks
A sequential file 'Emails.txt' contains a list of email addresses, one per line. Some of these email addresses are invalid. Write a pseudocode function ValidateAndExport(InputFile : STRING, OutputFile : STRING) RETURNS INTEGER that reads through the sequential input file and performs validation on each email address. An email address is considered valid if: 1. It contains exactly one '@' character. 2. It contains at least one '.' character located at some position after the '@' character. 3. It does not start or end with a '.' or '@' character. The function must write all valid emails to OutputFile, one per line, and return the total count of valid emails found. The function must also properly open and close both files. Use standard CAIE pseudocode and built-in functions: LENGTH(ThisString) and MID(ThisString, start, length).
PastPaper.showAnswers

PastPaper.workedSolution

FUNCTION ValidateAndExport(InputFile : STRING, OutputFile : STRING) RETURNS INTEGER DECLARE Email : STRING DECLARE ValidCount, AtPos, DotPos, AtCount, i, LengthEmail : INTEGER DECLARE CurrentChar : CHAR DECLARE IsValid : BOOLEAN ValidCount ← 0 OPENFILE InputFile FOR READ OPENFILE OutputFile FOR WRITE WHILE NOT EOF(InputFile) READFILE InputFile, Email LengthEmail ← LENGTH(Email) IsValid ← TRUE IF LengthEmail < 3 THEN IsValid ← FALSE ELSE IF MID(Email, 1, 1) = "." OR MID(Email, 1, 1) = "@" OR MID(Email, LengthEmail, 1) = "." OR MID(Email, LengthEmail, 1) = "@" THEN IsValid ← FALSE ELSE AtCount ← 0 AtPos ← 0 FOR i ← 1 TO LengthEmail CurrentChar ← MID(Email, i, 1) IF CurrentChar = "@" THEN AtCount ← AtCount + 1 AtPos ← i ENDIF ENDFOR IF AtCount <> 1 THEN IsValid ← FALSE ELSE DotPos ← 0 FOR i ← AtPos + 1 TO LengthEmail IF MID(Email, i, 1) = "." THEN DotPos ← i ENDIF ENDFOR IF DotPos = 0 THEN IsValid ← FALSE ENDIF ENDIF ENDIF ENDIF IF IsValid = TRUE THEN WRITEFILE OutputFile, Email ValidCount ← ValidCount + 1 ENDIF ENDWHILE CLOSEFILE InputFile CLOSEFILE OutputFile RETURN ValidCount ENDFUNCTION

PastPaper.markingScheme

1 mark: Correct FUNCTION header with return type INTEGER and correct RETURN statement. 1 mark: Correctly opening InputFile for READ and OutputFile for WRITE, and closing both at the end. 1 mark: Using a loop with NOT EOF(InputFile) to process all emails in the file. 1 mark: Implementing Rule 3: Checking if the email is too short, or if the first or last character is '.' or '@'. 1 mark: Implementing Rule 1: Counting the occurrences of '@' and ensuring there is exactly one. 1 mark: Implementing Rule 2: Searching for at least one '.' character after the position of the '@'. 1 mark: Correctly writing valid emails to OutputFile and updating/returning the count of valid emails.

PastPaper.sampleCTATitle

PastPaper.sampleCTADescription

PastPaper.sampleStickyMessage

PastPaper.stickyCtaText