Cambridge IGCSE · thinka 原创模拟试题

2023 Cambridge IGCSE Computer Science (0478) 模拟试题及答案详解

Thinka Jun 2023 (V2) Cambridge IGCSE-Style Mock — Computer Science (0478)

145 210 分钟2023
An original Thinka practice paper modelled on the structure and difficulty of the Jun 2023 (V2) Cambridge IGCSE Computer Science (0478) paper. Not affiliated with or reproduced from Cambridge.

Paper 12 Computer Systems

Answer all questions. Calculators must not be used.
10 题目 · 75
题目 1 · Short Answer
3
An embedded system developer uses hexadecimal notation instead of binary when defining memory-mapped input/output addresses. State three reasons why the developer would prefer to represent binary numbers in hexadecimal format.
查看答案详解

解题

Hexadecimal is used as a human-friendly shorthand for binary numbers because:
1. Shorter representation: Hexadecimal uses fewer digits (one hex digit per four binary bits), which is more compact and takes up less screen space.
2. Readability: It is much easier for programmers to read, write, and understand compared to long strings of 1s and 0s.
3. Less error-prone: Because the numbers are shorter and easier to parse visually, programmers are far less likely to make transcription or data entry mistakes.

评分标准

Award 1 mark per correct reason, up to a maximum of 3 marks:
- Shorter / more compact representation // takes up less screen space
- Easier/quicker to read, write, or understand
- Fewer errors/mistakes are likely to be made (when copying/entering)
- Easier to troubleshoot/debug (the code)
(Note: Reject "saves storage space / memory" as hexadecimal is only used for human representation; in memory, it is still stored as binary.)
题目 2 · Short Answer
3
An operating system uses interrupts to manage various signals from hardware devices and software programs. Explain what happens when a hardware device, such as a printer, generates an interrupt signal while the CPU is executing a user program.
查看答案详解

解题

When a hardware device generates an interrupt, the CPU temporarily stops executing the current user program. First, it saves the current status/state (including the program counter and register values) so it can return to it later. Second, it loads and executes the specific interrupt handler, known as the Interrupt Service Routine (ISR), to service the hardware request. Finally, once the ISR finishes, the CPU restores the saved state of the user program and resumes its execution from where it left off.

评分标准

Award 1 mark per correct point, up to a maximum of 3 marks:
- The CPU suspends/stops the execution of the current program/task.
- The CPU saves the current status / registers / program counter.
- The CPU identifies the interrupt source and runs/executes the Interrupt Service Routine (ISR) / handles the interrupt.
- Once the interrupt is handled, the saved state is restored and execution of the suspended program resumes.
题目 3 · Short Answer
3
A local network transfers files between computers. A checksum is used to detect transmission errors. Describe how a checksum is used to verify that a file has been transmitted without errors.
查看答案详解

解题

To verify a transmission using a checksum:
1. Calculation at Sender: Before sending, the sender uses a mathematical algorithm to calculate a checksum value based on the binary data of the file.
2. Transmission: The calculated checksum is sent along with the file to the destination.
3. Calculation and Comparison at Receiver: The receiver applies the identical algorithm to the received file to compute its own checksum. It then compares this computed checksum with the transmitted checksum. If the values are identical, the file is assumed to have arrived without errors. If they differ, an error has occurred, and the receiver requests a retransmission.

评分标准

Award 1 mark per point, up to a maximum of 3 marks:
- The sender calculates a checksum value from the data using an algorithm / formula before transmission.
- The checksum value is transmitted alongside the data.
- The receiver applies the same algorithm/formula to the received data to calculate its own checksum.
- The receiver compares the calculated checksum with the received checksum.
- If the two values match, the data is error-free // if they do not match, an error is detected (and a request for retransmission is made).
题目 4 · Short Answer
3
Explain how lossy compression reduces the file size of an image and state why a professional photographer might choose lossless compression instead.
查看答案详解

解题

Lossy compression algorithms reduce file sizes by permanently removing data that the human eye cannot easily perceive, such as subtle variations in color shades. A professional photographer, however, would avoid this and select lossless compression because it retains every single bit of original data without degrading image quality, which is critical when editing, printing, or archiving high-quality photos.

评分标准

Award 1 mark per point, up to a maximum of 3 marks:
- Lossy compression permanently discards/deletes data from the file.
- It identifies and removes redundant/unnecessary data (e.g., color shades the human eye cannot distinguish easily).
- Lossless compression is chosen because it retains all original data / does not degrade image quality / allows perfect reconstruction of the original file.
题目 5 · Short Answer
3
The Program Counter (PC) is a key register within the CPU's Control Unit. Describe the role of the Program Counter in the Fetch-Decode-Execute cycle, including how its value changes.
查看答案详解

解题

During the Fetch-Decode-Execute cycle, the Program Counter (PC) plays a critical role:
1. It stores the memory address of the next instruction scheduled for execution.
2. At the start of the fetch stage, the address in the PC is copied to the Memory Address Register (MAR) via the address bus.
3. Immediately after this address is copied, the PC is incremented by 1, preparing it to point to the next instruction in sequence for the subsequent cycle.

评分标准

Award 1 mark per point, up to a maximum of 3 marks:
- Stores/holds the address of the next instruction to be fetched/executed.
- This address is copied/sent to the Memory Address Register (MAR) (at the start of the fetch stage).
- The Program Counter is incremented (by 1) (to point to the subsequent instruction).
题目 6 · Structured Theory
12
1 (a) Convert the two binary numbers to hexadecimal.

(i) 110101101011

..........................................................................................................................................

(ii) 001111000101

.......................................................................................................................................... [4]

Working space

..........................................................................................................................................

..........................................................................................................................................

(b) A value is stored as an 8-bit binary number in a register:

0 0 1 1 0 1 1 0

A logical left shift of two places is performed on the binary number.

(i) Complete the binary register to show its contents after this logical left shift. [1]

(ii) State the mathematical effect of this logical left shift on the binary number and explain a potential problem that can occur when performing a left shift on a register of fixed size. [2]

..........................................................................................................................................

..........................................................................................................................................

(c) Give three reasons why programmers use hexadecimal to represent binary numbers, and explain why computers only process data in binary format. [5]

..........................................................................................................................................

..........................................................................................................................................

..........................................................................................................................................
查看答案详解

解题

(a) (i) D6B
(ii) 3C5
(b) (i) [ 1 | 1 | 0 | 1 | 1 | 0 | 0 | 0 ]
(ii) Mathematical effect: Multiplies the value by 4 (since shifting left by $n$ places multiplies by $2^n$).
Potential problem: Overflow error. If any highly significant '1' bits are shifted out of the left end of the register, they are lost, resulting in an incorrect final value.
(c) Reasons for using hexadecimal:
1. It is easier and quicker for humans to read, write, and understand than long strings of binary.
2. It is much easier to debug and find errors in code.
3. It takes up less screen space.
Why computers process in binary:
Computer processors are made of millions of tiny switches (transistors) that can only exist in one of two stable physical states: on (represented as 1) or off (represented as 0).

评分标准

(a) One mark per each correct character in the correct order:
- D, 6, B (2 marks)
- 3, C, 5 (2 marks)

(b) (i) One mark for correct binary contents:
- 11011000 (1 mark)
(ii) One mark for mathematical effect and one mark for potential problem:
- Multiplies the number by 4 (1 mark)
- Risk of overflow / loss of significant bits (1 mark)

(c) Maximum three marks for hexadecimal benefits:
- Easier/quicker to read, write, and understand (1 mark)
- Shorter representation / takes up less screen space (1 mark)
- Less likely to make mistakes / easier to debug (1 mark)
Maximum two marks for binary format necessity:
- Computer systems are built from transistors / logic gates (1 mark)
- These only have two stable states (on/off, high/low voltage), which maps perfectly to 1 and 0 (1 mark)
题目 7 · Structured Theory
12
2 (a) Describe the role of the Program Counter (PC) and the Memory Address Register (MAR) during the fetch stage of the fetch-decode-execute cycle. [4]

..........................................................................................................................................

..........................................................................................................................................

..........................................................................................................................................

(b) Computer systems use interrupts to manage communication between hardware devices and the processor.

(i) Describe what is meant by an interrupt. [2]

..........................................................................................................................................

..........................................................................................................................................

(ii) State three different sources of an interrupt. [3]

..........................................................................................................................................

..........................................................................................................................................

(c) Identify three main components of the CPU (excluding registers) and state their primary function. [3]

..........................................................................................................................................

..........................................................................................................................................
查看答案详解

解题

(a) The Program Counter (PC) holds the address of the next instruction to be fetched from memory. This address is then copied from the PC to the Memory Address Register (MAR) via the address bus. Once copied, the PC is incremented by one so that it points to the address of the subsequent instruction.
(b) (i) An interrupt is a signal sent from a device or software program to the processor. It alerts the processor that an event has occurred that requires immediate attention, causing the processor to temporarily suspend its current execution cycle to run an interrupt service routine (ISR).
(ii) Sources: Input/Output hardware request (e.g., printer out of paper, keyboard keystroke), hardware fault (e.g., power failure), or software error (e.g., division by zero).
(c) 1. Control Unit (CU): Decodes instructions and sends control signals to coordinate the flow of data within the CPU.
2. Arithmetic Logic Unit (ALU): Performs arithmetic operations (like addition and subtraction) and logical comparisons (like AND, OR, and NOT).
3. Internal/System Clock: Emits regular electrical pulses to synchronize all CPU operations.

评分标准

(a) One mark per descriptive point, max 4:
- Program Counter (PC) holds the address of the next instruction to be fetched (1 mark)
- This address is copied from the PC to the MAR (1 mark)
- This address is transmitted using the address bus (1 mark)
- The PC is incremented (by 1) (1 mark)

(b) (i) One mark per point, max 2:
- A signal sent to the processor from a device/software (1 mark)
- Requesting processor attention / temporarily suspends current execution to run an ISR (1 mark)
(ii) One mark per correct source, max 3:
- Hardware error (e.g., disk read fail) (1 mark)
- I/O request (e.g., keyboard input, printer out of paper) (1 mark)
- Software error (e.g., division by zero) (1 mark)
- Timer signal (1 mark)

(c) One mark for each component and its correct function, max 3:
- Control Unit (CU) - decodes instructions / directs data flow (1 mark)
- Arithmetic Logic Unit (ALU) - performs calculations / logical operations (1 mark)
- Clock - synchronizes processing components (1 mark)
题目 8 · Structured Theory
12
3 (a) Complete the paragraph about how a web page is requested and displayed, using terms from the list.

Some of the terms in the list will not be used. Some terms may be used more than once.

Cookie, DNS server, HTML, HTTP/HTTPS, IP address, MAC address, URL, Web browser, Web server

A user enters a website's ........................................................... into their ........................................................... . This application sends the domain name to a ........................................................... to find the corresponding ........................................................... . A request is then sent to the ........................................................... hosting the website using the ........................................................... protocol. [6]

(b) Cyber security threats are a major concern for online systems.

(i) Define what is meant by 'phishing' and explain how it differs from 'pharming'. [4]

..........................................................................................................................................

..........................................................................................................................................

..........................................................................................................................................

(ii) Give two methods a user can employ to detect or protect themselves from a phishing attempt. [2]

..........................................................................................................................................

..........................................................................................................................................
查看答案详解

解题

(a) URL, Web browser, DNS server, IP address, Web server, HTTP/HTTPS
(b) (i) Phishing is a social engineering attack where malicious actors send fraudulent messages (usually emails) designed to look legitimate, in order to trick users into sharing sensitive data (like passwords or credit card numbers). Pharming is a cyberattack where traffic from a legitimate website is hijacked and redirected to a fake replica website.
The key difference is that phishing relies on the user actively clicking a deceptive link in a message, whereas pharming operates silently behind the scenes by installing malicious code on a computer or poisoning DNS servers, redirecting users even if they typed the correct address.
(ii) Protection methods:
- Look closely for spelling mistakes and poor grammar in the message text.
- Check the actual domain name of the sender's email address rather than just the friendly display name.

评分标准

(a) One mark for each correct term in order:
1. URL
2. Web browser
3. DNS server
4. IP address
5. Web server
6. HTTP/HTTPS

(b) (i) One mark for definition of phishing:
- Sending fake emails to trick users into providing credentials/data (1 mark)
One mark for definition of pharming:
- Redirecting user traffic to a fake website using malicious software or DNS manipulation (1 mark)
Two marks for contrast/differences (max 2):
- Phishing requires the user to click a link to proceed (1 mark)
- Pharming redirects users automatically even if they type the correct URL (1 mark)

(ii) One mark for each valid protection method, max 2:
- Check for poor spelling / grammatical errors (1 mark)
- Examine the sender's email domain address (1 mark)
- Avoid clicking links; go directly to the official website (1 mark)
- Use two-factor authentication (2FA) (1 mark)
题目 9 · Structured Theory
12
4 An automated climate control system is installed in a large commercial greenhouse to maintain optimal growth conditions for rare plants. The system must maintain a constant temperature between 18°C and 24°C, and ensure soil moisture does not fall below a set limit.

(a) (i) Identify two sensors that would be suitable for use in this system. [2]

(ii) Identify two actuators that would be used in this system. [2]

(iii) Describe how the sensors, microprocessor, and actuators work together to automatically control the environment in the greenhouse. [5]

..........................................................................................................................................

..........................................................................................................................................

..........................................................................................................................................

(b) The system has a capacitive touch screen interface for staff to monitor status. Describe how a capacitive touch screen detects a user's input. [3]

..........................................................................................................................................

..........................................................................................................................................

..........................................................................................................................................
查看答案详解

解题

(a) (i) Temperature sensor and soil moisture (humidity) sensor.
(ii) Heater, cooling fan, water valve/pump, or window motor.
(iii) The sensors continuously collect analogue environmental data and send it to an Analogue-to-Digital Converter (ADC). The ADC converts this to digital data, which is passed to the microprocessor. The microprocessor compares these values to the preset limits (18°C–24°C for temperature, and the moisture threshold). If a value is outside the limits, the microprocessor sends digital control signals to turn an actuator on or off (e.g., turning on the heater if the temperature is below 18°C, or opening water pumps if the soil is dry). The digital signal is converted back to analogue if the actuator requires it. This process operates continuously in a feedback loop.
(b) A capacitive touch screen contains a glass panel coated with a transparent, charge-storing conductive layer. When a user's finger (which conducts electricity) touches the screen, it draws an electrical current from that point, creating a change in the electrostatic capacitance. Sensors at the corners of the screen measure this difference, and a microprocessor calculates the precise coordinates of the touch.

评分标准

(a) (i) One mark per correct sensor, max 2:
- Temperature sensor (1 mark)
- Moisture / humidity sensor (1 mark)
(ii) One mark per correct actuator, max 2:
- Heater / heating element (1 mark)
- Fan / cooling pump (1 mark)
- Water pump / motorized valve (1 mark)
- Vent / window motor (1 mark)
(iii) One mark per descriptive point, max 5:
- Sensors continuously capture analogue data (1 mark)
- Analogue data is converted to digital via an ADC (1 mark)
- Microprocessor compares digital data against pre-programmed ranges (1 mark)
- If out of range, microprocessor sends signal to actuator (1 mark)
- Actuators operate (e.g., heater turns on) to bring condition back to set limit (1 mark)
- System runs continuously in a feedback loop (1 mark)

(b) One mark per descriptive point, max 3:
- Screen features a transparent conductive/charge-storing layer (1 mark)
- Touching screen with a finger draws a current / disrupts the electrostatic field (1 mark)
- The resulting change in capacitance is detected by sensors (1 mark)
- Microprocessor calculates the exact X-Y coordinates of the touch (1 mark)
题目 10 · Structured Theory
12
5 (a) A logic circuit has three inputs: A, B, and C. The output X is 1 if (A is NOT 1 AND B is 1) OR (B is NOT 1 AND C is 1).

(i) Write the logic expression for this system. [3]

..........................................................................................................................................

(ii) Complete the truth table for this logic expression.

| A | B | C | Working space | X |
|---|---|---|---|---|
| 0 | 0 | 0 | | |
| 0 | 0 | 1 | | |
| 0 | 1 | 0 | | |
| 0 | 1 | 1 | | |
| 1 | 0 | 0 | | |
| 1 | 0 | 1 | | |
| 1 | 1 | 0 | | |
| 1 | 1 | 1 | | | [4]

(b) Programmers can use compilers or interpreters to translate high-level code.

(i) Describe two differences between how a compiler and an interpreter translate and execute a program. [4]

..........................................................................................................................................

..........................................................................................................................................

..........................................................................................................................................

(ii) State one advantage of using an interpreter during the development of a program. [1]

..........................................................................................................................................
查看答案详解

解题

(a) (i) $X = (\text{NOT } A \text{ AND } B) \text{ OR } (\text{NOT } B \text{ AND } C)$
(ii) Let's evaluate the expression for each row:
- Row 1 (0,0,0): (1 AND 0) OR (1 AND 0) -> 0 OR 0 = 0
- Row 2 (0,0,1): (1 AND 0) OR (1 AND 1) -> 0 OR 1 = 1
- Row 3 (0,1,0): (1 AND 1) OR (0 AND 0) -> 1 OR 0 = 1
- Row 4 (0,1,1): (1 AND 1) OR (0 AND 1) -> 1 OR 0 = 1
- Row 5 (1,0,0): (0 AND 0) OR (1 AND 0) -> 0 OR 0 = 0
- Row 6 (1,0,1): (0 AND 0) OR (1 AND 1) -> 0 OR 1 = 1
- Row 7 (1,1,0): (0 AND 1) OR (0 AND 0) -> 0 OR 0 = 0
- Row 8 (1,1,1): (0 AND 1) OR (0 AND 1) -> 0 OR 0 = 0

Output $X$ values from top to bottom: 0, 1, 1, 1, 0, 1, 0, 0.

(b) (i) Two differences:
1. A compiler translates the entire source code in one operation into machine code (object code), whereas an interpreter translates and executes the source code line-by-line.
2. A compiler generates a standalone executable file (e.g., .exe), so the program can run on another computer without needing the compiler. An interpreter does not produce an executable file; the interpreter must always be present to run the code.
(ii) Interpreters stop executing immediately at the exact line where a syntax error is found. This helps the developer locate and fix bugs much faster.

评分标准

(a) (i) Three marks for correct logic expression:
- (NOT A AND B) (1 mark)
- (NOT B AND C) (1 mark)
- OR joining the components (1 mark)
(ii) Four marks for correct X output column:
- 4 marks for all 8 correct outputs: 0, 1, 1, 1, 0, 1, 0, 0
- 3 marks for 6 or 7 correct outputs
- 2 marks for 4 or 5 correct outputs
- 1 mark for 2 or 3 correct outputs

(b) (i) Two marks per difference, max 4 (must address both compiler and interpreter for each point):
- Translation method: Compiler translates whole source code at once // Interpreter translates code line-by-line (2 marks)
- Output file: Compiler produces a separate executable machine code file // Interpreter does not produce an object/executable file (2 marks)
- Execution speed: Compiler code runs faster once compiled // Interpreter code runs slower because translation occurs on the fly (2 marks)
(ii) One mark for advantage:
- Facilitates easier / faster debugging (1 mark)

准备好测试自己了吗?

将这些笔记转化为考试练习。获取此课题的无限AI题目,即时批改及详细解析。

练习此课题

Paper 22 Algorithms, Programming and Logic

Answer all questions. Calculators must not be used.
9 题目 · 53
题目 1 · Short Answer
4
A security alarm system has three inputs representing sensors: \(A\) (motion detector), \(B\) (door sensor), and \(C\) (window sensor). The alarm system output \(X\) is 1 (activated) if:
- Motion detector \(A\) is active AND door sensor \(B\) is active,
- OR
- Window sensor \(C\) is active AND motion detector \(A\) is NOT active.

(a) Write a logic expression to represent this security system using the terms AND, OR, and NOT.
(b) State the value of \(X\) for each of the following scenarios:
(i) \(A = 0, B = 1, C = 1\)
(ii) \(A = 1, B = 0, C = 1\)
查看答案详解

解题

(a) Combining the two conditions with OR gives: \(X = (A \text{ AND } B) \text{ OR } (C \text{ AND NOT } A)\).
(b) (i) When \(A = 0, B = 1, C = 1\), the first part \(A \text{ AND } B = 0\), but the second part \(C \text{ AND NOT } A = 1 \text{ AND } 1 = 1\). Thus \(X = 0 \text{ OR } 1 = 1\).
(ii) When \(A = 1, B = 0, C = 1\), the first part \(A \text{ AND } B = 0\), and the second part \(C \text{ AND NOT } A = 1 \text{ AND } 0 = 0\). Thus \(X = 0 \text{ OR } 0 = 0\).

评分标准

(a) 2 marks:
- 1 mark for: `(A AND B)`
- 1 mark for: `OR (C AND NOT A)` (or equivalent logic)
(b) 2 marks:
- 1 mark for: (i) X = 1
- 1 mark for: (ii) X = 0
题目 2 · Short Answer
4
A bookstore database has a table named `Books` to store details of items.
(a) State the most appropriate data type for the fields `BookID` (e.g. BK902) and `Price` (e.g. 12.99).
(b) Explain the purpose of the following SQL statement:
`SELECT Title, Price FROM Books WHERE InStock = TRUE ORDER BY Price DESC;`
查看答案详解

解题

(a) `BookID` contains both letters and numbers, making Text or Alphanumeric the most appropriate data type. `Price` contains fractional numbers, so Real, Decimal, or Currency is the correct data type.
(b) The `SELECT` clause retrieves the Title and Price. The `WHERE` clause filters only books that are currently in stock. The `ORDER BY Price DESC` clause sorts the output in descending order of price (highest first).

评分标准

(a) 2 marks:
- 1 mark for BookID: Text / Alphanumeric / String
- 1 mark for Price: Real / Decimal / Currency / Single / Double
(b) 2 marks:
- 1 mark for identifying that it displays Title and Price of books that are in stock
- 1 mark for identifying that it is sorted in descending order of Price (highest to lowest)
题目 3 · Short Answer
4
A registration program requires a user to enter their age and a newly created password. The rules for the inputs are:
- The age must be a whole number between 13 and 120 inclusive.
- The password must not be empty and must be entered twice to ensure it was typed correctly.

(a) Identify two different validation checks that should be performed on the age input.
(b) Identify and describe the verification check used to ensure the password has been entered without typing errors.
查看答案详解

解题

(a) A Range check verifies if the age is between 13 and 120. A Type check checks that the entered value is an integer/whole number.
(b) The verification technique is Double-entry. The system requests the password twice and compares the entries to verify they are identical, which ensures no typing errors were made.

评分标准

(a) 2 marks:
- 1 mark for: Range check
- 1 mark for: Type check / Character check / Format check
(b) 2 marks:
- 1 mark for: identifying Double-entry check
- 1 mark for: explaining that the two entered passwords are compared to ensure they match
题目 4 · Short Answer
4
A programmer needs to write a pseudocode algorithm that appends the text stored in a variable `NewEntry` to an existing sequential file named `history.txt`.
Describe the four essential steps, in the correct order, that the algorithm must perform to successfully append the data and ensure it is saved.
查看答案详解

解题

The logical sequence for file writing is:
1. Open the file in the correct mode (APPEND or WRITE).
2. Fetch the text to be added.
3. Write the value of the variable into the file.
4. Close the file to commit the changes and free the system resource.

评分标准

4 marks for the four steps described in the correct chronological order:
- 1 mark for: Open `history.txt`
- 1 mark for: Specifying append mode / write mode
- 1 mark for: Writing/appending the variable `NewEntry` to the file
- 1 mark for: Closing the file `history.txt`
题目 5 · Short Answer
4
Consider this segment of pseudocode:

```text
01 Total <- 0
02 Counter <- 0
03 REPEAT
04 INPUT Value
05 IF Value > 100
06 THEN
07 Total <- Total + Value
08 Counter <- Counter + 1
09 ENDIF
10 UNTIL Counter = 5
```

(a) Identify the type of loop used in this pseudocode.
(b) State the purpose of the statement on line 08.
(c) Explain what would happen if the user inputs five numbers that are all less than 100.
查看答案详解

解题

(a) The loop is controlled by a condition evaluated at the end: `REPEAT...UNTIL`, which is a post-condition loop.
(b) Line 08 increments `Counter` by 1. Its purpose is to count the number of values inputted that are greater than 100.
(c) Since all five inputs are less than 100, the condition on line 05 is never true. Line 08 is never executed. `Counter` remains 0, meaning the termination condition `Counter = 5` is never satisfied, resulting in an infinite loop.

评分标准

(a) 1 mark:
- Post-condition loop // REPEAT...UNTIL loop
(b) 1 mark:
- Increments the loop counter / tracks the number of inputs greater than 100
(c) 2 marks:
- 1 mark for: loop runs infinitely / never terminates / continues to ask for input
- 1 mark for: Counter is never incremented (remains 0) because the IF condition `Value > 100` is never met
题目 6 · Short Answer
4
A programmer is writing a program and needs to decide whether to use a procedure or a function for two different tasks.
- Task 1: Calculate and return the area of a circle given its radius.
- Task 2: Display a menu of options on the screen.

(a) Identify the most appropriate subroutine type (procedure or function) for:
(i) Task 1
(ii) Task 2
(b) State two general differences between a procedure and a function.
查看答案详解

解题

(a) (i) Task 1 needs to calculate and pass back a single value (area), which is the role of a Function.
(ii) Task 2 executes a set of instructions (displaying text) but does not return a value, which is appropriate for a Procedure.
(b) Functions must return a value, can be used in expressions, and typically do not change global variables, whereas procedures perform tasks without returning a value and are called independently.

评分标准

(a) 2 marks:
- 1 mark for (i) Function
- 1 mark for (ii) Procedure
(b) 2 marks for any two of:
- A function must return a value // a procedure does not return a value
- A function is called as part of an expression/assignment // a procedure is called as a standalone instruction
- A function has a return data type defined // a procedure does not
题目 7 · Trace Table
7
An algorithm is represented by the following pseudocode. The array `List[1:6]` contains the values: `[12, 5, 8, 12, 3, 15]`.

```
01 Count <- 0
02 Index <- 1
03 Limit <- 6
04 Target <- 10
05 REPEAT
06 IF List[Index] > Target THEN
07 List[Index] <- List[Index] - 5
08 Count <- Count + 1
09 ELSE
10 List[Index] <- List[Index] + 2
11 ENDIF
12 Index <- Index + 1
13 UNTIL Index > Limit
14 OUTPUT Count
```

Complete the trace table for this algorithm.

| Count | Index | List[1] | List[2] | List[3] | List[4] | List[5] | List[6] | OUTPUT |
| :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: |
| | | 12 | 5 | 8 | 12 | 3 | 15 | |
| | | | | | | | | |
查看答案详解

解题

Let's trace the execution of the algorithm step-by-step:

- **Initialization (Lines 01-04):**
- `Count <- 0`
- `Index <- 1`
- `Limit <- 6`
- `Target <- 10`

- **First iteration (Index = 1):**
- `List[1]` is 12. Since \(12 > 10\), the `IF` condition is true.
- `List[1] <- 12 - 5 = 7`
- `Count <- 0 + 1 = 1`
- `Index <- 1 + 1 = 2`
- Condition `Index > Limit` (\(2 > 6\)) is false, loop continues.

- **Second iteration (Index = 2):**
- `List[2]` is 5. Since \(5 > 10\) is false, the `ELSE` branch executes.
- `List[2] <- 5 + 2 = 7`
- `Index <- 2 + 1 = 3`
- Condition `Index > Limit` (\(3 > 6\)) is false, loop continues.

- **Third iteration (Index = 3):**
- `List[3]` is 8. Since \(8 > 10\) is false, the `ELSE` branch executes.
- `List[3] <- 8 + 2 = 10`
- `Index <- 3 + 1 = 4`
- Condition `Index > Limit` (\(4 > 6\)) is false, loop continues.

- **Fourth iteration (Index = 4):**
- `List[4]` is 12. Since \(12 > 10\) is true.
- `List[4] <- 12 - 5 = 7`
- `Count <- 1 + 1 = 2`
- `Index <- 4 + 1 = 5`
- Condition `Index > Limit` (\(5 > 6\)) is false, loop continues.

- **Fifth iteration (Index = 5):**
- `List[5]` is 3. Since \(3 > 10\) is false, `ELSE` executes.
- `List[5] <- 3 + 2 = 5`
- `Index <- 5 + 1 = 6`
- Condition `Index > Limit` (\(6 > 6\)) is false, loop continues.

- **Sixth iteration (Index = 6):**
- `List[6]` is 15. Since \(15 > 10\) is true.
- `List[6] <- 15 - 5 = 10`
- `Count <- 2 + 1 = 3`
- `Index <- 6 + 1 = 7`
- Condition `Index > Limit` (\(7 > 6\)) is true, loop terminates.

- **Output (Line 14):**
- Outputs `Count` which contains the value 3.

评分标准

Award marks according to the following guidelines (up to a maximum of 7 marks):
- **1 mark** for initial values of Count (0) and Index (1) correctly written on the first row.
- **1 mark** for correct updates to List[1] (7) and Count (1) in the first iteration.
- **1 mark** for correct updates to List[2] (7) and List[3] (10) across respective iterations.
- **1 mark** for correct update to List[4] (7) and Count (2).
- **1 mark** for correct updates to List[5] (5) and List[6] (10) and Count (3).
- **1 mark** for correct tracking of Index incrementing sequentially up to 7.
- **1 mark** for correct final OUTPUT of 3.
题目 8 · Trace Table
7
A program contains the following algorithm designed to process two numerical values:

```
01 A <- 4
02 B <- 15
03 C <- 0
04 WHILE B > A DO
05 IF B MOD 2 = 0 THEN
06 B <- B - 3
07 C <- C + A
08 ELSE
09 B <- B - 1
10 A <- A + 1
11 ENDIF
12 ENDWHILE
13 OUTPUT A, B, C
```

Complete the trace table for this algorithm. Show the state of variables after each change.

| A | B | C | OUTPUT |
| :---: | :---: | :---: | :---: |
| | | | |
查看答案详解

解题

Let's perform a dry run of the loop:

- **Initialization (Lines 01-03):**
- `A <- 4`
- `B <- 15`
- `C <- 0`

- **Loop Condition Check (Line 04):** Is \(B > A\)? \(15 > 4\) (True). Loop begins.

- **Iteration 1:**
- `B MOD 2 = 0`? \(15 \text{ MOD } 2 = 1\) (False). `ELSE` branch executes.
- `B <- 15 - 1 = 14`
- `A <- 4 + 1 = 5`

- **Iteration 2:**
- Is \(B > A\)? \(14 > 5\) (True).
- `B MOD 2 = 0`? \(14 \text{ MOD } 2 = 0\) (True). `IF` branch executes.
- `B <- 14 - 3 = 11`
- `C <- 0 + 5 = 5`

- **Iteration 3:**
- Is \(B > A\)? \(11 > 5\) (True).
- `B MOD 2 = 0`? \(11 \text{ MOD } 2 = 1\) (False). `ELSE` branch executes.
- `B <- 11 - 1 = 10`
- `A <- 5 + 1 = 6`

- **Iteration 4:**
- Is \(B > A\)? \(10 > 6\) (True).
- `B MOD 2 = 0`? \(10 \text{ MOD } 2 = 0\) (True). `IF` branch executes.
- `B <- 10 - 3 = 7`
- `C <- 5 + 6 = 11`

- **Iteration 5:**
- Is \(B > A\)? \(7 > 6\) (True).
- `B MOD 2 = 0`? \(7 \text{ MOD } 2 = 1\) (False). `ELSE` branch executes.
- `B <- 7 - 1 = 6`
- `A <- 6 + 1 = 7`

- **Loop Termination Check:** Is \(B > A\)? \(6 > 7\) (False). Loop terminates.

- **Output (Line 13):** Outputs `A, B, C` which translates to `7, 6, 11`.

评分标准

Award marks according to the following guidelines (up to a maximum of 7 marks):
- **1 mark** for correct initial values of A (4), B (15), C (0).
- **1 mark** for the first state change showing B = 14 and A = 5.
- **1 mark** for the second state change showing B = 11 and C = 5.
- **1 mark** for the third state change showing B = 10 and A = 6.
- **1 mark** for the fourth state change showing B = 7 and C = 11.
- **1 mark** for the fifth state change showing B = 6 and A = 7.
- **1 mark** for the correct final output: `7, 6, 11` (all three values required).
题目 9 · Extended Programming Project
15
A library management program utilizes a two-dimensional (2D) array `BookCatalog[]` to store the title and author of each book.

Another 2D array, `RentalStatus[]`, contains details regarding the rental state of each book:
* column one stores the availability status (0 for available, 1 for borrowed)
* column two stores the Member ID of the borrower (0 if the book is currently available)
* column three stores the daily rental cost in dollars, for example 1.50

The internal Book ID serves as the row index for both arrays. For example, Book ID 15's details would be stored in:
`BookCatalog[15,1]` and `BookCatalog[15,2]`
`RentalStatus[15,1]`, `RentalStatus[15,2]` and `RentalStatus[15,3]`

The variable `CatalogSize` contains the total number of books in the library's catalog.

The arrays and the variable `CatalogSize` have already been set up and the data has been stored.

Write a program that meets the following requirements:
* checks if a Book ID entered by the user exists in the catalog before any action can take place
* displays a menu showing the four actions available for the user to choose from:
1. display book details and status
2. borrow book
3. return book
4. exit
* allows an action to be chosen and completed. Each action must be completed by a procedure with a parameter of the Book ID.

You must use pseudocode or program code and add comments to explain how your code works. All inputs and outputs must contain suitable messages.

You only need to declare any local arrays and local variables that you use.

You do not need to declare and initialise the data in the global arrays `BookCatalog[]` and `RentalStatus[]` and the variable `CatalogSize`.
查看答案详解

解题

Below is an example solution written in pseudocode:

```
// Procedure to display details of a selected book
PROCEDURE DisplayBook(BookID : INTEGER)
OUTPUT "Book Title: ", BookCatalog[BookID, 1]
OUTPUT "Author: ", BookCatalog[BookID, 2]
IF RentalStatus[BookID, 1] = 0 THEN
OUTPUT "Availability: Available"
ELSE
OUTPUT "Availability: Borrowed by Member ID ", RentalStatus[BookID, 2]
ENDIF
OUTPUT "Daily Rental Fee: $", RentalStatus[BookID, 3]
ENDPROCEDURE

// Procedure to borrow a book
PROCEDURE BorrowBook(BookID : INTEGER)
DECLARE MemberID : INTEGER
// Check if book is already borrowed
IF RentalStatus[BookID, 1] = 1 THEN
OUTPUT "Error: This book is already rented."
ELSE
// Loop to ensure a valid positive Member ID is supplied
REPEAT
OUTPUT "Enter Member ID: "
INPUT MemberID
UNTIL MemberID > 0

// Update book rental details
RentalStatus[BookID, 1] <-- 1
RentalStatus[BookID, 2] <-- MemberID
OUTPUT "Book successfully rented to Member: ", MemberID
ENDIF
ENDPROCEDURE

// Procedure to return a book and compute the charge
PROCEDURE ReturnBook(BookID : INTEGER)
DECLARE RentalDays : INTEGER
DECLARE TotalCharge : REAL
// Check if book is currently borrowed
IF RentalStatus[BookID, 1] = 0 THEN
OUTPUT "Error: This book is not currently rented."
ELSE
// Loop to obtain a valid positive rental duration
REPEAT
OUTPUT "Enter the number of days the book was rented: "
INPUT RentalDays
UNTIL RentalDays > 0

// Calculate and display total charges
TotalCharge <-- RentalDays * RentalStatus[BookID, 3]
OUTPUT "The total rental charge is: $", TotalCharge

// Reset status indicators
RentalStatus[BookID, 1] <-- 0
RentalStatus[BookID, 2] <-- 0
OUTPUT "Book successfully returned and updated."
ENDIF
ENDPROCEDURE

// Main Program Execution
DECLARE SelectedID, Choice : INTEGER
DECLARE ValidID : BOOLEAN

// 1. Check if Book ID exists
REPEAT
OUTPUT "Please enter a Book ID (1 to ", CatalogSize, "): "
INPUT SelectedID
IF SelectedID >= 1 AND SelectedID <= CatalogSize THEN
ValidID <-- TRUE
ELSE
OUTPUT "Error: Invalid Book ID. Please try again."
ValidID <-- FALSE
ENDIF
UNTIL ValidID = TRUE

// 2. Display menu and handle actions
REPEAT
OUTPUT "*** LIBRARY SYSTEM MENU ***"
OUTPUT "1. Display Book Details"
OUTPUT "2. Borrow Book"
OUTPUT "3. Return Book"
OUTPUT "4. Exit"
OUTPUT "Please select your choice (1-4): "
INPUT Choice

CASE Choice OF
1 : CALL DisplayBook(SelectedID)
2 : CALL BorrowBook(SelectedID)
3 : CALL ReturnBook(SelectedID)
4 : OUTPUT "Exiting library system. Goodbye."
OTHERWISE OUTPUT "Invalid choice. Please select from 1-4."
ENDCASE
UNTIL Choice = 4
```

评分标准

### AO2: Apply knowledge and understanding (Max 9 marks)

#### Band 1 (1–3 Marks)
* At least one programming technique (such as selection, iteration, or input/output) has been used.
* Data structures have been referenced, but not fully or appropriately for all operations.

#### Band 2 (4–6 Marks)
* Some programming techniques used are appropriate to the problem.
* More than one technique (such as range validation on input and menu loop) is applied correctly.
* Data structures chosen are appropriate and store/retrieve some of the necessary data correctly.

#### Band 3 (7–9 Marks)
* The full range of programming techniques is applied effectively to cover all scenario requirements.
* Book ID existence validation is successfully implemented.
* A menu system with selection (e.g. `CASE` or nested `IF`) is fully integrated.
* Procedures with the parameters are declared and used correctly to perform tasks.
* Array operations correctly inspect and update data inside `RentalStatus[]`.

---

### AO3: Provide solutions to problems (Max 6 marks)

#### Band 1 (1–2 Marks)
* Code is presented with limited or missing comments.
* Variable and procedure identifiers are partially appropriate but may lack clarity.
* The program logic is partially correct but contains several inaccuracies.

#### Band 2 (3–4 Marks)
* The program contains some relevant comments explaining key sections.
* The majority of identifier names are meaningful and appropriate to their purpose.
* The solution contains parts that are illogical or inaccurate but achieves most requirements.

#### Band 3 (5–6 Marks)
* The program is logically ordered, clean, and fully commented.
* Highly suitable identifiers are used throughout.
* The solution is accurate and performs all tasks effectively as described in the scenario (validating Book ID, processing borrow updates, calculating daily charges, resetting values upon return).

想知道自己有几分把握?

thinka 是 DSE 学生在用的 AI 练习应用,提供无限量练习题、即时自动批改和详细解题步骤。超过 100,000 名学生用它确认自己是真的会,而不只是「以为会」。

想练更多同类题型?在 thinka 无限量刷题,即时知道答案。

免费开始练习