An original Thinka practice paper modelled on the structure and difficulty of the Jun 2025 (V2) Cambridge International A Level Computer Science (9618) paper. Not affiliated with or reproduced from Cambridge.
卷一 Theory Fundamentals
Answer all questions. Calculators must not be used.
19 題目 · 75 分
題目 1 · Short Answer
3 分
Subtract the 8-bit binary number 00101100 from 01010101 using two's complement representation. Show your working by: 1. Converting the subtrahend to its two's complement form. 2. Performing the binary addition. 3. Giving the final 8-bit binary answer.
查看答案詳解收起答案詳解
解題
Step 1: The subtrahend is 00101100. To find its two's complement, invert all bits to get 11010011 and then add 1, which results in 11010100. Step 2: Add this to the minuend: 01010101 + 11010100 = 100101001. Step 3: Discard the overflow bit outside the 8-bit range, which gives the final result 00101001.
評分準則
1 mark: Correct two's complement of the subtrahend (11010100). 1 mark: Correct working showing binary addition of the minuend and the calculated two's complement. 1 mark: Correct final 8-bit binary result (00101001).
題目 2 · Short Answer
3 分
An assembly language program contains the following instructions: LDD 105, then ADD 106, then STO 107. Before execution, the Accumulator (ACC) contains the value 12, memory address 105 contains the value 35, memory address 106 contains the value 15, and memory address 107 contains the value 0. State the contents of the Accumulator (ACC) immediately after the execution of each of the three instructions.
查看答案詳解收起答案詳解
解題
1. LDD 105 loads the value at address 105 directly into the ACC. Address 105 contains 35, so ACC becomes 35. 2. ADD 106 adds the value at address 106 to the current ACC. 35 + 15 = 50, so ACC becomes 50. 3. STO 107 stores the value of the ACC (50) into address 107. The ACC itself remains unchanged, so ACC is still 50.
評分準則
1 mark: ACC = 35 after execution of LDD 105. 1 mark: ACC = 50 after execution of ADD 106. 1 mark: ACC = 50 after execution of STO 107.
題目 3 · Short Answer
3 分
A relational database contains two tables: tblDepartment(DepartmentID, DepartmentName, Budget) and tblEmployee(EmployeeID, FirstName, LastName, DepartmentID). Identify the primary key in tblDepartment, the foreign key in tblEmployee, and state the type of relationship that exists between tblDepartment and tblEmployee.
查看答案詳解收起答案詳解
解題
In tblDepartment, DepartmentID uniquely identifies each department, making it the primary key. In tblEmployee, DepartmentID refers back to the primary key of tblDepartment to link the tables, making it the foreign key. Since one department can employ multiple employees, but each employee belongs to only one department, the relationship is One-to-Many.
評分準則
1 mark: Correctly identifying DepartmentID as the primary key in tblDepartment. 1 mark: Correctly identifying DepartmentID as the foreign key in tblEmployee. 1 mark: Correctly identifying the relationship as One-to-Many.
題目 4 · Short Answer
3 分
A block of data has been transmitted and received using even parity. The received grid is: Row 1: 1 1 0 1 | Parity: 1. Row 2: 0 1 1 0 | Parity: 0. Row 3: 1 1 1 1 | Parity: 1. Row 4: 0 1 0 1 | Parity: 0. Column Parity Row: 0 1 0 1 | Parity: 0. A single bit was corrupted during transmission. Identify the Row number, Column number, and the correct value of the corrupted bit.
查看答案詳解收起答案詳解
解題
Checking row parity: Row 1 has 4 ones (even). Row 2 has 2 ones (even). Row 3 has 5 ones (odd - ERROR!). Row 4 has 2 ones (even). Checking column parity: Col 1 has 2 ones (even). Col 2 has 5 ones (odd - ERROR!). Col 3 has 2 ones (even). Col 4 has 4 ones (even). The intersection of the row and column errors occurs at Row 3, Column 2. Since the received bit value is 1, the corrected value must be 0.
評分準則
1 mark: Identifying Row 3 as containing the error. 1 mark: Identifying Column 2 as containing the error. 1 mark: Stating that the correct bit value is 0.
題目 5 · Short Answer
3 分
A system validates exam score inputs which must be integers between 0 and 100 inclusive. For each of the three test data categories: 1. Normal, 2. Boundary (Extreme), and 3. Abnormal (Invalid), provide one appropriate test input value.
查看答案詳解收起答案詳解
解題
1. Normal data: Any integer from 1 to 99 inclusive (e.g., 55) is a valid score within the expected range. 2. Boundary data: 0 or 100 are values on the immediate limits of the acceptable range. 3. Abnormal data: Values outside the accepted boundaries (such as -5 or 105) or data of an incorrect type (such as 'abc' or 45.5) which should be rejected.
評分準則
1 mark: Providing any valid integer between 1 and 99 inclusive for normal data. 1 mark: Providing exactly 0 or 100 for boundary data. 1 mark: Providing any value less than 0, greater than 100, or a non-integer data type for abnormal data.
題目 6 · Structured Explanations
4 分
Explain the role of a router in routing a data packet across the Internet to its destination.
查看答案詳解收起答案詳解
解題
When a router receives a packet, it reads the destination IP address contained in the packet's header. It then references its internal routing table, which contains information on network topology and paths. Based on this, the router determines the most efficient path (or next hop) for the packet. Finally, it forwards the packet to the next router or destination interface.
評分準則
Award 1 mark for each point up to a maximum of 4: 1. Receives a data packet and inspects/reads the destination IP address in the packet header. 2. References/searches its internal routing table. 3. Determines the most efficient or optimum path / next hop for the packet. 4. Forwards/transmits the packet to the next router, node, or destination.
題目 7 · Structured Explanations
4 分
Describe the steps the CPU takes when an interrupt is detected at the end of a Fetch-Execute cycle.
查看答案詳解收起答案詳解
解題
At the end of each Fetch-Execute cycle, the CPU checks the interrupt lines. If an interrupt flag is set and its priority is high enough, the CPU suspends execution of the current program. It saves the contents of current registers (including the Program Counter) onto a stack. The Program Counter is then loaded with the starting address of the Interrupt Service Routine (ISR). Once the ISR completes, the saved register values are popped from the stack, and execution of the original program resumes.
評分準則
Award 1 mark for each point up to a maximum of 4: 1. Checks for interrupts/interrupt flags at the end of the current Fetch-Execute cycle. 2. Saves current register states / Program Counter (PC) onto the stack. 3. Loads the Program Counter (PC) with the start address of the Interrupt Service Routine (ISR). 4. Restores/pops the register values from the stack once the ISR completes to resume the original program.
題目 8 · Structured Explanations
4 分
A relational database contains two tables: CUSTOMER and ORDER. Describe how the Database Management System (DBMS) can enforce referential integrity and data validation to maintain data integrity.
查看答案詳解收起答案詳解
解題
Referential integrity ensures that relationships between tables remain consistent. The DBMS prevents orphaned records by ensuring that any foreign key in the child table (ORDER) has a matching primary key in the parent table (CUSTOMER). Data validation involves the DBMS checking inputs against predefined rules (e.g., ensuring order quantity is a positive integer) to prevent incorrect or non-sensical data entry.
評分準則
Award 1 mark for each point up to a maximum of 4 (Max 2 for referential integrity, Max 2 for data validation): - Referential Integrity: 1. Ensures that a foreign key value in the child table (ORDER) must match an existing primary key value in the parent table (CUSTOMER). 2. Prevents orphaned records (e.g., cannot delete a customer with active orders / cannot add an order for a non-existent customer). - Data Validation: 3. Automatic checks performed by the DBMS on input data to ensure it is sensible/conforms to rules. 4. Prevents invalid data types or invalid ranges from being saved (e.g., preventing negative quantities).
題目 9 · Structured Explanations
4 分
A company wants to design a new corporate logo. Explain two advantages of designing the logo as a vector graphic instead of a bitmap image.
查看答案詳解收起答案詳解
解題
Vector graphics store images as mathematical formulas and geometric properties (lines, curves, coordinates) rather than as individual pixels. Because of this, they can be scaled up or down infinitely without any loss of quality or pixelation. Additionally, they have a smaller file size because they only need to store the drawing instructions, whereas bitmaps must store color data for every individual pixel.
評分準則
Award 1 mark for each point up to a maximum of 4 (Max 2 per advantage fully explained): - Advantage 1 (Scalability): 1. Vector graphics are scale-invariant / can be resized infinitely. 2. They do not lose quality or become pixelated when scaled because they are recalculated mathematically (unlike bitmaps which stretch pixels). - Advantage 2 (File Size / Editing): 3. Vector graphics have a smaller file size as they store only mathematical drawing instructions / formulas instead of pixel data. 4. Individual elements/shapes can be easily modified/edited without affecting the rest of the image.
題目 10 · Structured Explanations
4 分
Describe the functions of a disk defragmenter utility and a backup utility, explaining how each contributes to the efficiency or security of a computer system.
查看答案詳解收起答案詳解
解題
A disk defragmenter utility works by reorganizing files on a hard disk drive so that all segments/blocks of a single file are stored contiguously. This reduces read/write head movement, speeding up file access and system performance. A backup utility creates copies of critical files and stores them on an external drive or cloud storage, enabling recovery in case of hardware failure or malware attack.
評分準則
Award 1 mark for each point up to a maximum of 4 (Max 2 for defragmenter, Max 2 for backup): - Disk Defragmenter: 1. Reorganizes fragmented file blocks/sectors on a hard drive to be contiguous. 2. Improves file access speeds / read-write efficiency by reducing physical drive head movement. - Backup Utility: 3. Creates copies of files and directories to separate storage media (e.g., cloud, external storage). 4. Protects data security/integrity by allowing data recovery in case of system failure, corruption, or malware.
題目 11 · Structured Explanations
4 分
Explain how a digital signature is created by a sender and verified by a recipient to ensure the authenticity and integrity of an emailed document.
查看答案詳解收起答案詳解
解題
To create a digital signature, the sender inputs the document into a hashing algorithm to produce a unique message digest (hash). The sender then encrypts this hash using their private key. The encrypted hash is the digital signature, which is sent along with the document. To verify, the recipient decrypts the signature using the sender's public key to obtain the decrypted hash. The recipient then runs the received document through the same hashing algorithm. If the decrypted hash and the newly calculated hash are identical, authenticity and integrity are confirmed.
評分準則
Award 1 mark for each point up to a maximum of 4: 1. Sender calculates a cryptographic hash/message digest of the document. 2. Sender encrypts this hash using their own private key to produce the digital signature. 3. Recipient decrypts the digital signature using the sender's public key to retrieve the original hash. 4. Recipient hashes the received document independently and compares the result with the decrypted hash; if they match, the document has not been altered.
題目 12 · Structured Explanations
4 分
Contrast open-source software and proprietary (commercial) software by describing how they differ in terms of source code accessibility and licensing terms.
查看答案詳解收起答案詳解
解題
Open-source software gives users access to the underlying source code, allowing them to view, edit, and tailor it to their needs. Its licensing terms generally permit free use, modification, and redistribution. Proprietary software keeps its source code hidden/compiled, preventing any modification. Its license (EULA) restricts copying, distribution, and modification, and usually requires a purchasing fee.
評分準則
Award 1 mark for each point up to a maximum of 4 (Max 2 for source code, Max 2 for licensing): - Source Code: 1. Open-source software provides full access to the source code for editing and customization. 2. Proprietary software keeps the source code closed/compiled so users cannot view or modify it. - Licensing Terms: 3. Open-source licenses (e.g., GPL) allow users to run, share, and redistribute the software freely. 4. Proprietary licenses restrict copying, redistribution, and modification, and typically require a paid user license.
題目 13 · Structured Explanations
4 分
Explain the difference between corrective maintenance and adaptive maintenance in software development. Provide a distinct example for each type of maintenance.
查看答案詳解收起答案詳解
解題
Corrective maintenance is reactive and aims to resolve bugs, logical errors, or coding defects discovered in a system once it is live. For example, fixing an error where a program crashes if a user enters a negative value. Adaptive maintenance is proactive and involves modifying the software so that it remains compatible with an external change, such as hardware upgrades, operating system updates, or new regulatory standards. For example, updating an application to run on the latest version of macOS.
評分準則
Award 1 mark for each point up to a maximum of 4: 1. Corrective maintenance is defined as identifying and resolving bugs, logical defects, or errors in the existing system. 2. Valid example of corrective maintenance (e.g., fixing a run-time error when a database query fails, resolving a broken link on a form submission). 3. Adaptive maintenance is defined as altering software so that it operates correctly within a changed external environment (OS, hardware, or regulations). 4. Valid example of adaptive maintenance (e.g., rewriting code to support a new API version, updating a payroll module to reflect new tax laws).
題目 14 · Structured Explanations
4 分
Describe the steps of the Fetch stage of the Fetch-Decode-Execute cycle. Your description must include the use of Register Transfer Notation (RTN) to represent the changes in the registers.
查看答案詳解收起答案詳解
解題
During the fetch stage, the CPU retrieves the next instruction from memory: 1. The memory address of the next instruction stored in the Program Counter (PC) is copied into the Memory Address Register (MAR): \(\text{MAR} \leftarrow [\text{PC}]\). 2. The instruction stored at the memory address inside the MAR is loaded via the data bus into the Memory Data Register (MDR): \(\text{MDR} \leftarrow [[\text{MAR}]]\). 3. Simultaneously, the Program Counter (PC) is incremented by 1 to point to the next instruction in sequence: \(\text{PC} \leftarrow [\text{PC}] + 1\). 4. The instruction in the MDR is then copied into the Current Instruction Register (CIR) to be ready for decoding: \(\text{CIR} \leftarrow [\text{MDR}]\).
評分準則
Award 1 mark for each correct step with its corresponding RTN up to a maximum of 4 marks: - Copying PC to MAR: \(\text{MAR} \leftarrow [\text{PC}]\) [1 mark] - Loading instruction from address in MAR to MDR: \(\text{MDR} \leftarrow [[\text{MAR}]]\) [1 mark] - Incrementing PC: \(\text{PC} \leftarrow [\text{PC}] + 1\) [1 mark] - Copying MDR to CIR: \(\text{CIR} \leftarrow [\text{MDR}]\) [1 mark]
題目 15 · Structured Explanations
4 分
A local area network (LAN) uses CSMA/CD (Carrier Sense Multiple Access with Collision Detection) to manage data transmission on a shared bus.
Explain how CSMA/CD detects and handles a collision when two devices attempt to transmit data simultaneously.
查看答案詳解收起答案詳解
解題
1. **Carrier Sensing**: Before sending data, a device listens to the shared transmission medium to determine if another device is currently transmitting (if the medium is busy). 2. **Collision Detection**: While transmitting, the device continues to monitor the medium. If two devices transmit at the same time, their signals collide, resulting in an abnormal voltage level which is detected as a collision. 3. **Jam Signal**: Once a collision is detected, the transmitting device immediately stops normal data transmission and broadcasts a 'jam signal' to notify all other devices on the network that a collision has occurred. 4. **Random Backoff**: After the jam signal, each device waiting to transmit generates a random wait time (backoff period) before attempting to sense the medium again. This random delay prevents the devices from immediately colliding again.
評分準則
Award 1 mark per explanation point up to a maximum of 4: - 1 mark: Senses/listens to the medium to check if it is idle before transmitting. - 1 mark: Monitors the medium during transmission to detect overlapping signals/collisions. - 1 mark: Transmission is aborted and a jam signal is broadcast upon collision detection. - 1 mark: Devices apply a random backoff time/delay before trying to retransmit.
題目 16 · SQL Query Selection
5 分
A school database stores information about books and student borrowings in two tables: tblBook and tblBorrowing. The table structures are: tblBook(BookID, BookTitle, Author, Genre) and tblBorrowing(BorrowID, BookID, StudentID, DateBorrowed, DateReturned). Write an SQL query to display the BookTitle and DateBorrowed for all books borrowed by the student with StudentID of 'S1024' that have not been returned yet (i.e. DateReturned contains a null value). The results must be sorted with the most recent borrowings first.
查看答案詳解收起答案詳解
解題
To retrieve data from both tables, an INNER JOIN is performed on the common key BookID. The fields selected are BookTitle (from tblBook) and DateBorrowed (from tblBorrowing). The filter criteria are applied using a WHERE clause: StudentID must equal 'S1024' and DateReturned must be checked for NULL using the 'IS NULL' operator. Finally, the ORDER BY clause sorts the records by DateBorrowed in descending order (DESC) to show the most recent borrowings first.
評分準則
1 mark: SELECT BookTitle, DateBorrowed (with or without table prefixes). 1 mark: FROM tblBook INNER JOIN tblBorrowing ON tblBook.BookID = tblBorrowing.BookID (accept implicit join via WHERE). 1 mark: WHERE StudentID = 'S1024'. 1 mark: AND DateReturned IS NULL (reject DateReturned = NULL). 1 mark: ORDER BY DateBorrowed DESC.
題目 17 · Assembly Code Tracing
5 分
An assembly language program is written using the 9618 instruction set. The current state of main memory addresses 108, 109, 110, and 111 is: 108: 12, 109: 4, 110: 0, 111: 0. The assembly program is: 1: LDD 108; 2: SUB 109; 3: CMP #8; 4: JPE EQUAL; 5: LDM #5; 6: STO 110; 7: JMP NEXT; 8: EQUAL: LDM #20; 9: STO 111; 10: NEXT: INC ACC; 11: STO 110; 12: END. Identify the values of the registers and memory locations: (i) Value of the Accumulator (ACC) after line 2 has executed. (ii) The status of the comparison flag (Equal or Not Equal) after line 3 has executed. (iii) Value of the Accumulator (ACC) immediately after line 8 has executed. (iv) The final value stored in memory address 111 when the program ends. (v) The final value stored in memory address 110 when the program ends.
查看答案詳解收起答案詳解
解題
Line 1 loads the value at address 108 (12) into ACC. Line 2 subtracts the value at address 109 (4) from ACC, resulting in ACC = 8. Line 3 compares ACC (8) with immediate value 8, setting the comparison flag to Equal. Line 4 jumps to EQUAL (line 8) because the flag is Equal. Line 8 loads immediate value 20 into ACC. Line 9 stores ACC (20) into address 111. Line 10 increments ACC to 21. Line 11 stores ACC (21) into address 110. Line 12 ends execution.
評分準則
1 mark for each correct value: (i) 8, (ii) Equal, (iii) 20, (iv) 20, (v) 21.
題目 18 · SQL DDL and Update
5 分
A database contains info about active projects. (a) Write an SQL script to create a database table named tblProject with the following attributes and constraints: ProjectID is the primary key and consists of a fixed-length string of exactly 6 characters; ProjectName is a variable-length string of up to 50 characters and cannot be null; Budget is a decimal value for currency. (b) Write an SQL script to update tblProject to increase the budget of all projects with a current budget of less than 15000 by 10%.
查看答案詳解收起答案詳解
解題
Part (a) uses the CREATE TABLE command. ProjectID uses CHAR(6) because it is a fixed length of 6 characters, and is defined as PRIMARY KEY. ProjectName uses VARCHAR(50) and has the NOT NULL constraint. Budget is specified as DECIMAL or NUMERIC. Part (b) uses UPDATE tblProject, sets the new Budget using SET Budget = Budget * 1.10, and filters the target rows with WHERE Budget < 15000.
評分準則
Part (a) [3 Marks]: 1 mark for correct CREATE TABLE syntax with tblProject and parentheses. 1 mark for ProjectID CHAR(6) PRIMARY KEY. 1 mark for ProjectName VARCHAR(50) NOT NULL. Part (b) [2 Marks]: 1 mark for UPDATE tblProject SET Budget = Budget * 1.1 (or Budget * 1.10 or Budget + Budget * 0.1). 1 mark for WHERE Budget < 15000.
題目 19 · Assembly Indexed Addressing Tracing
5 分
Consider the following assembly language program which uses the 9618 instruction set: LDM #0; STO 310; TAX; LOOP: LDX 300; ADD 310; STO 310; INC IX; TXA; CMP #3; JPN LOOP; END. The starting values in memory before execution are: 300: 15, 301: 22, 302: 8, 303: 31, 310: 0. The Index Register (IX) starts at 0. Answer the following: 1. How many times is the instruction at label LOOP executed? 2. What is the value in the Index Register (IX) at the end of the second iteration of the loop? 3. What is the value loaded into the Accumulator (ACC) immediately after the instruction TXA is executed for the first time? 4. State the final value stored in memory address 310 when the program terminates. Show your working.
查看答案詳解收起答案詳解
解題
The loop executes 3 times. Iteration 1: IX is 0. LDX 300 loads Mem[300] (15) into ACC. ADD 310 adds 0, resulting in 15. STO 310 saves 15 in address 310. INC IX sets IX to 1. TXA transfers 1 to ACC. CMP #3 compares 1 with 3 (Not Equal), so JPN jumps back. Iteration 2: IX is 1. LDX 300 loads Mem[301] (22) into ACC. ADD 310 adds 15, resulting in 37. STO 310 saves 37. INC IX sets IX to 2. TXA transfers 2 to ACC. CMP #3 compares 2 with 3 (Not Equal), so JPN jumps back. Iteration 3: IX is 2. LDX 300 loads Mem[302] (8) into ACC. ADD 310 adds 37, resulting in 45. STO 310 saves 45. INC IX sets IX to 3. TXA transfers 3 to ACC. CMP #3 compares 3 with 3 (Equal). Since it is equal, JPN LOOP does not branch, and the program ends. The final value in 310 is 45.
評分準則
1 mark: Correct number of loop executions (3 times). 1 mark: IX value at end of second iteration (2). 1 mark: ACC value after first TXA (1). 2 marks: Final value in 310 (45) with shown correct addition steps (15 + 22 + 8 = 45). Allow 1 mark if the correct value of 45 is given but working is missing or incorrect.
卷二 Fundamental Problem-solving and Programming Skills
Answer all questions. Use pseudocode syntax as detailed in the insert.
13 題目 · 59 分
題目 1 · Short Answer
2 分
Explain how stepwise refinement is used to design an algorithm for a complex problem.
查看答案詳解收起答案詳解
解題
Stepwise refinement is a top-down design method. The programmer begins with a high-level description of a problem and progressively breaks it down into smaller sub-tasks. This process continues iteratively until each sub-task is simple enough to be translated directly into pseudocode or program code.
評分準則
1 mark per bullet point: - Decomposition of the main problem into smaller / more manageable sub-tasks. - Process repeated / refined until the sub-tasks can be written as code / individual modules.
題目 2 · Short Answer
2 分
State two differences between a record data type and a 1D array.
查看答案詳解收起答案詳解
解題
A record is a user-defined composite data type that allows grouping of related data items of different types (such as an INTEGER, a STRING, and a REAL together) and refers to them by field names. A 1D array is a built-in data structure that stores a collection of elements of the same data type, accessed via a numeric index.
評分準則
1 mark per valid difference (max 2): - Record can hold different data types / heterogeneous data, array must hold same data type / homogeneous data. - Record elements are accessed by field names, array elements are accessed by indices. - Array is usually of fixed size, record is a composite user-defined structure.
題目 3 · Short Answer
2 分
Compare passing a parameter 'by value' and 'by reference' in terms of their effect on the original argument in the calling procedure.
查看答案詳解收起答案詳解
解題
When a parameter is passed by value (BYVAL), a local copy of the value is created for the procedure. Hence, any modification of this parameter is restricted to the local scope and the calling environment's variable remains unchanged. When passed by reference (BYREF), the procedure receives a pointer to the original memory location, so any modifications directly affect the variable in the calling environment.
評分準則
1 mark for explaining By Value: By value creates a copy / does not affect the original variable in the calling routine. 1 mark for explaining By Reference: By reference passes the address / memory pointer / directly alters the original variable in the calling routine.
題目 4 · Short Answer
2 分
Describe the purpose of using a 'stub' during the testing phase of software development.
查看答案詳解收起答案詳解
解題
In software development, particularly top-down integration testing, some lower-level modules might not yet be developed or coded. To test the higher-level modules that call these unfinished modules, developers use 'stubs'. A stub is a simple piece of dummy code that simulates the interface of the actual module, usually just displaying a message or returning a fixed hardcoded value, allowing the calling module to be tested without errors.
評分準則
1 mark per bullet point (max 2): - Acts as a placeholder / dummy module for code that is not yet written / completed. - Allows testing of higher-level modules / program flow to continue by returning predefined mock values.
題目 5 · Short Answer
2 分
The pseudocode function MID(String, Start, Length) returns a substring starting at index Start (1-based) with length Length. The function LENGTH(String) returns the number of characters. Given the assignment Word <- "COMPUTER", state the value and the data type of the result returned by the following expression: MID(Word, 4, LENGTH(Word) - 5)
查看答案詳解收起答案詳解
解題
1. LENGTH(Word) returns 8 since "COMPUTER" has 8 characters. 2. The expression simplifies to MID(Word, 4, 8 - 5) which is MID("COMPUTER", 4, 3). 3. MID("COMPUTER", 4, 3) extracts 3 characters starting from the 4th position (index 4 is 'P'). 4. The extracted characters are 'P', 'U', and 'T', which gives "PUT". 5. The data type of the returned value is STRING.
評分準則
1 mark for the correct value: "PUT" (accept PUT, reject other lengths or incorrect substrings). 1 mark for the correct data type: STRING (or String).
題目 6 · Short Answer
2 分
State the purpose of a structure chart and identify one type of arrow used on a structure chart to show data movement.
查看答案詳解收起答案詳解
解題
A structure chart is a design tool used in top-down design to represent the modular structure of a program, displaying how modules are organized hierarchically and how they interact. The flow of data between modules is represented using arrows: a 'data couple' (an arrow with an open circle) represents data being passed, while a 'control flag' (an arrow with a filled circle) represents status signals or control variables (like a boolean flag) being passed.
評分準則
1 mark for the purpose: To show the hierarchical structure / decomposition / modular breakdown of a program. 1 mark for identifying the arrow: Data couple (accept 'arrow with an open circle') OR control flag / parameter / status flag (accept 'arrow with a filled circle').
題目 7 · Trace Table
5 分
A software developer writes a pseudocode function to process a string by removing vowels and counting how many vowels were removed. The function is defined as follows:
OutputStr <- "" Count <- 0 FOR Index <- 1 TO LENGTH(InputStr) NextChar <- MID(InputStr, Index, 1) IF NextChar = 'A' OR NextChar = 'E' OR NextChar = 'I' OR NextChar = 'O' OR NextChar = 'U' THEN Count <- Count + 1 ELSE OutputStr <- OutputStr & NextChar ENDIF NEXT Index OutputStr <- OutputStr & NUM_TO_STR(Count) RETURN OutputStr ENDFUNCTION ```
Complete the trace table below for the function call `Process("CAMBRIDGE")`.
| Index | NextChar | Count | OutputStr | Return Value | |---|---|---|---|---| | | | | | |
查看答案詳解收起答案詳解
解題
Let us trace the algorithm step-by-step with the input "CAMBRIDGE": 1. `OutputStr` is initialized to `""`, and `Count` is initialized to `0`. 2. The loop runs for `Index` from 1 to 9 (length of "CAMBRIDGE"): - `Index = 1`: `NextChar` is 'C'. It is not a vowel. `OutputStr` becomes `"C"`. - `Index = 2`: `NextChar` is 'A'. It is a vowel. `Count` becomes `1`. - `Index = 3`: `NextChar` is 'M'. Not a vowel. `OutputStr` becomes `"CM"`. - `Index = 4`: `NextChar` is 'B'. Not a vowel. `OutputStr` becomes `"CMB"`. - `Index = 5`: `NextChar` is 'R'. Not a vowel. `OutputStr` becomes `"CMBR"`. - `Index = 6`: `NextChar` is 'I'. Vowel. `Count` becomes `2`. - `Index = 7`: `NextChar` is 'D'. Not a vowel. `OutputStr` becomes `"CMBRD"`. - `Index = 8`: `NextChar` is 'G'. Not a vowel. `OutputStr` becomes `"CMBRDG"`. - `Index = 9`: `NextChar` is 'E'. Vowel. `Count` becomes `3`. 3. The loop terminates. 4. `OutputStr` is concatenated with the string representation of `Count` (3), resulting in `"CMBRDG3"`. 5. The value `"CMBRDG3"` is returned.
評分準則
1 mark: Correctly initializing OutputStr to "" and Count to 0. 1 mark: Correctly writing all values of Index (1 to 9) and NextChar. 1 mark: Correctly updating the Count column only on vowels (to 1, 2, 3). 1 mark: Correctly building up the OutputStr column step-by-step (vowels omitted). 1 mark: Correct final return value "CMBRDG3".
題目 8 · Trace Table
5 分
An algorithm is designed to process an array of integers and compute a total based on the differences between adjacent elements. The pseudocode procedure is shown below:
``` PROCEDURE Analyse(Arr : ARRAY[1..5] OF INTEGER) DECLARE Index : INTEGER DECLARE Temp : INTEGER DECLARE Total : INTEGER Total <- 0 FOR Index <- 1 TO 4 Temp <- Arr[Index + 1] - Arr[Index] IF Temp > 0 THEN Total <- Total + Temp ELSE Total <- Total - Temp ENDIF NEXT Index OUTPUT Total ENDPROCEDURE ```
Complete the trace table for the procedure call `Analyse(Arr)` where `Arr` contains the values: `[12, 15, 10, 8, 14]` (such that `Arr[1] = 12`, `Arr[2] = 15`, etc.).
| Index | Temp | Total | Output | |---|---|---|---| | | | | | | |
查看答案詳解收起答案詳解
解題
Let us trace the algorithm execution: 1. `Total` is initialized to 0. 2. The loop runs for `Index` from 1 to 4: - `Index = 1`: `Temp <- Arr[2] - Arr[1]` = `15 - 12 = 3`. Since `3 > 0` is True, `Total <- Total + Temp` = `0 + 3 = 3`. - `Index = 2`: `Temp <- Arr[3] - Arr[2]` = `10 - 15 = -5`. Since `-5 > 0` is False, `Total <- Total - Temp` = `3 - (-5) = 8`. - `Index = 3`: `Temp <- Arr[4] - Arr[3]` = `8 - 10 = -2`. Since `-2 > 0` is False, `Total <- Total - Temp` = `8 - (-2) = 10`. - `Index = 4`: `Temp <- Arr[5] - Arr[4]` = `14 - 8 = 6`. Since `6 > 0` is True, `Total <- Total + Temp` = `10 + 6 = 16`. 3. The loop terminates. 4. `Total` is outputted, which is 16.
評分準則
1 mark: Correct Index values (1, 2, 3, 4) and corresponding Temp values (3, -5, -2, 6). 1 mark: Correctly updating Total to 3 at Index = 1. 1 mark: Correctly handling negative difference subtraction to yield Total = 8 at Index = 2. 1 mark: Correctly handling negative difference subtraction to yield Total = 10 at Index = 3. 1 mark: Correctly updating Total to 16 at Index = 4 and giving final Output of 16.
題目 9 · Trace Table
5 分
The following pseudocode function converts an integer to its base-4 equivalent represented as a string:
``` FUNCTION Mystery(Num : INTEGER) RETURNS STRING DECLARE Remainder : INTEGER DECLARE Result : STRING Result <- "" WHILE Num > 0 DO Remainder <- Num MOD 4 Result <- NUM_TO_STR(Remainder) & Result Num <- Num DIV 4 ENDWHILE RETURN Result ENDFUNCTION ```
Complete the trace table for the function call `Mystery(59)`.
| Num | Remainder | Result | Return Value | |---|---|---|---| | | | | | | |
查看答案詳解收起答案詳解
解題
Let us trace the logic step-by-step: 1. `Result` is initialized to `""`. `Num` is 59. 2. First iteration of `WHILE Num > 0` (59 > 0 is True): - `Remainder <- 59 MOD 4` = 3 - `Result <- "3" & ""` = `"3"` - `Num <- 59 DIV 4` = 14 3. Second iteration of `WHILE Num > 0` (14 > 0 is True): - `Remainder <- 14 MOD 4` = 2 - `Result <- "2" & "3"` = `"23"` - `Num <- 14 DIV 4` = 3 4. Third iteration of `WHILE Num > 0` (3 > 0 is True): - `Remainder <- 3 MOD 4` = 3 - `Result <- "3" & "23"` = `"323"` - `Num <- 3 DIV 4` = 0 5. The while loop condition `Num > 0` (0 > 0) is False. The loop terminates. 6. The function returns the `Result` string: `"323"`.
評分準則
1 mark: Correctly tracking values of Num through integer division (59 -> 14 -> 3 -> 0). 1 mark: Correctly calculating and recording all Remainder values (3, 2, 3). 2 marks: Correctly updating Result by prepending the remainder character (award 1 mark for correct characters, 1 mark for correct prepending order: "3" -> "23" -> "323"). 1 mark: Correct return value of "323".
題目 10 · Pseudocode Algorithm Design
8 分
Write a pseudocode algorithm for a procedure LongestRun that takes a 1-dimensional array of integers as a parameter and outputs the starting index and the length of the longest consecutive sequence of identical numbers. The procedure should take two parameters: the array DataArray (indexed from 1 to 100) and the integer NumElements which represents the actual number of elements used. If there is a tie, the starting index of the first occurrence should be output.
查看答案詳解收起答案詳解
解題
PROCEDURE LongestRun(DataArray : ARRAY[1:100] OF INTEGER, NumElements : INTEGER) DECLARE MaxStart, MaxLength, CurrentStart, CurrentLength, i : INTEGER MaxStart <- 1 MaxLength <- 1 CurrentStart <- 1 CurrentLength <- 1 FOR i <- 2 TO NumElements IF DataArray[i] = DataArray[i - 1] THEN CurrentLength <- CurrentLength + 1 ELSE IF CurrentLength > MaxLength THEN MaxLength <- CurrentLength MaxStart <- CurrentStart ENDIF CurrentStart <- i CurrentLength <- 1 ENDIF ENDFOR IF CurrentLength > MaxLength THEN MaxLength <- CurrentLength MaxStart <- CurrentStart ENDIF OUTPUT "Starting index: ", MaxStart OUTPUT "Length: ", MaxLength ENDPROCEDURE
評分準則
1 mark: Correct procedure header with parameter names and types. 1 mark: Initializing MaxStart, MaxLength, CurrentStart, CurrentLength correctly to 1. 1 mark: Correct loop from index 2 up to NumElements. 1 mark: Checking if the current element is equal to the previous element. 1 mark: Incrementing CurrentLength in the true branch. 1 mark: Updating MaxLength and MaxStart in the false branch if CurrentLength > MaxLength. 1 mark: Resetting CurrentStart to i and CurrentLength to 1 in the false branch. 1 mark: Final comparison check after loop ends and outputting both starting index and maximum length.
題目 11 · Pseudocode Algorithm Design
8 分
A text file Transactions.txt contains transaction records where each line represents one record stored in the format: ,,. Write pseudocode for a function ProcessTransactions that reads all records from Transactions.txt and writes only those records with a Status of APPROVED to a new text file ApprovedTxns.txt. The function must return the total number of records that were NOT approved. Assume that the text files can be successfully opened, and each line can be parsed using a built-in function SPLIT(String, Character) which returns an array of strings (e.g., SPLIT('TXN01,10.0,APPROVED', ',') returns an array containing 'TXN01' at index 1, '10.0' at index 2, and 'APPROVED' at index 3).
查看答案詳解收起答案詳解
解題
FUNCTION ProcessTransactions() RETURNS INTEGER DECLARE Line, Status : STRING DECLARE NonApprovedCount : INTEGER DECLARE Parts : ARRAY[1:3] OF STRING NonApprovedCount <- 0 OPENFILE "Transactions.txt" FOR READ OPENFILE "ApprovedTxns.txt" FOR WRITE WHILE NOT EOF("Transactions.txt") READFILE "Transactions.txt", Line Parts <- SPLIT(Line, ',') Status <- Parts[3] IF Status = "APPROVED" THEN WRITEFILE "ApprovedTxns.txt", Line ELSE NonApprovedCount <- NonApprovedCount + 1 ENDIF ENDWHILE CLOSEFILE "Transactions.txt" CLOSEFILE "ApprovedTxns.txt" RETURN NonApprovedCount ENDFUNCTION
評分準則
1 mark: Correct function header and RETURN statement with INTEGER return type. 1 mark: Opening Transactions.txt for READ and ApprovedTxns.txt for WRITE. 1 mark: Correct loop using WHILE NOT EOF("Transactions.txt") or equivalent. 1 mark: Reading a line from Transactions.txt inside the loop. 1 mark: Splitting the read line and extracting the Status part correctly (index 3). 1 mark: Conditional check if status is "APPROVED". 1 mark: Writing the line to ApprovedTxns.txt if approved, otherwise incrementing NonApprovedCount. 1 mark: Closing both files correctly.
題目 12 · Pseudocode Algorithm Design
8 分
A 2D array Grid of size 10 rows by 10 columns (indexed 1 to 10) contains integer values representing heights of a terrain. Write a pseudocode function CountLocalPeaks that takes this 2D array Grid as a parameter and returns the number of local peaks as an integer. A local peak is defined as an element whose value is strictly greater than all of its horizontally and vertically adjacent neighbors (up, down, left, right). Boundary elements (elements on the outer edges of the grid) must not be considered as potential peaks.
查看答案詳解收起答案詳解
解題
FUNCTION CountLocalPeaks(Grid : ARRAY[1:10, 1:10] OF INTEGER) RETURNS INTEGER DECLARE r, c, PeakCount : INTEGER PeakCount <- 0 FOR r <- 2 TO 9 FOR c <- 2 TO 9 IF Grid[r, c] > Grid[r - 1, c] AND Grid[r, c] > Grid[r + 1, c] AND Grid[r, c] > Grid[r, c - 1] AND Grid[r, c] > Grid[r, c + 1] THEN PeakCount <- PeakCount + 1 ENDIF ENDFOR ENDFOR RETURN PeakCount ENDFUNCTION
評分準則
1 mark: Correct function header with 2D array parameter and returns type INTEGER. 1 mark: Initializing PeakCount to 0. 1 mark: Outer loop iterating from index 2 to 9. 1 mark: Inner loop iterating from index 2 to 9 (ensuring boundary elements are skipped). 1 mark: Correct comparison of current element with upper neighbor (Grid[r - 1, c]) and lower neighbor (Grid[r + 1, c]). 1 mark: Correct comparison of current element with left neighbor (Grid[r, c - 1]) and right neighbor (Grid[r, c + 1]). 1 mark: Combining all four comparisons with AND. 1 mark: Incrementing PeakCount and returning the final peak count.
題目 13 · Pseudocode Algorithm Design
8 分
A queue is implemented as a circular queue in a 1-dimensional array QueueArray of size 50 (indexed 1 to 50). The global integer variable HeadPointer points to the first occupied element. The global integer variable TailPointer points to the next available free index. When the queue is empty, HeadPointer and TailPointer are equal. When the queue is full, the next position of TailPointer (calculated circularly) is equal to HeadPointer. Write a pseudocode function Enqueue that takes an integer parameter NewItem, inserts it into the queue if there is space, and returns TRUE. If the queue is full, it must output an error message and return FALSE.
查看答案詳解收起答案詳解
解題
FUNCTION Enqueue(NewItem : INTEGER) RETURNS BOOLEAN DECLARE NextTail : INTEGER NextTail <- (TailPointer MOD 50) + 1 IF NextTail = HeadPointer THEN OUTPUT "Error: Queue is full" RETURN FALSE ELSE QueueArray[TailPointer] <- NewItem TailPointer <- NextTail RETURN TRUE ENDIF ENDFUNCTION
評分準則
1 mark: Correct function header with parameter NewItem and returns BOOLEAN. 1 mark: Calculating the circular next tail position correctly using MOD 50 + 1 (or equivalent condition). 1 mark: Checking if the next tail position is equal to HeadPointer to detect the queue-full state. 1 mark: Outputting an appropriate error message when full. 1 mark: Returning FALSE when the queue is full. 1 mark: Correctly assigning NewItem to QueueArray at index TailPointer when not full. 1 mark: Updating TailPointer to NextTail (or circular next position) when not full. 1 mark: Returning TRUE when successfully inserted.
想知道自己有幾分把握?
Thinka 是 DSE 學生用的 AI 練習應用程式,有無限量練習題、即時自動批改和詳細解題步驟。逾 100,000 名學生用它確認自己真的識,而不只是「以為識」。