An original Thinka practice paper modelled on the structure and difficulty of the Jun 2024 (V2) Cambridge IGCSE Computer Science (0478) paper. Not affiliated with or reproduced from Cambridge.
卷一 Computer Systems
Answer all questions. Calculators must not be used on this paper.
14 题目 · 51 分
题目 1 · Short Recall & Definition
2 分
State the role of the Program Counter (PC) in the Von Neumann architecture.
查看答案详解收起答案详解
解题
The Program Counter is a CPU register in the Control Unit. Its primary role is to hold the memory address of the next instruction that needs to be fetched from memory, decoded, and executed. Once the address is sent, the PC is incremented to point to the next instruction in sequence.
评分标准
One mark for each point (max 2): - Stores/holds the memory address of an instruction (1 mark) - ...of the next instruction to be fetched / decoded / executed (1 mark)
题目 2 · Short Recall & Definition
2 分
State what is meant by asymmetric encryption.
查看答案详解收起答案详解
解题
Unlike symmetric encryption which uses a single shared key, asymmetric encryption utilizes a key pair: a public key (which can be shared with anyone) and a private key (which is kept secret by the recipient). Data encrypted with the public key can only be decrypted with the corresponding private key.
评分标准
One mark for each point (max 2): - Uses two different keys / a public key and a private key (1 mark) - Keys are mathematically related / one key is used for encryption and the other is used for decryption (1 mark)
题目 3 · Short Recall & Definition
2 分
Explain the difference between half-duplex and full-duplex data transmission.
查看答案详解收起答案详解
解题
In half-duplex transmission, communication is bi-directional, but the devices must take turns sending data (such as a walkie-talkie). In full-duplex transmission, communication is bi-directional and can happen at the same time (such as a telephone call).
评分标准
One mark for each point (max 2): - Half-duplex: data is transmitted in both directions, but only one direction at a time / not simultaneously (1 mark) - Full-duplex: data is transmitted in both directions simultaneously / at the same time (1 mark)
题目 4 · Short Recall & Definition
2 分
Define what is meant by an interrupt in a computer system.
查看答案详解收起答案详解
解题
An interrupt is a mechanism used to alert the processor that an external event or software process requires immediate attention. When the processor receives an interrupt signal, it suspends its current operations, saves its state, and executes an interrupt service routine (ISR) to handle the event before resuming its previous tasks.
评分标准
One mark for each point (max 2): - A signal sent to the processor/CPU from a device/hardware or software program (1 mark) - Causes the processor to temporarily suspend its current task/instructions to service the interrupt (1 mark)
题目 5 · Short Recall & Definition
2 分
State what is meant by the cyber security threat 'pharming'.
查看答案详解收起答案详解
解题
Pharming attacks do not rely on tricking the user into clicking a link (unlike phishing). Instead, malicious code is installed on the user's computer or a DNS server is poisoned, redirecting legitimate traffic to a fraudulent website that mimics the real one to harvest credentials or personal details.
评分标准
One mark for each point (max 2): - Malicious code is installed on a user's computer/web server OR DNS server is poisoned/compromised (1 mark) - Redirects the user to a fake/malicious website without their consent/even if they typed the correct URL (1 mark)
题目 6 · Short Recall & Definition
2 分
State what is meant by lossless compression.
查看答案详解收起答案详解
解题
Lossless compression reduces file size by identifying and eliminating redundancy rather than discarding information. Algorithms like Run-Length Encoding (RLE) are used. This type of compression is critical for files where any loss of information could make them unusable, such as text files, executable code, or medical images.
评分标准
One mark for each point (max 2): - A method of reducing file size where no data/information is lost/discarded (1 mark) - The original file can be reconstructed exactly as it was / is identical to the original (1 mark)
题目 7 · Systems Calculations & Formats
4 分
A stereo audio track is recorded with a sample rate of 8000 Hz and a sample resolution of 16 bits. The duration of the audio track is 32 seconds.
Calculate the file size of the audio track in kibibytes (KiB). Show all your working.
查看答案详解收起答案详解
解题
1. Convert bits to bytes: 16 bits = 2 bytes.
2. Calculate total bytes: File size = sample rate × sample resolution (in bytes) × duration × number of channels File size = 8000 × 2 bytes × 32 seconds × 2 channels File size = 1,024,000 bytes.
1 mark for showing correct formula/substitution of values (8000 × 16 × 32 × 2). 1 mark for converting bits to bytes (dividing by 8) OR showing the correct intermediate total in bytes (1,024,000 bytes). 1 mark for dividing the byte total by 1024 to convert to KiB. 1 mark for the correct final answer of 1000 (KiB).
题目 8 · Systems Calculations & Formats
4 分
Two 8-bit signed binary integers representing positive denary values are shown:
Integer A: 01011100 Integer B: 00101010
Add the two integers using binary addition and explain why an overflow error has occurred.
An overflow error has occurred because: 1. The maximum value that can be represented by an 8-bit signed two's complement integer is +127. Adding 92 (Integer A) and 42 (Integer B) equals 134, which exceeds this limit. 2. Adding two positive numbers (MSB of 0) has resulted in a negative number (MSB of 1).
评分标准
1 mark for showing correct binary addition working (including carries). 1 mark for correct binary sum: 10000110. 1 mark for identifying that the sum (134 in denary) exceeds the maximum limit of +127 for an 8-bit signed representation. 1 mark for explaining that adding two positive numbers has incorrectly changed the sign bit / resulted in a negative number (MSB is 1).
题目 9 · Systems Calculations & Formats
4 分
A pixel sequence consists of 20 bytes of raw data represented by the characters: AAAAA BBB CCCC DDDDDDDD
This sequence is compressed using Run-Length Encoding (RLE), where each run is represented by a 1-byte count followed by a 1-byte character value.
Calculate the percentage reduction in size achieved by this compression. Show all your working.
查看答案详解收起答案详解
解题
1. Original size: There are 20 characters, which equals 20 bytes.
2. Compressed size: There are 4 distinct runs (5 A's, 3 B's, 4 C's, and 8 D's). Each compressed run requires 2 bytes (1 byte for count, 1 byte for value). Compressed size = 4 runs × 2 bytes = 8 bytes.
1 mark for identifying the correct original size of 20 bytes. 1 mark for calculating the correct compressed size of 8 bytes. 1 mark for calculating the savings difference in bytes (12 bytes). 1 mark for calculating the correct final percentage reduction of 60%.
题目 10 · Explaining System Processes
5 分
A local network is connected to the internet through a packet-filtering firewall. Explain the process of how this firewall decides whether to permit or block an incoming data packet attempting to enter the local network.
查看答案详解收起答案详解
解题
1. The firewall intercepts the incoming data packet at the network boundary. 2. It reads the packet header to extract metadata such as the source IP address, destination IP address, port number, and protocol type. 3. It compares this extracted data against its configured database of security rules (Access Control List). 4. If the packet characteristics match an 'allow' rule, the packet is forwarded to the destination computer within the local network. 5. If the packet violates the rules or matches a 'deny' rule, the firewall blocks or drops the packet, and may log the security event.
评分标准
Award 1 mark for each correct step described (maximum of 5 marks): - Intercepting the incoming data packet at the network gateway. - Extracting packet header information (accept examples such as source/destination IP, port number, protocol). - Comparing packet header details against a predefined set of security rules / Access Control List (ACL). - Permitting the packet to enter the network if it satisfies the security criteria. - Blocking/dropping the packet if it violates the criteria, and optionally logging/alerting the administrator.
题目 11 · Explaining System Processes
5 分
A microprocessor in a control system can receive interrupts from external sensors. Explain the step-by-step process that the CPU performs when an interrupt signal is received during program execution.
查看答案详解收起答案详解
解题
1. At the end of each instruction cycle, the CPU checks for any active interrupt signals. 2. If an interrupt is present, the CPU temporarily halts the execution of the current program. 3. The current contents of CPU registers, including the Program Counter (PC), are saved securely onto a memory stack. 4. The CPU loads the address of the corresponding Interrupt Service Routine (ISR) from an interrupt vector table into the Program Counter. 5. The CPU executes the ISR to handle the interrupt, and once complete, pops the saved register values back off the stack to resume the interrupted program from where it left off.
评分标准
Award 1 mark for each correct step described (maximum of 5 marks): - Checking for interrupts at the end of the current instruction cycle. - Pausing/halting the execution of the active program. - Saving the current processor state / register values (e.g. Program Counter) to a memory stack. - Loading and executing the appropriate Interrupt Service Routine (ISR) / interrupt handler. - Retrieving the saved state from the stack and resuming the original program at the next instruction.
题目 12 · Explaining System Processes
5 分
Data integrity must be maintained when sending a large binary file over a digital network. Explain the process of calculating and verifying a checksum to identify if any transmission errors have occurred.
查看答案详解收起答案详解
解题
1. Prior to transmission, the sender inputs the file data into a checksum generator algorithm. 2. The algorithm calculates a unique numeric value (the checksum) representing the data block. 3. This calculated checksum is appended to the payload of the data block and transmitted across the network. 4. Once received, the destination device inputs the received file payload into the exact same algorithm to produce a recalculated checksum. 5. The receiver compares the transmitted checksum value with its newly recalculated checksum; if they are identical, the file is verified as error-free; if they differ, the file is rejected and a retransmission is requested.
评分标准
Award 1 mark for each correct step described (maximum of 5 marks): - Sender applying a checksum algorithm to the data block prior to transmission. - Appending the calculated checksum value to the data block payload. - Transmitting both the data block and the checksum to the destination. - Receiver executing the same mathematical algorithm on the received data payload to generate a recalculated checksum. - Comparing the transmitted and recalculated checksums to detect errors (accepting if they match, flagging an error / requesting retransmission if they do not match).
题目 13 · Text Fills
6 分
Complete the paragraph about how interrupts are handled by the CPU. Use the terms from the list. Some terms will not be used, and some may be used once.
Terms: - application - accumulator - compiler - CPU - interrupt service routine (ISR) - operating system - printer - program counter - registers - signal
An interrupt is a (1) ................................................... sent from a device or software to the (2) ................................................... . This request causes the processor to temporarily suspend its current task. To do this, the processor must first save the current status of its (3) ................................................... so that it can return to the task later. The processor then executes a specialized program known as an (4) ................................................... to handle the request. A hardware interrupt could be triggered by a peripheral device, such as a (5) ................................................... indicating it has run out of paper. Once serviced, the processor restores the saved values and continues executing the suspended (6) ................................................... .
查看答案详解收起答案详解
解题
(1) signal: An interrupt is a signal sent to the processor. (2) CPU: The target that receives the interrupt request is the CPU. (3) registers: Register values (such as the Program Counter and Accumulator) must be saved to preserve the state. (4) interrupt service routine (ISR): This is the dedicated handler code executed for the specific interrupt. (5) printer: A printer running out of paper is a classic hardware interrupt scenario. (6) program: The CPU restores the saved register states and resumes the interrupted program.
评分标准
One mark for each correct term in the correct position: - (1) signal - (2) CPU - (3) registers - (4) interrupt service routine (ISR) - (5) printer - (6) program // task
题目 14 · Table Matching
6 分
The table contains statements describing different cyber security threats. Complete the table by giving the correct cyber security threat for each statement.
| Cyber security threat | Statement | | :--- | :--- | | ................................................... | A user is redirected to a fake website because malicious code has redirected the web traffic, even if they typed the correct URL. | | ................................................... | An attacker systematically tries every possible password combination until the correct one is discovered. | | ................................................... | Legitimate-looking emails are sent to users to trick them into clicking a link that takes them to a malicious website where they disclose personal details. | | ................................................... | Malware that encrypts a user's data and demands a fee to decrypt the files and restore access. | | ................................................... | A software program that misrepresents itself to appear useful, but secretly runs malicious code in the background. | | ................................................... | A type of malicious software that secretly monitors keypresses and user activity to gather sensitive information like passwords. |
查看答案详解收起答案详解
解题
- Row 1 describes Pharming because it involves redirecting web traffic to a DNS-spoofed fake site. - Row 2 describes a Brute-force attack as it involves trying all potential password combinations. - Row 3 describes Phishing, which relies on deceptive emails. - Row 4 describes Ransomware, which restricts access to files via encryption and demands payment. - Row 5 describes a Trojan horse, which masquerades as legitimate software. - Row 6 describes Spyware (such as keyloggers) which monitors and records user activity.
评分标准
One mark for each correct threat identified: - Row 1: Pharming - Row 2: Brute-force attack // Brute-force - Row 3: Phishing - Row 4: Ransomware - Row 5: Trojan horse // Trojan - Row 6: Spyware
Answer all questions. Calculators must not be used on this paper.
10 题目 · 56 分
题目 1 · Gate Matching & Identification
3 分
Three standard symbols for logic gates are described below.
- Symbol P: An OR gate with a small circle (bubble) at the output. - Symbol Q: An AND gate with a small circle (bubble) at the output. - Symbol R: An OR gate with an extra curved line along the input side.
Identify the logic function (gate name) represented by each symbol:
- Symbol P - Symbol Q - Symbol R
查看答案详解收起答案详解
解题
1. Symbol P is an OR gate followed by an inverter (indicated by the bubble at the output), which represents a NOR gate. 2. Symbol Q is an AND gate followed by an inverter (indicated by the bubble at the output), which represents a NAND gate. 3. Symbol R is an OR gate with an additional curved input line, which represents an Exclusive OR (XOR) gate.
评分标准
Award 1 mark for each correct identification up to a maximum of 3 marks: - NOR (1 mark) - NAND (1 mark) - XOR / Exclusive OR (1 mark)
题目 2 · Gate Matching & Identification
3 分
Three different truth tables for 2-input logic gates are described by their behavior below.
- Table X: The output is only 1 when both inputs are 0. - Table Y: The output is only 0 when both inputs are 1. - Table Z: The output is 1 only when the two inputs are different.
Identify the single standard logic gate (NOT, AND, OR, NAND, NOR, XOR) that corresponds to each truth table description:
- Table X - Table Y - Table Z
查看答案详解收起答案详解
解题
1. Table X describes a NOR gate because its output is 1 only when all inputs are 0. 2. Table Y describes a NAND gate because its output is 0 only when both inputs are 1 (the inverse of an AND gate). 3. Table Z describes an XOR gate because its output is 1 only when the inputs are different (one is 1 and the other is 0).
评分标准
Award 1 mark for each correct identification up to a maximum of 3 marks: - Table X: NOR (1 mark) - Table Y: NAND (1 mark) - Table Z: XOR (1 mark)
题目 3 · Gate Matching & Identification
3 分
Three logic circuit specifications are given below:
1. The output is 1 if either input A is 1 or input B is 1, but not both. 2. The output is 1 if input A is NOT 1 and input B is NOT 1. 3. The output is 1 if both inputs A and B are 1, then the result is inverted.
Identify the single standard logic gate that can perform each of these operations:
1. Specification 1 describes the Exclusive OR (XOR) gate where output is high if the inputs are different. 2. Specification 2 describes the NOR gate where output is 1 only when both inputs are 0. 3. Specification 3 describes the NAND gate where the result of the AND logic is inverted.
评分标准
Award 1 mark for each correct identification up to a maximum of 3 marks: - Specification 1: XOR / Exclusive OR (1 mark) - Specification 2: NOR (1 mark) - Specification 3: NAND (1 mark)
题目 4 · Algorithm Design & Debugging
5 分
An algorithm is written in pseudocode to find the minimum value in an array of 50 positive numbers, Scores[1:50].
01 Min <- 0 02 FOR Counter <- 1 TO 50 03 IF Scores[Counter] > Min 04 THEN 05 Min <- Scores[Counter] 06 ENDIF 07 NEXT Min
Identify the line numbers of three errors in the pseudocode and suggest a correction for each. Then explain why initializing Min to 0 (Line 01) prevents the algorithm from functioning correctly.
查看答案详解收起答案详解
解题
Errors and Corrections: 1. Line 01: 'Min <- 0' should be 'Min <- Scores[1]' (or a very large number like 99999). 2. Line 03: 'IF Scores[Counter] > Min' should be 'IF Scores[Counter] < Min'. 3. Line 07: 'NEXT Min' should be 'NEXT Counter'.
Explanation: Since all elements in the array are positive integers (greater than 0), the comparison 'Scores[Counter] < Min' (once corrected) will always evaluate to False if Min is initialized to 0. Consequently, Min will remain 0, which is incorrect as 0 is not a value in the array.
评分标准
One mark for each correct error identification and correction (max 3 marks): - Line 01: Change Min <- 0 to Min <- Scores[1] - Line 03: Change Scores[Counter] > Min to Scores[Counter] < Min - Line 07: Change NEXT Min to NEXT Counter
Two marks for explanation: - Explaining that positive numbers will always be greater than 0, meaning the 'less than' condition is never met (1 mark). - Concluding that Min will incorrectly remain 0 at the end of the execution (1 mark).
题目 5 · Algorithm Design & Debugging
5 分
Write an algorithm in pseudocode that inputs a user's age. The algorithm must: - Use a loop to validate that the age entered is a whole number between 11 and 18 inclusive. - Output an error message if the age is invalid and prompt the user to re-enter it. - Output 'Age accepted' once a valid age has been entered.
You do not need to declare your variables.
查看答案详解收起答案详解
解题
OUTPUT "Enter age:" INPUT Age WHILE Age < 11 OR Age > 18 OUTPUT "Invalid age. Please enter an age between 11 and 18:" INPUT Age ENDWHILE OUTPUT "Age accepted"
(Alternative using REPEAT...UNTIL): REPEAT OUTPUT "Enter age:" INPUT Age IF Age < 11 OR Age > 18 THEN OUTPUT "Invalid age." ENDIF UNTIL Age >= 11 AND Age <= 18 OUTPUT "Age accepted"
评分标准
One mark for each point (max 5 marks): - MP1: Initializing variable and setting up a conditional loop (WHILE or REPEAT...UNTIL). - MP2: Prompting and getting input for age inside the loop. - MP3: Correct validation condition checking range (e.g. Age < 11 OR Age > 18 for loop entry, or Age >= 11 AND Age <= 18 for loop exit). - MP4: Outputting an appropriate error message inside the loop when input is invalid. - MP5: Outputting 'Age accepted' only after exiting the validation loop.
题目 6 · Algorithm Design & Debugging
5 分
A 1D array Rainfall[1:30] stores the daily rainfall in millimetres (mm) for a 30-day month.
Write an algorithm in pseudocode to: - Calculate and output the total rainfall for the entire month. - Count and output the number of days that had zero rainfall.
You do not need to declare your variables.
查看答案详解收起答案详解
解题
Total <- 0 DryDays <- 0 FOR Day <- 1 TO 30 Total <- Total + Rainfall[Day] IF Rainfall[Day] = 0 THEN DryDays <- DryDays + 1 ENDIF NEXT Day OUTPUT "Total rainfall for the month is: ", Total OUTPUT "Number of days with zero rainfall: ", DryDays
评分标准
One mark for each point (max 5 marks): - MP1: Initialise total and dry day counters to 0 before the loop. - MP2: Set up a loop to iterate through all 30 elements of the array (e.g., FOR Day <- 1 TO 30). - MP3: Accumulate the total rainfall inside the loop (Total <- Total + Rainfall[Day]). - MP4: Check if rainfall is 0 and increment the dry days counter inside the loop. - MP5: Output both the total rainfall and the number of dry days after the loop ends.
题目 7 · Algorithm Design & Debugging
5 分
An algorithm is written in pseudocode to search for a target name in an array of 100 names, Names[1:100].
01 Index <- 0 02 Found <- FALSE 03 WHILE Found = FALSE OR Index < 100 04 IF Names[Index] = Target 05 THEN 06 Found <- TRUE 07 OUTPUT "Found at ", Index 08 ENDIF 09 Index <- Index + 1 10 NEXT Index
Identify the line numbers of three errors in this pseudocode, suggest a correction for each, and explain why using 'OR' in Line 03 causes a logic error.
查看答案详解收起答案详解
解题
Errors and Corrections: 1. Line 01: 'Index <- 0' should be 'Index <- 1' (as the array index starts at 1). 2. Line 03: 'Found = FALSE OR Index < 100' should be 'Found = FALSE AND Index <= 100' (to prevent out-of-bounds and stop when found). 3. Line 10: 'NEXT Index' should be 'ENDWHILE' (closing the while loop).
Explanation of the OR error: If the logical operator 'OR' is used, the loop condition remains True even if one sub-condition becomes False. If the item is found, 'Found' becomes True, but the loop continues because 'Index < 100' is still True. Alternatively, if the item is not found, when Index reaches 101, 'Index < 100' becomes False, but the loop continues because 'Found = FALSE' is still True, causing an 'index out of bounds' error.
评分标准
One mark for each correct error identification and correction (max 3 marks): - Line 01: Change Index <- 0 to Index <- 1 - Line 03: Change OR to AND (accept changing < 100 to <= 100 as part of this or as an alternate correct mark) - Line 10: Change NEXT Index to ENDWHILE
Two marks for explanation of the 'OR' error: - Explaining that 'OR' means the loop continues even after the target is found (1 mark). - Explaining that 'OR' leads to an out-of-bounds array index error when the name is not in the list (1 mark).
题目 8 · structural
6 分
A public library uses a database table named `Book` to store information about its inventory. The fields in the table are:
* `BookID` – the unique book identifier, for example 'BK904' * `Title` – the title of the book, for example 'The Great Gatsby' * `YearPublished` – the year the book was published, for example 2018 * `Available` – whether the book is currently available to be borrowed (yes or no) * `Price` – the replacement cost of the book, for example 14.99
(a) Identify the field that is most suitable to be used as the primary key for the `Book` table. [1]
(b) State the most suitable data type for the following four fields in this table: `BookID`, `YearPublished`, `Available`, and `Price`. [2]
(c) Explain what is achieved by executing each of these structured query language (SQL) queries:
* **Query 1**: `SELECT AVG(Price) FROM Book;` [1] * **Query 2**: `SELECT COUNT(BookID) FROM Book WHERE Available = FALSE;` [2]
查看答案详解收起答案详解
解题
(a) The field `BookID` is the most appropriate primary key because it contains unique values that uniquely identify each record (book) in the database.
(b) Suitable data types: * `BookID`: Text/Alphanumeric because it contains letters and numbers (e.g., 'BK904'). * `YearPublished`: Integer because calendar years are whole numbers (e.g., 2018). * `Available`: Boolean since it only requires two states: yes (True) or no (False). * `Price`: Real/Decimal/Currency because it contains fractional values representing money (e.g., 14.99).
(c) Explanations of SQL Queries: * **Query 1**: Finds the average value of the `Price` field across all book records. * **Query 2**: Finds the total count of books where the `Available` status is FALSE (representing books currently checked out/unavailable).
评分标准
(a) * 1 mark for identifying `BookID`.
(b) * 2 marks for all four correct data types. * 1 mark if two or three are correct. * 0 marks if fewer than two are correct.
(c) * 1 mark for Query 1: correct identification of finding the average replacement cost/price of books. * 2 marks for Query 2: * 1 mark for identifying that it counts the records/number of books. * 1 mark for identifying the condition (where they are unavailable / Available is false).
题目 9 · structural
6 分
The following algorithm is written in pseudocode:
```text 01 Counter ← 1 02 Total ← 0 03 Limit ← 4 04 REPEAT 05 INPUT Value 06 IF Value > 10 07 THEN 08 Total ← Total + Value 09 ELSE 10 Total ← Total - Value 11 ENDIF 12 Counter ← Counter + 1 13 UNTIL Counter > Limit 14 OUTPUT Total ```
(a) Complete the trace table for the algorithm using the following input data: `12, 5, 15, 8` [4]
(a) Step-by-step trace process: * `Counter ← 1`, `Total ← 0`, `Limit ← 4` are initialized. * **Iteration 1**: `Value` = 12. Since 12 > 10, `Total` becomes 0 + 12 = 12. `Counter` is incremented to 2. Condition `Counter > Limit` (2 > 4) is FALSE. * **Iteration 2**: `Value` = 5. Since 5 is not > 10, `Total` becomes 12 - 5 = 7. `Counter` is incremented to 3. Condition `Counter > Limit` (3 > 4) is FALSE. * **Iteration 3**: `Value` = 15. Since 15 > 10, `Total` becomes 7 + 15 = 22. `Counter` is incremented to 4. Condition `Counter > Limit` (4 > 4) is FALSE. * **Iteration 4**: `Value` = 8. Since 8 is not > 10, `Total` becomes 22 - 8 = 14. `Counter` is incremented to 5. Condition `Counter > Limit` (5 > 4) is TRUE, so the loop terminates. * `Total` (14) is output.
(b) The algorithm iterates 4 times, taking a user input on each loop. If the input is greater than 10, it adds it to a running sum; if it is 10 or less, it subtracts it from that sum. It outputs the final cumulative total.
评分标准
(a) Trace Table Marks [Max 4]: * 1 mark for initialization: Counter = 1, Total = 0, Limit = 4 correctly logged. * 1 mark for logging all values of `Value` in correct sequential rows (12, 5, 15, 8). * 1 mark for calculating correct updates to `Total` at each step (12, 7, 22, 14). * 1 mark for correct increment of `Counter` up to 5 and the correct final output value (14).
(b) Description Marks [Max 2]: * 1 mark for identifying that it processes/inputs exactly 4 numbers. * 1 mark for stating that numbers greater than 10 are added to a running sum, and numbers 10 or less are subtracted (and the total is output).
题目 10 · free_response
15 分
A game simulating a delivery drone uses a two-dimensional (2D) array `Warehouse[]` of size 6 by 6 to store the positions of a package and an obstacle.
At the start of the game: * The program places a 'P' (package) in a random cell (not in `Warehouse[1,1]`) and empties all other cells. * The program places an 'O' (obstacle) in a random cell (not in `Warehouse[1,1]` and not in the same cell as the package). * The drone starts at the top left of the grid (`Warehouse[1,1]`). * The drone starts with 8 energy points.
During the game: * The player inputs a direction to move: 'N' (Up), 'S' (Down), 'E' (Right), or 'W' (Left) by one cell. * The program must check if the move is within the grid boundaries. If a move is out of range, the drone does not move, no energy is lost, and an appropriate message is displayed. * For each valid move, the drone loses 1 energy point. * If the drone moves onto the cell containing 'O', it loses an additional 2 energy points, and a warning is displayed. * "Delivery Successful" is displayed if the drone reaches the cell with 'P' and has energy remaining (greater than 0). * "Delivery Failed" is displayed if the drone runs out of energy (0 or less) without reaching the package.
Write a program that meets these requirements.
You must use pseudocode or program code and add comments to explain how your code works.
You do not need to declare any arrays or variables; you may assume that this has already been done.
All inputs and outputs must contain suitable messages.
查看答案详解收起答案详解
解题
Below is an example solution written in pseudocode:
```text // Set up warehouse grid FOR Row <- 1 TO 6 FOR Column <- 1 TO 6 Warehouse[Row, Column] <- "" NEXT Column NEXT Row
// Generate random position for Package (P) avoiding start cell [1,1] REPEAT PRow <- ROUND((RANDOM() * 5) + 1, 0) PCol <- ROUND((RANDOM() * 5) + 1, 0) UNTIL PRow <> 1 OR PCol <> 1 Warehouse[PRow, PCol] <- "P"
// Generate random position for Obstacle (O) avoiding [1,1] and [PRow, PCol] REPEAT ORow <- ROUND((RANDOM() * 5) + 1, 0) OCol <- ROUND((RANDOM() * 5) + 1, 0) UNTIL (ORow <> 1 OR OCol <> 1) AND (ORow <> PRow OR OCol <> PCol) Warehouse[ORow, OCol] <- "O"
// Game loop WHILE Energy > 0 AND NOT Success OUTPUT "Current position: Row ", DroneRow, ", Column ", DroneCol OUTPUT "Energy remaining: ", Energy OUTPUT "Enter move (N = North, S = South, E = East, W = West): " INPUT Move
// Process move inputs IF Move = "N" THEN TempRow <- DroneRow - 1 MoveValid <- TRUE ELSEIF Move = "S" THEN TempRow <- DroneRow + 1 MoveValid <- TRUE ELSEIF Move = "E" THEN TempCol <- DroneCol + 1 MoveValid <- TRUE ELSEIF Move = "W" THEN TempCol <- DroneCol - 1 MoveValid <- TRUE ELSE OUTPUT "Invalid input! Enter N, S, E, or W." ENDIF
IF MoveValid THEN // Boundary check IF TempRow >= 1 AND TempRow <= 6 AND TempCol >= 1 AND TempCol <= 6 THEN // Update actual drone position and consume base energy DroneRow <- TempRow DroneCol <- TempCol Energy <- Energy - 1
// Check if cell has an obstacle IF Warehouse[DroneRow, DroneCol] = "O" THEN OUTPUT "Warning! Hit an obstacle! Lost 2 extra energy points." Energy <- Energy - 2 ENDIF
// Check if cell contains the package IF Warehouse[DroneRow, DroneCol] = "P" THEN OUTPUT "Delivery Successful!" Success <- TRUE ENDIF ELSE OUTPUT "Boundary error! Drone cannot leave the warehouse area." ENDIF ENDIF ENDWHILE
// Check end-of-game outcome IF NOT Success THEN OUTPUT "Delivery Failed! Out of energy." ENDIF ```
评分标准
### AO2: Apply knowledge and understanding (Max 9 marks) * **R1: Game Setup (Max 3 marks)** * Clearing all elements of the 2D array appropriately. * Generating unique random coordinates for 'P' (not in cell [1,1]). * Generating unique random coordinates for 'O' (not in cell [1,1] and not equal to 'P' cell). * **R2: Input & Validation (Max 3 marks)** * Looping continuously until energy is depleted or game is won. * Inputting directions (N, S, E, W) and mapping to temporary coordinates. * Checking if the planned moves are within the index range of 1 to 6. * **R3: Game Logic & Outcomes (Max 3 marks)** * Deducting 1 point of energy for valid moves, and handling boundary warnings without deducting energy. * Deducting an additional 2 energy points (total 3 points) if 'O' is encountered. * Outputting the correct win/loss termination messages.
### AO3: Provide solutions (Max 6 marks) * **Comments (Max 2 marks)** * *2 marks*: Program has been fully commented with relevant descriptions. * *1 mark*: Program has some relevant comments. * **Identifiers & Logic Flow (Max 2 marks)** * *2 marks*: Highly meaningful variable names used throughout; clear logical sequence. * *1 mark*: Majority of identifiers are appropriately named; solution has some minor structural flaws. * **Completeness & Accuracy (Max 2 marks)** * *2 marks*: Solution matches all the program specifications accurately without design flaws. * *1 mark*: Solution contains a few operational logical errors but covers most aspects of the simulation.
想知道自己有几分把握?
thinka 是 DSE 学生在用的 AI 练习应用,提供无限量练习题、即时自动批改和详细解题步骤。超过 100,000 名学生用它确认自己是真的会,而不只是「以为会」。