Cambridge IGCSE · Thinka 原創模擬試題

2024 Cambridge IGCSE Computer Science (0478) 模擬試題連答案詳解

Thinka Nov 2024 (V2) Cambridge International A Level-Style Mock — Computer Science (0478)

150 210 分鐘2024
An original Thinka practice paper modelled on the structure and difficulty of the Nov 2024 (V2) Cambridge International A Level Computer Science (0478) paper. Not affiliated with or reproduced from Cambridge.

卷一 Computer Systems

Answer all questions. Calculators must not be used. Total mark is 75.
28 題目 · 74.49999999999997
題目 1 · Short Answer Theory
2.2
A network engineer is configuring an IPv6 address sub-segment and needs to convert the hexadecimal value C4 to both binary and denary. State the 8-bit binary and denary values for C4.
查看答案詳解

解題

Hexadecimal C is 12 in denary, which corresponds to 1100 in 4-bit binary. Hexadecimal 4 is 4 in denary, which corresponds to 0100 in 4-bit binary. Combining these yields the 8-bit binary value 11000100. To find the denary value: \(12 \times 16 + 4 = 192 + 4 = 196\).

評分準則

1 mark for the correct 8-bit binary value (11000100). 1.2 marks for the correct denary value (196).
題目 2 · Short Answer Theory
2.2
Explain why a high-definition video stream from a computer to a monitor typically uses parallel data transmission rather than serial data transmission.
查看答案詳解

解題

Parallel transmission sends multiple bits of data simultaneously over multiple physical wires, whereas serial transmission sends one bit at a time over a single wire. High-definition video streams contain a large volume of data that must be transferred with very low latency, requiring the higher bandwidth/throughput offered by parallel transmission over short distances.

評分準則

1 mark for identifying that multiple bits are sent simultaneously over multiple wires. 1.2 marks for explaining that this provides the higher bandwidth / faster transfer speed necessary for large volumes of high-definition video data.
題目 3 · Short Answer Theory
2.2
Explain how a checksum is used to detect errors during data transmission.
查看答案詳解

解題

Before transmission, the sender runs an algorithm on the data payload to calculate a numerical checksum, which is appended to the transmission. On receipt, the receiver executes the identical algorithm on the received payload and compares the result to the transmitted checksum. If the two values do not match, an error has occurred during transmission.

評分準則

1 mark for stating the sender calculates and transmits a checksum with the data. 1.2 marks for stating the receiver recalculates the checksum and compares it, indicating an error if they do not match.
題目 4 · Short Answer Theory
2.2
Describe the purpose of the Program Counter (PC) register in the CPU during the fetch-decode-execute cycle.
查看答案詳解

解題

The Program Counter (PC) holds the address of the next instruction that needs to be fetched from memory. Once this address is copied to the Memory Address Register (MAR) during the fetch stage, the PC is immediately incremented by one so that it points to the memory location of the next sequential instruction.

評分準則

1 mark for explaining that it holds the memory address of the next instruction to be fetched. 1.2 marks for stating that it increments (adds 1) once the address is sent to the MAR.
題目 5 · Short Answer Theory
2.2
State two different scenarios that would cause a hardware interrupt to be sent to the CPU.
查看答案詳解

解題

Hardware interrupts are physical signals sent from external hardware devices to notify the CPU that they require attention. Common examples include a printer flagging that it has run out of paper or is jammed, or input peripherals like a keyboard sending a signal when a key is pressed by the user.

評分準則

1.1 marks for each correct, distinct hardware interrupt scenario (maximum 2.2 marks). Acceptable answers include: keyboard keypress, mouse movement, printer paper jam/out of paper, storage drive ready/error. Reject software-based interrupts like division by zero.
題目 6 · Short Answer Theory
2.2
A student claims that a MAC address and an IP address are the same because they both uniquely identify a computer. Explain why this claim is incorrect by contrasting their primary purposes.
查看答案詳解

解題

The student is incorrect because a MAC address (Media Access Control) is a physical, permanent, and unique identifier assigned to a network interface card (NIC) by the manufacturer, which does not change. In contrast, an IP (Internet Protocol) address is a logical, temporary address assigned to a device by a router or ISP, which changes whenever the device connects to a different network.

評分準則

1.1 marks for explaining that a MAC address is physical, permanent, and hardcoded by the manufacturer. 1.1 marks for explaining that an IP address is logical, temporary, and depends on the device's current network location.
題目 7 · Short Answer Theory
2.2
Explain the primary difference between symmetric encryption and asymmetric encryption.
查看答案詳解

解題

Symmetric encryption relies on a single secret key that must be shared between the sender and receiver to both encrypt and decrypt the plaintext message. Asymmetric encryption overcomes the key-distribution problem by using a key-pair: a public key, which anyone can use to encrypt data, and a private key, which is kept secret by the owner and is the only key capable of decrypting that data.

評分準則

1.1 marks for explaining that symmetric encryption uses the same/single key for both processes. 1.1 marks for explaining that asymmetric encryption uses a public key for encryption and a different, private key for decryption.
題目 8 · Short Answer Theory
2.2
A logic circuit has two inputs, A and B. It outputs 1 only when both inputs are different. Identify the single logic gate that performs this function, and state its output when A = 1 and B = 1.
查看答案詳解

解題

An Exclusive OR (XOR) gate outputs a high signal (1) only when its two input signals differ from each other (i.e., one is 0 and the other is 1). If both inputs are identical, such as when A = 1 and B = 1, the XOR gate outputs a low signal (0).

評分準則

1 mark for identifying the logic gate as XOR. 1.2 marks for stating the output is 0 (or False) when both inputs are 1.
題目 9 · short_answer
2.2
Identify two benefits to a computer programmer of representing binary values as hexadecimal values.
查看答案詳解

解題

Hexadecimal acts as a shorthand notation for binary, where one hexadecimal digit represents exactly 4 bits (a nibble). This significantly reduces the length of the values that a programmer must read, write, or type. As a result, it is much easier to spot errors and debug the system, and the risk of transcription errors (mistyping a 0 or 1) is greatly reduced.

評分準則

Award marks as follows (maximum 2.2 marks):
- 1 mark: State that hexadecimal is shorter, making it easier/faster for humans to read, write, or remember.
- 1 mark: State that it reduces typing/transcription errors or makes debugging easier (e.g., easier to recognize binary patterns).
- 0.2 marks: For a clear technical explanation linking the benefit to binary conversions (e.g., pointing out that 1 hex digit represents 4 bits / a nibble).
題目 10 · short_answer
2.2
Explain why serial data transmission is preferred over parallel data transmission for transmitting data over long distances.
查看答案詳解

解題

In serial transmission, data is sent one bit at a time over a single wire. Parallel transmission sends multiple bits simultaneously over multiple wires. Over long distances, parallel transmission suffers from 'skew' (where bits travel at slightly different speeds and arrive out of sync) and signal degradation (crosstalk). Serial transmission avoids these issues completely and is also much less expensive due to using fewer physical wires.

評分準則

Award marks as follows (maximum 2.2 marks):
- 1 mark: Explaining that serial transmission prevents data skew (bits arriving out of synchronization/order).
- 1 mark: Explaining that serial is cheaper or easier to install over long distances because it requires fewer wires.
- 0.2 marks: Mentioning that serial suffers less from interference/crosstalk over long distances.
題目 11 · short_answer
2.2
Explain the specific role of the Program Counter (PC) register during the fetch stage of the fetch-decode-execute cycle.
查看答案詳解

解題

At the start of the fetch stage, the Program Counter (PC) holds the address of the next instruction that needs to be retrieved from memory. This address is sent to the Memory Address Register (MAR) via the address bus. Once this address copy is complete, the value in the PC is incremented by 1 so that it points to the memory location of the next sequential instruction.

評分準則

Award marks as follows (maximum 2.2 marks):
- 1 mark: Stating that the PC holds the address of the next instruction to be fetched/executed.
- 1 mark: Explaining that this address is copied/sent to the Memory Address Register (MAR).
- 0.2 marks: Explaining that the PC is then incremented (by 1) to prepare for the subsequent cycle.
題目 12 · short_answer
2.2
Explain how a checksum is used to verify that a block of transmitted data has not been corrupted.
查看答案詳解

解題

Before transmission, the sending device applies a specific mathematical algorithm to the data block to produce a numerical checksum. This checksum is appended to the data packet. Upon receipt, the destination device applies the exact same algorithm to the received data block to generate its own checksum. It compares this value with the received checksum. If they match, the data is correct; if they do not match, the data has been corrupted, and a request for retransmission is sent.

評分準則

Award marks as follows (maximum 2.2 marks):
- 1 mark: The sender calculates a checksum from the data block (using an algorithm) and transmits it alongside the data.
- 1 mark: The receiver recalculates the checksum from the received data and compares the two checksum values.
- 0.2 marks: Stating that if the checksums match, the data is accepted, and if they do not match, a retransmission request is initiated.
題目 13 · short_answer
2.2
Describe two key functions performed by a web browser when a user requests and views a website.
查看答案詳解

解題

A web browser has two main functions: first, it acts as a client by sending requests to a web server (using protocols like HTTP or HTTPS) to retrieve HTML files, images, and other resources. Second, it parses, translates, and renders the HTML, CSS, and JavaScript instructions into the visual interface that the user sees on their display.

評分準則

Award marks as follows (maximum 2.2 marks):
- 1 mark: For identifying the function of requesting/retrieving web resources from a web server (using HTTP/HTTPS).
- 1 mark: For identifying the function of translating, interpreting, or rendering HTML/CSS/JavaScript code into a visual page.
- 0.2 marks: For mentioning other browser duties such as handling URLs/DNS requests, storing cookies, or managing user history.
題目 14 · short_answer
2.2
Explain why lossless compression, rather than lossy compression, must be used when compressing a computer program's executable file.
查看答案詳解

解題

An executable file consists of precise machine code instructions. If lossy compression were used, some data would be permanently discarded to reduce the file size. Losing even a single bit of computer code could change instructions or create syntax errors, rendering the program corrupted and unable to run. Lossless compression ensures that the decompressed file is an identical bit-for-bit copy of the original, maintaining the executable's complete instructions.

評分準則

Award marks as follows (maximum 2.2 marks):
- 1 mark: Lossless compression reconstructs the original data exactly with zero data loss.
- 1 mark: Lossy compression permanently deletes/discards data, which would alter or corrupt the program's code/instructions.
- 0.2 marks: Explaining the consequence (e.g., that a corrupted executable file will not run, will crash, or will cause system errors).
題目 15 · Calculation / Representation
2.5
An 8-bit two's complement binary integer is represented as \(10111101_2\). Show the working to convert this representation into its denary value.
查看答案詳解

解題

Method 1: Using column weights.
The column weights for an 8-bit two's complement number are:
\(-128\), \(64\), \(32\), \(16\), \(8\), \(4\), \(2\), \(1\).
Using the bits from \(10111101_2\):
\((-128 \times 1) + (64 \times 0) + (32 \times 1) + (16 \times 1) + (8 \times 1) + (4 \times 1) + (2 \times 0) + (1 \times 1)\)
\(= -128 + 32 + 16 + 8 + 4 + 1\)
\(= -128 + 61\)
\(= -67\)

Method 2: Flip and add 1.
1. Find the magnitude of the negative number by inverting (flipping) all the bits: \(10111101 \rightarrow 01000010\).
2. Add 1 to the inverted value: \(01000010 + 1 = 01000011_2\).
3. Convert this binary value to denary: \(64 + 2 + 1 = 67\).
4. Apply the negative sign to get \(-67\).

評分準則

- 1 mark for correct conversion method (e.g. showing column weights with a negative sign for the MSB, or showing correct bit inversion step to \(01000010\)).
- 1 mark for correct intermediate calculation (e.g. summing positive weights to get \(61\) or adding 1 to get \(01000011\) which represents \(67\)).
- 0.5 marks for the correct final answer: \(-67\).
題目 16 · Calculation / Representation
2.5
Perform a logical shift of three places to the right on the 8-bit binary register containing \(11011000_2\). Convert the resulting binary register into its hexadecimal equivalent. Show your working.
查看答案詳解

解題

1. Perform the logical right shift of three places on the binary string \(11011000_2\):
- Shift 1: \(01101100\)
- Shift 2: \(00110110\)
- Shift 3: \(00011011\)
The resulting binary register is \(00011011_2\).

2. Convert \(00011011_2\) to hexadecimal:
- Split into two 4-bit nibbles: \(0001\) and \(1011\).
- Convert first nibble: \(0001_2 = 1_{16}\).
- Convert second nibble: \(1011_2 = 11_{10} = B_{16}\).
- Combined hexadecimal result is \(1B\).

評分準則

- 1 mark for showing the correct shifted binary value: \(00011011\).
- 1 mark for showing the correct process of splitting into nibbles and converting to hex digits (e.g. \(0001 \rightarrow 1\) and \(1011 \rightarrow B\)).
- 0.5 marks for the correct final hexadecimal answer: \(1B\) (or \(1B_{16}\)).
題目 17 · Calculation / Representation
2.5
A digital image has a resolution of \(512 \times 256\) pixels and a colour depth of 24 bits per pixel. Calculate the file size of this image in kibibytes (KiB). Show all your working.
查看答案詳解

解題

1. Calculate total number of pixels:
\(512 \times 256 = 131,072\) pixels.

2. Calculate the file size in bits:
\(131,072 \text{ pixels} \times 24 \text{ bits/pixel} = 3,145,728\) bits.

3. Convert bits to bytes (divide by 8):
\(3,145,728 / 8 = 393,216\) bytes.
Alternatively, 24 bits = 3 bytes. Total bytes = \(512 \times 256 \times 3 = 131,072 \times 3 = 393,216\) bytes.

4. Convert bytes to KiB (divide by 1024):
\(393,216 / 1024 = 384\) KiB.

Alternative powers-of-two method:
- \(512 = 2^9\)
- \(256 = 2^8\)
- \(24 \text{ bits} = 3 \text{ bytes}\)
- Total bytes = \(2^9 \times 2^8 \times 3 = 3 \times 2^{17}\) bytes.
- Size in KiB = \((3 \times 2^{17}) / 2^{10} = 3 \times 2^7 = 3 \times 128 = 384\) KiB.

評分準則

- 1 mark for correct method to calculate the total size in bytes (e.g., \(512 \times 256 \times 3\) or \(512 \times 256 \times 24 / 8\)).
- 1 mark for correctly dividing the byte total by 1024 to convert to KiB.
- 0.5 marks for the correct final answer: \(384\) (or \(384 \text{ KiB}\)).
題目 18 · Calculation / Representation
2.5
A mono (single channel) sound recording is made with a sample rate of \(44,100 \text{ Hz}\) and a sample resolution of 16 bits. The recording lasts for 20 seconds. Calculate the file size of this sound recording in megabytes (MB). Show your working. Use denary approximations (e.g., \(1 \text{ kB} = 1000 \text{ bytes}\), \(1 \text{ MB} = 1,000,000 \text{ bytes}\)).
查看答案詳解

解題

1. Calculate the file size in bits:
\(\text{Size} = \text{sample rate} \times \text{sample resolution} \times \text{time (seconds)} \times \text{channels}\)
\(\text{Size} = 44,100 \times 16 \times 20 \times 1 = 14,112,000\) bits.

2. Convert bits to bytes (divide by 8):
\(14,112,000 / 8 = 1,764,000\) bytes.
(Alternatively: 16 bits = 2 bytes. Total bytes = \(44,100 \times 2 \times 20 = 1,764,000\) bytes).

3. Convert bytes to megabytes (MB) using denary approximation (divide by 1,000,000):
\(1,764,000 / 1,000,000 = 1.764\) MB.

評分準則

- 1 mark for correct method to calculate total bytes (e.g., \(44,100 \times 2 \times 20 = 1,764,000\) bytes).
- 1 mark for correct base-10 conversion from bytes to MB (dividing by 1,000,000).
- 0.5 marks for correct final answer: \(1.764\) (or \(1.764 \text{ MB}\)).
題目 19 · Calculation / Representation
2.5
A computer graphics application represents a colour using the hexadecimal code `#A3C2F1`. Convert the middle hexadecimal value, `C2`, into its denary representation. Show all your working.
查看答案詳解

解題

1. Split the hexadecimal number `C2` into its constituent digits: `C` and `2`.
2. Determine the place values: the left digit has a place value of 16, and the right digit has a place value of 1.
3. Convert the hexadecimal character `C` to its denary equivalent: `C` in hex is equal to 12 in denary.
4. Multiply each digit by its place value and sum the results:
\((12 \times 16) + (2 \times 1) = 192 + 2 = 194\).

評分準則

- 1 mark for identifying the denary value of hex digit `C` as 12 and multiplying it by 16.
- 1 mark for adding the units digit (2) to the product.
- 0.5 marks for the correct final answer: 194.
題目 20 · Calculation / Representation
2.5
In a transmission using odd parity for both rows and columns (parity block), the following table of bits was received:
Row 1: 1 0 1 0 1 0 1 1
Row 2: 0 1 1 0 0 0 1 1
Row 3: 1 1 0 0 1 1 1 0
Row 4 (Parity Row): 1 1 1 0 1 0 0 1
Identify the coordinate (Row number and Column number, counting from Left-to-Right starting at Column 1) of the single bit that has been corrupted during transmission. Show how you determined this.
查看答案詳解

解題

1. Check the parity of each row (must contain an odd number of 1s):
- Row 1: five 1s (Odd - OK)
- Row 2: four 1s (Even - Error!)
- Row 3: five 1s (Odd - OK)
- Row 4: five 1s (Odd - OK)
This shows the error is in Row 2.

2. Check the parity of each column (must contain an odd number of 1s):
- Column 1: three 1s (Odd - OK)
- Column 2: three 1s (Odd - OK)
- Column 3: three 1s (Odd - OK)
- Column 4: zero 1s (Even - Error!)
- Column 5: three 1s (Odd - OK)
- Column 6: one 1 (Odd - OK)
- Column 7: three 1s (Odd - OK)
- Column 8: three 1s (Odd - OK)
This shows the error is in Column 4.

3. The intersection of Row 2 and Column 4 indicates the corrupted bit.

評分準則

- 1 mark for identifying Row 2 has incorrect parity (even number of 1s / 4 ones).
- 1 mark for identifying Column 4 has incorrect parity (even number of 1s / 0 ones).
- 0.5 marks for the correct final coordinate: Row 2, Column 4 (accept: Row 2 Col 4).
題目 21 · Calculation / Representation
2.5
Convert the negative denary integer \(-83\) into an 8-bit two's complement binary number. Show your working.
查看答案詳解

解題

Method 1: Two's complement inversion.
1. Represent positive 83 as an 8-bit binary number:
\(83 = 64 + 16 + 2 + 1 = 01010011_2\).
2. Invert all bits (one's complement):
\(01010011 \rightarrow 10101100\).
3. Add 1 to the result:
\(10101100 + 1 = 10101101_2\).

Method 2: Column subtraction.
1. The MSB weight is \(-128\).
2. Calculate the difference: \(-83 - (-128) = 45\).
3. Represent 45 in the remaining positive weights (64, 32, 16, 8, 4, 2, 1):
\(45 = 32 + 8 + 4 + 1 = 0101101_2\).
4. Combine: \(1\) for the \(-128\) weight followed by \(0101101_2\) to get \(10101101\).

評分準則

- 1 mark for correctly representing positive 83 in binary (\(01010011\)) or calculating the required positive offset from \(-128\) (which is \(45\)).
- 1 mark for inverting all bits of the positive representation to get \(10101100\), or correctly converting \(45\) to binary (\(0101101\)).
- 0.5 marks for the correct final answer: \(10101101\).
題目 22 · Calculation / Representation
2.5
A company uses a 4-digit product ID code, where the first three digits are the data digits and the fourth digit is a check digit calculated using the following algorithm:
- Multiply the 1st digit by 4
- Multiply the 2nd digit by 3
- Multiply the 3rd digit by 2
- Sum these products
- Divide the sum by 10 and find the remainder
- The check digit is 10 minus this remainder (if the remainder is 0, the check digit is 0)
Calculate the check digit for the product code with data digits: `7 5 8`.
查看答案詳解

解題

1. Apply weights to each of the data digits:
- 1st digit: \(7 \times 4 = 28\)
- 2nd digit: \(5 \times 3 = 15\)
- 3rd digit: \(8 \times 2 = 16\)

2. Sum the products:
\(28 + 15 + 16 = 59\)

3. Divide by 10 to find the remainder:
\(59 / 10 = 5\) remainder \(9\).

4. Subtract the remainder from 10 to find the check digit:
\(10 - 9 = 1\).

評分準則

- 1 mark for correctly multiplying and summing the values: \(28 + 15 + 16 = 59\).
- 1 mark for correctly calculating the remainder and applying the subtraction: \(59 \bmod 10 = 9\), then \(10 - 9 = 1\).
- 0.5 marks for the correct final check digit: \(1\).
題目 23 · Diagram / Table
5.3
A logic circuit has three inputs (A, B, C) and two outputs/intermediates (X, Y). The system is represented by the following logic expressions: X = A AND NOT B; Y = X OR C. Complete the table by identifying the binary values (0 or 1) for the missing entries labeled (i), (ii), (iii), (iv), and (v). ABCXY001(i)10100(ii)100(iii)(iv)1100(v)
查看答案詳解

解題

Let's compute each entry step-by-step: 1) For (i), inputs are A=0, B=0, C=1. Formula for X is A AND NOT B. Here X = 0 AND NOT 0 = 0 AND 1 = 0. So (i) = 0. 2) For (ii), inputs are A=0, B=1, C=0. Formula for Y is X OR C. We are given X=0, so Y = 0 OR 0 = 0. So (ii) = 0. 3) For (iii) and (iv), inputs are A=1, B=0, C=0. Formula for X is A AND NOT B, so X = 1 AND NOT 0 = 1 AND 1 = 1. Thus (iii) = 1. Formula for Y is X OR C, so Y = 1 OR 0 = 1. Thus (iv) = 1. 4) For (v), inputs are A=1, B=1, C=0. Formula for Y is X OR C. We are given X=0, so Y = 0 OR 0 = 0. Thus (v) = 0.

評分準則

Award 1 mark for each correct identification of (i) to (v) (up to 5 marks). Award 0.3 marks for demonstrating logic calculations for at least two rows.
題目 24 · Diagram / Table
5.3
A block of data containing 4 bytes is transmitted using even parity, with an additional parity byte (Row 5) sent at the end of the block. During transmission, some bits are obscured. Complete the table by determining the binary values (0 or 1) for the missing bits labeled (i), (ii), (iii), (iv), and (v). Byte/RowBit 1Bit 2Bit 3Bit 4Bit 5Bit 6Bit 7Bit 8 (Parity)Byte 11011010(i)Byte 201(ii)01111Byte 31101(iii)100Byte 40011101(iv)Parity Byte (Row 5)00110(v)01
查看答案詳解

解題

We use Even Parity, meaning every row and every column must contain an even number of '1' bits. 1) For (i) in Byte 1: The row bits are 1, 0, 1, 1, 0, 1, 0. There are 4 '1's, which is already even. Thus, (i) must be 0. 2) For (ii) in Col 3: The bits are Row 1 (1), Row 2 (ii), Row 3 (0), Row 4 (1), Parity Row (1). The sum of '1's excluding (ii) is 1+0+1+1 = 3 (odd). Thus, (ii) must be 1 to make it even. 3) For (iii) in Col 5: The bits are Row 1 (0), Row 2 (1), Row 3 (iii), Row 4 (1), Parity Row (0). The sum of '1's excluding (iii) is 0+1+1+0 = 2 (even). Thus, (iii) must be 0. 4) For (iv) in Byte 4: The row bits are 0, 0, 1, 1, 1, 0, 1. There are 4 '1's, which is already even. Thus, (iv) must be 0. 5) For (v) in Col 6: The bits are Row 1 (1), Row 2 (1), Row 3 (1), Row 4 (0), Parity Row (v). The sum of '1's excluding (v) is 1+1+1+0 = 3 (odd). Thus, (v) must be 1 to make it even.

評分準則

Award 1 mark for each correct bit value for (i) to (v) (up to 5 marks total). Award 0.3 marks for showing a clear 2D parity analysis methodology.
題目 25 · Diagram / Table
5.3
Match each CPU component on the left with its correct description on the right. Write the letter (J, K, L, M, or N) in the space provided (i) to (v). CPU ComponentLabelDescriptionLetterProgram Counter (PC)(i)Description J: Decodes instructions and coordinates the flow of data within the CPU.JMemory Address Register (MAR)(ii)Description K: Stores the memory address of the next instruction to be fetched.KMemory Data Register (MDR)(iii)Description L: Holds the address of the memory location currently being read from or written to.LAccumulator (ACC)(iv)Description M: Temporarily holds data or instructions fetched from memory or waiting to be written.MControl Unit (CU)(v)Description N: Temporarily stores the results of arithmetic and logical operations.N
查看答案詳解

解題

1) Program Counter (PC) stores the memory address of the next instruction to be fetched, matching Description K. So (i) = K. 2) Memory Address Register (MAR) holds the address of the memory location currently being read from or written to, matching Description L. So (ii) = L. 3) Memory Data Register (MDR) temporarily holds data or instructions fetched from memory or waiting to be written, matching Description M. So (iii) = M. 4) Accumulator (ACC) temporarily stores the results of arithmetic and logical operations, matching Description N. So (iv) = N. 5) Control Unit (CU) decodes instructions and coordinates the flow of data within the CPU, matching Description J. So (v) = J.

評分準則

Award 1 mark for each correct matching label (i) to (v) (up to 5 marks total). Award 0.3 marks for correct completion of all register associations with no errors.
題目 26 · multiple_choice
2.6
A programmer has a 12-bit binary number representing a measurement: 001111011010. What is the hexadecimal equivalent of this binary value?
  1. A.3CA
  2. B.3DA
  3. C.7DA
  4. D.3D5 verification code block placeholder value if needed but we have valid hex digit values here instead of a placeholder d option value which is 3D5 of course!
查看答案詳解

解題

To convert the 12-bit binary number 001111011010 to hexadecimal, we group it into 4-bit nibbles starting from the right: the first nibble is 1010, which equals 10 in decimal or A in hexadecimal; the second nibble is 1101, which equals 13 in decimal or D in hexadecimal; the third nibble is 0011, which equals 3 in decimal or 3 in hexadecimal. Combining these parts together yields the final value 3DA.

評分準則

1.0 mark for correctly dividing the 12-bit binary number into three 4-bit nibbles. 1.0 mark for converting individual nibbles to their correct hexadecimal equivalents. 0.6 marks for combining them in the correct sequence to obtain 3DA.
題目 27 · multiple_choice
2.6
During the fetch stage of the fetch-decode-execute cycle, the CPU copies an address from the Program Counter (PC) to another register. What is this register, and what is its primary function in this stage?
  1. A.The Memory Data Register (MDR); it holds the instruction that has just been fetched from memory.
  2. B.The Current Instruction Register (CIR); it decodes the instruction currently being executed.
  3. C.The Memory Address Register (MAR); it holds the address of the memory location currently being read from or written to.
  4. D.The Accumulator (ACC); it stores the intermediate results of arithmetic and logic operations.
查看答案詳解

解題

During the fetch stage, the address stored in the Program Counter (PC) represents the next instruction to be fetched. This address is copied via the address bus to the Memory Address Register (MAR), which holds the memory address currently being accessed. Thus, MAR is the correct register, and its function is to hold this address during the read operation.

評分準則

1.6 marks for identifying the correct register as the Memory Address Register (MAR). 1.0 mark for correctly describing its function during the fetch stage.
題目 28 · multiple_choice
2.6
A high-speed industrial printing machine needs to receive large amounts of configuration data from a central computer. The communication must allow data to flow in both directions, but only in one direction at any given time. Additionally, the data is sent one bit at a time over a single wire to prevent skewing over a 15-meter cable distance. Which combination of data transmission methods is being described?
  1. A.Parallel and Half-duplex
  2. B.Serial and Full-duplex
  3. C.Serial and Half-duplex
  4. D.Parallel and Simplex
查看答案詳解

解題

Serial data transmission sends data one bit at a time over a single wire, making it highly reliable over longer distances like 15 meters without the risk of bits falling out of sync (skewing). Half-duplex transmission allows data to travel in both directions but only in one direction at a time. Therefore, the combined method is Serial and Half-duplex.

評分準則

1.3 marks for correctly identifying serial transmission based on the single-wire and distance criteria. 1.3 marks for correctly identifying half-duplex transmission based on the directional flow description.

卷二 Algorithms, Programming and Logic

Answer all questions. Calculators must not be used. Total mark is 75.
19 題目 · 72
題目 1 · Short Answer
2.5
Explain the purpose of stepwise refinement in the design of a computer program.
查看答案詳解

解題

Stepwise refinement involves breaking a complex problem down into smaller, more manageable sub-problems (1 mark). This decomposition continues until each sub-problem represents a single task that can be easily coded (1 mark). This makes the overall system easier to design, test, and maintain (0.5 marks).

評分準則

1 mark for explaining the decomposition of a problem into smaller/simpler parts. 1 mark for stating that refinement continues until tasks can be directly coded. 0.5 marks for stating a benefit (e.g. easier to test, debug, or write).
題目 2 · Short Answer
2.5
Describe the relationship between a primary key and a foreign key in a relational database, and explain why a foreign key is used.
查看答案詳解

解題

A primary key uniquely identifies each record within its own table (1 mark). A foreign key is an attribute in another table that points to this primary key to establish a relationship between the two tables (1 mark). This allows tables to be linked together and helps maintain referential integrity (0.5 marks).

評分準則

1 mark for defining a primary key as a unique identifier. 1 mark for defining a foreign key as a reference to a primary key in another table. 0.5 marks for explaining its purpose (to link tables or maintain referential integrity).
題目 3 · Short Answer
2.5
State two differences between a one-dimensional (1D) array and a two-dimensional (2D) array. Use an example of how each is indexed to support your explanation.
查看答案詳解

解題

A 1D array represents a single row or list of elements (0.5 marks) and uses a single index to locate an item, such as MyArray[5] (0.5 marks). In contrast, a 2D array represents a grid or table with rows and columns (0.5 marks) and requires two indexes to locate an item, representing the row and column coordinates, such as MyArray[3, 4] (1 mark).

評分準則

0.5 marks for describing 1D array as a linear list/row. 0.5 marks for describing 1D indexing with a valid single-index example. 0.5 marks for describing 2D array as a grid/table. 1 mark for describing 2D indexing with a valid two-index example.
題目 4 · Short Answer
2.5
Explain the difference between the operation of an XOR gate and an OR gate, using their outputs for identical inputs.
查看答案詳解

解題

When both inputs are 0, both gates output 0 (0.5 marks). When one input is 1 and the other is 0, both gates output 1 (0.5 marks). The difference is when both inputs are 1 (0.5 marks): the OR gate outputs 1 (0.5 marks), while the XOR gate outputs 0 (0.5 marks).

評分準則

0.5 marks for stating output is 0 for both when both inputs are 0. 0.5 marks for stating output is 1 for both when inputs are different. 0.5 marks for identifying the difference occurs when both inputs are 1. 0.5 marks for stating OR outputs 1 for two 1 inputs. 0.5 marks for stating XOR outputs 0 for two 1 inputs.
題目 5 · Short Answer
2.5
A programmer is writing a program that needs to update an existing text file by adding new data to the end of it, without losing any existing data. Identify the file access mode they must use and describe the steps required to safely complete this operation.
查看答案詳解

解題

The correct file access mode is 'append' (0.5 marks). The steps required are: 1. Open the file in append mode (0.5 marks). 2. Write or append the new data to the end of the file (0.5 marks). 3. Close the file to save changes and free system resources (1 mark).

評分準則

0.5 marks for identifying the 'append' mode. 0.5 marks for opening the file in append mode. 0.5 marks for writing/appending the data. 1 mark for closing the file to save changes.
題目 6 · Short Answer
2.5
Distinguish between validation and verification in the context of user input, giving one distinct example of each.
查看答案詳解

解題

Validation is an automated check conducted by the computer to check if the entered data meets specific rules or is reasonable (0.5 marks), such as a range check to ensure an age is between 11 and 18 (0.5 marks). Verification checks that the data has been entered accurately and matches the original source (0.5 marks), such as requiring the user to type a new password twice to confirm it (1 mark).

評分準則

0.5 marks for definition of validation. 0.5 marks for a valid example of validation. 0.5 marks for definition of verification. 1 mark for a valid example of verification (such as double entry or visual check).
題目 7 · Short Answer
2.5
Describe the difference between a global variable and a local variable in terms of their scope and lifetime within a program.
查看答案詳解

解題

A global variable is declared outside any subroutine, making its scope global (accessible anywhere) (0.5 marks) and its lifetime extends for the entire execution of the program (0.5 marks). A local variable is declared inside a specific subroutine, meaning its scope is limited to that subroutine (0.5 marks) and its lifetime ends when the subroutine finishes execution (1 mark).

評分準則

0.5 marks for global variable scope. 0.5 marks for global variable lifetime. 0.5 marks for local variable scope. 1 mark for local variable lifetime/destruction upon subroutine termination.
題目 8 · Short Answer
2.5
Explain the purpose of a trace table and describe how a programmer would use it to identify a logic error in an algorithm.
查看答案詳解

解題

A trace table is a dry-running tool used to track and record the values of variables as an algorithm executes step-by-step (1 mark). The programmer inputs test data and records variable changes in the table columns (1 mark). By comparing the actual recorded values at each step with the expected outcomes, they can locate exactly where the logic error occurs (0.5 marks).

評分準則

1 mark for explaining what a trace table is (dry run tracking variable values). 1 mark for explaining the process (stepping through line-by-line with test data and updating values). 0.5 marks for explaining how it identifies the error (comparing actual vs expected values to find the exact point of divergence).
題目 9 · Trace Table
4.5
An algorithm is represented by the following pseudocode:

```text
DECLARE Values : ARRAY[1:7] OF INTEGER
Values <- [12, 5, -3, 8, -1, 15, 0]
DECLARE Count, Index, Temp : INTEGER

Count <- 0
FOR Index <- 1 TO 6
IF Values[Index] > Values[Index + 1] THEN
Temp <- Values[Index] - Values[Index + 1]
IF Temp > 5 THEN
Count <- Count + 1
ENDIF
ENDIF
NEXT Index
OUTPUT Count
```

Trace the algorithm and complete the trace table below. Note: cells can remain blank if a value does not change.

| Index | Temp | Count | OUTPUT |
|---|---|---|---|
| | | 0 | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
查看答案詳解

解題

Step-by-step trace of the algorithm:
1. Initialize `Count` to 0.
2. `Index = 1`: `Values[1]` (12) > `Values[2]` (5) is True. `Temp` = 12 - 5 = 7. Since 7 > 5, `Count` becomes 1.
3. `Index = 2`: `Values[2]` (5) > `Values[3]` (-3) is True. `Temp` = 5 - (-3) = 8. Since 8 > 5, `Count` becomes 2.
4. `Index = 3`: `Values[3]` (-3) > `Values[4]` (8) is False. No change to `Temp` or `Count`.
5. `Index = 4`: `Values[4]` (8) > `Values[5]` (-1) is True. `Temp` = 8 - (-1) = 9. Since 9 > 5, `Count` becomes 3.
6. `Index = 5`: `Values[5]` (-1) > `Values[6]` (15) is False. No change to `Temp` or `Count`.
7. `Index = 6`: `Values[6]` (15) > `Values[7]` (0) is True. `Temp` = 15 - 0 = 15. Since 15 > 5, `Count` becomes 4.
8. The loop ends after Index reaches 6.
9. `OUTPUT Count` displays 4.

評分準則

Marking Scheme (Total 4.5 Marks):
- 1 Mark: Correctly tracing all `Index` loop values (1, 2, 3, 4, 5, 6) in sequence.
- 1 Mark: Correctly tracing the calculated values of `Temp` (7, 8, 9, 15) in the correct rows.
- 1 Mark: Correctly updating `Count` (from 0 to 1, then 2, 3, 4) at the correct steps.
- 1 Mark: Correctly showing no changes for `Index = 3` and `Index = 5` (cells left blank or values repeated).
- 0.5 Marks: Correct final output value of 4.
題目 10 · Trace Table
4.5
An algorithm is represented by the following pseudocode:

```text
DECLARE Word : STRING
DECLARE Length, Position, Count : INTEGER
Word <- "CABBAGE"
Length <- 7
Position <- 1
Count <- 0

WHILE Position < Length DO
IF SUBSTRING(Word, Position, 1) = SUBSTRING(Word, Position + 1, 1) THEN
Count <- Count + 1
Position <- Position + 2
ELSE
Position <- Position + 1
ENDIF
ENDWHILE
OUTPUT Count, Position
```

Trace the algorithm and complete the trace table below. Note: `Char1` represents `SUBSTRING(Word, Position, 1)` and `Char2` represents `SUBSTRING(Word, Position + 1, 1)`.

| Position | Count | Char1 | Char2 | OUTPUT |
|---|---|---|---|---|
| 1 | 0 | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
查看答案詳解

解題

Step-by-step trace of the loop:
- Initial state: `Position = 1`, `Count = 0`.
- Iteration 1: `Position = 1` (< 7). `Char1` is "C", `Char2` is "A". They are unequal, so `Position` becomes 2.
- Iteration 2: `Position = 2` (< 7). `Char1` is "A", `Char2` is "B". They are unequal, so `Position` becomes 3.
- Iteration 3: `Position = 3` (< 7). `Char1` is "B", `Char2` is "B". They are equal, so `Count` increases to 1 and `Position` increases by 2 to become 5.
- Iteration 4: `Position = 5` (< 7). `Char1` is "A", `Char2` is "G". They are unequal, so `Position` becomes 6.
- Iteration 5: `Position = 6` (< 7). `Char1` is "G", `Char2` is "E". They are unequal, so `Position` becomes 7.
- Loop Check: `Position = 7` is not less than 7, so loop terminates.
- Output: `Count` (1) and `Position` (7) are output.

評分準則

Marking Scheme (Total 4.5 Marks):
- 1 Mark: Correctly tracing the sequence of `Position` updates (1, 2, 3, 5, 6, 7).
- 1 Mark: Correctly identifying the characters compared (`Char1` and `Char2`) in each step.
- 1 Mark: Correctly incrementing `Count` from 0 to 1 only when `Position` is 3.
- 1 Mark: Correctly ending the loop at `Position = 7` with no further character comparisons.
- 0.5 Marks: Correct final output of '1, 7' (or 1 and 7).
題目 11 · Logic Circuit and Truth Table Diagram
4
An automated greenhouse ventilation system uses three sensors to control a motor (M). The motor is turned on (M = 1) when:
- the temperature is high (T = 1) AND the humidity is low (H = 0)
- OR
- the manual switch is active (S = 1) AND the humidity is low (H = 0).

(a) Write the Boolean logic expression for this system using the input variables T, H, S and the operators AND, OR, NOT. [2 marks]

(b) Complete the output column for M in the truth table below. [2 marks]

| T | H | S | M |
|---|---|---|---|
| 0 | 0 | 0 | |
| 0 | 0 | 1 | |
| 0 | 1 | 0 | |
| 0 | 1 | 1 | |
| 1 | 0 | 0 | |
| 1 | 0 | 1 | |
| 1 | 1 | 0 | |
| 1 | 1 | 1 | |
查看答案詳解

解題

Part (a):
From the system specification, we can formulate two separate conditions that are joined by an OR:
- Condition 1: Temperature is high AND humidity is low: \( T \text{ AND NOT } H \)
- Condition 2: Manual switch is active AND humidity is low: \( S \text{ AND NOT } H \)
Combining these gives: \( M = (T \text{ AND NOT } H) \text{ OR } (S \text{ AND NOT } H) \) (or equivalent simplified forms like \( M = (T \text{ OR } S) \text{ AND NOT } H \)).

Part (b):
Using the expression, we evaluate each row:
- T=0, H=0, S=0: \( M = (0 \text{ AND } 1) \text{ OR } (0 \text{ AND } 1) = 0 \)
- T=0, H=0, S=1: \( M = (0 \text{ AND } 1) \text{ OR } (1 \text{ AND } 1) = 1 \)
- T=0, H=1, S=0: \( M = (0 \text{ AND } 0) \text{ OR } (0 \text{ AND } 0) = 0 \)
- T=0, H=1, S=1: \( M = (0 \text{ AND } 0) \text{ OR } (1 \text{ AND } 0) = 0 \)
- T=1, H=0, S=0: \( M = (1 \text{ AND } 1) \text{ OR } (0 \text{ AND } 1) = 1 \)
- T=1, H=0, S=1: \( M = (1 \text{ AND } 1) \text{ OR } (1 \text{ AND } 1) = 1 \)
- T=1, H=1, S=0: \( M = (1 \text{ AND } 0) \text{ OR } (0 \text{ AND } 0) = 0 \)
- T=1, H=1, S=1: \( M = (1 \text{ AND } 0) \text{ OR } (1 \text{ AND } 0) = 0 \)

評分準則

Part (a): [Total: 2 marks]
- 1 mark for \( T \text{ AND NOT } H \) AND \( S \text{ AND NOT } H \) as separate logic expressions.
- 1 mark for joining the expressions correctly with OR (e.g., \( M = (T \text{ OR } S) \text{ AND NOT } H \) is also fully acceptable).

Part (b): [Total: 2 marks]
- 2 marks for all 8 rows correct.
- 1 mark for 6 or 7 rows correct.
- 0 marks for 5 or fewer rows correct.
題目 12 · Logic Circuit and Truth Table Diagram
4
A logic circuit is represented by the following Boolean expression:

\( Z = \text{NOT}(A \text{ AND } B) \text{ AND } (B \text{ OR } C) \)

Complete the truth table below. [4 marks]

| A | B | C | Intermediate: NOT(A AND B) | Intermediate: B OR C | Output: Z |
|---|---|---|---|---|---|
| 0 | 0 | 0 | | | |
| 0 | 0 | 1 | | | |
| 0 | 1 | 0 | | | |
| 0 | 1 | 1 | | | |
| 1 | 0 | 0 | | | |
| 1 | 0 | 1 | | | |
| 1 | 1 | 0 | | | |
| 1 | 1 | 1 | | | |
查看答案詳解

解題

To complete the table, we calculate each column step-by-step:

1. Column for \( \text{NOT}(A \text{ AND } B) \):
- A AND B is 1 only when both A and B are 1 (rows 7 and 8). Hence, \( \text{NOT}(A \text{ AND } B) \) is 0 for those rows, and 1 for all other rows.
- Values: 1, 1, 1, 1, 1, 1, 0, 0

2. Column for \( B \text{ OR } C \):
- B OR C is 1 if either B or C (or both) are 1.
- Values: 0, 1, 1, 1, 0, 1, 1, 1

3. Column for output Z (col 1 AND col 2):
- Z is 1 only when both intermediate columns are 1.
- Row 1: 1 AND 0 = 0
- Row 2: 1 AND 1 = 1
- Row 3: 1 AND 1 = 1
- Row 4: 1 AND 1 = 1
- Row 5: 1 AND 0 = 0
- Row 6: 1 AND 1 = 1
- Row 7: 0 AND 1 = 0
- Row 8: 0 AND 1 = 0

評分準則

- 1 mark for correct intermediate column 'NOT(A AND B)' (1, 1, 1, 1, 1, 1, 0, 0)
- 1 mark for correct intermediate column 'B OR C' (0, 1, 1, 1, 0, 1, 1, 1)
- 2 marks for correct output column 'Z' (0, 1, 1, 1, 0, 1, 0, 0). Award 1 mark if there are only 1 or 2 mistakes in the output column.
題目 13 · pseudocode
6
A text file named "scores.txt" contains a list of integers representing student test scores, with one score on each line.

Write a pseudocode algorithm that:
1. Opens the file "scores.txt" for reading.
2. Opens a new file named "results.txt" for writing.
3. Reads each score from "scores.txt".
4. Counts how many scores are 50 or above.
5. Writes this final count to "results.txt".
6. Closes both files.
查看答案詳解

解題

The algorithm must initialize a counter, open both files in the correct modes, loop until the end of the file is reached, perform a conditional check on each read value, write the final count to the output file, and close both files.

Example Pseudocode:
```
DECLARE Score : INTEGER
DECLARE Count : INTEGER
Count <- 0
OPENFILE "scores.txt" FOR READ
OPENFILE "results.txt" FOR WRITE
WHILE NOT EOF("scores.txt") DO
READFILE "scores.txt", Score
IF Score >= 50 THEN
Count <- Count + 1
ENDIF
ENDWHILE
WRITEFILE "results.txt", Count
CLOSEFILE "scores.txt"
CLOSEFILE "results.txt"
```

評分準則

Award 1 mark for each of the following (up to 6 marks total):
1. Opening "scores.txt" for READ and "results.txt" for WRITE.
2. Initializing the count variable to 0.
3. Correct loop structure using WHILE NOT EOF("scores.txt") (or equivalent loop structure).
4. Reading each value from the file inside the loop and performing a conditional check (Score >= 50).
5. Writing the correct final count to "results.txt" outside the loop.
6. Closing both files correctly using CLOSEFILE.
題目 14 · pseudocode
6
A text file named "temp.txt" contains daily temperature readings as real numbers, with one temperature per line.

Write a pseudocode algorithm that:
1. Opens the file "temp.txt" for reading.
2. Reads all temperature values in the file.
3. Calculates the average temperature.
4. Outputs the average temperature, or outputs the message "No data" if the file was empty.
5. Closes the file.
查看答案詳解

解題

The algorithm needs to open "temp.txt" for reading, loop through each entry, maintain an accumulator for the total sum and a counter for the number of entries, close the file, and then perform a selection check to output either the average (Total / Count) or "No data" to prevent a division-by-zero error if the file is empty.

Example Pseudocode:
```
DECLARE Total : REAL
DECLARE Count : INTEGER
DECLARE Temp : REAL
Total <- 0.0
Count <- 0
OPENFILE "temp.txt" FOR READ
WHILE NOT EOF("temp.txt") DO
READFILE "temp.txt", Temp
Total <- Total + Temp
Count <- Count + 1
ENDWHILE
CLOSEFILE "temp.txt"
IF Count > 0 THEN
OUTPUT Total / Count
ELSE
OUTPUT "No data"
ENDIF
```

評分準則

Award 1 mark for each of the following (up to 6 marks total):
1. Opening "temp.txt" for READ and closing it with CLOSEFILE.
2. Initializing total accumulator to 0.0 and count accumulator to 0.
3. Using a loop with NOT EOF("temp.txt") condition to process all elements.
4. Correctly reading a value and accumulating the total temperature inside the loop.
5. Incrementing the count variable inside the loop.
6. Correct IF-ELSE structure checking if Count > 0 before dividing, outputting the correct average or outputting "No data".
題目 15 · Database SQL
2
An SQL database table named CHARACTERS contains the fields: CharacterID, Name, Class, Level, and Health. Write an SQL query to retrieve and display only the Name and Level fields for all characters whose Class is 'Mage'.
查看答案詳解

解題

To retrieve the Name and Level fields, the SELECT clause must contain 'SELECT Name, Level'. The table to query is specified by 'FROM CHARACTERS'. To filter for characters where the Class is 'Mage', we use the WHERE clause: 'WHERE Class = 'Mage''. This forms the complete query: SELECT Name, Level FROM CHARACTERS WHERE Class = 'Mage';

評分準則

1 mark for: SELECT Name, Level FROM CHARACTERS. 1 mark for: WHERE Class = 'Mage' (Accept double quotes around Mage, and accept absence of trailing semicolon).
題目 16 · Database SQL
2
A database table called BOOKS stores information about books and has the fields: BookID, Title, Author, Price, and Genre. Write an SQL query to retrieve and display only the Title and Price of all books that have a Price less than 15.00, sorted in alphabetical order by their Title.
查看答案詳解

解題

The fields to retrieve are Title and Price: SELECT Title, Price. The table is BOOKS: FROM BOOKS. The condition is Price less than 15.00: WHERE Price < 15.00. The sorting is in alphabetical order of Title: ORDER BY Title. Combining these gives: SELECT Title, Price FROM BOOKS WHERE Price < 15.00 ORDER BY Title;

評分準則

1 mark for correct SELECT and FROM clauses: SELECT Title, Price FROM BOOKS. 1 mark for correct WHERE and ORDER BY clauses: WHERE Price < 15.00 ORDER BY Title (allow ASC).
題目 17 · Database SQL
2
A database table named EMPLOYEES contains the following fields: EmpID, LastName, Department, Salary, and DateJoined. Write an SQL query to display all fields for all records where the Salary is greater than 50000, sorted from highest to lowest Salary.
查看答案詳解

解題

To retrieve all fields, we use 'SELECT *'. The source table is EMPLOYEES: 'FROM EMPLOYEES'. The criteria is Salary greater than 50000: 'WHERE Salary > 50000'. To sort from highest to lowest, we sort in descending order of Salary: 'ORDER BY Salary DESC'. The complete query is SELECT * FROM EMPLOYEES WHERE Salary > 50000 ORDER BY Salary DESC;

評分準則

1 mark for correct selection of all fields: SELECT * FROM EMPLOYEES. 1 mark for correct filtering and descending sort order: WHERE Salary > 50000 ORDER BY Salary DESC.
題目 18 · Database SQL
2
A database table named PRODUCTS stores inventory details with the fields: ProductID, ProductName, StockLevel, ReorderLevel, and Category. Write an SQL query to display the ProductName and StockLevel for all records where the Category is 'Electronics' and the StockLevel is less than or equal to the ReorderLevel.
查看答案詳解

解題

We need to select ProductName and StockLevel: SELECT ProductName, StockLevel. The source table is PRODUCTS: FROM PRODUCTS. The conditions are that Category must be 'Electronics' and StockLevel must be less than or equal to ReorderLevel: WHERE Category = 'Electronics' AND StockLevel <= ReorderLevel. Combining these gives the full query.

評分準則

1 mark for SELECT and FROM clauses: SELECT ProductName, StockLevel FROM PRODUCTS. 1 mark for WHERE clause containing both conditions joined by AND: WHERE Category = 'Electronics' AND StockLevel <= ReorderLevel (accept single or double quotes for 'Electronics').
題目 19 · Complex Applied Program Coding
15
A local commercial nursery uses a computerized control system to monitor the environment across 10 separate greenhouses, numbered 1 to 10.

Write an algorithm using pseudocode that meets the following requirements:
1. Prompts the user to enter and validate the current temperature for each of the 10 greenhouses. Temperatures must be between -10.0 and 50.0 degrees Celsius inclusive. Any invalid input must produce an error message and prompt the user to re-enter.
2. Stores the 10 validated temperatures in a 1D array named 'Temp'.
3. Calculates and outputs the average temperature of all greenhouses.
4. Finds and outputs the highest temperature recorded, along with the greenhouse number(s) that recorded this temperature (note: more than one greenhouse may share the highest temperature).
5. Identifies any greenhouse with a temperature above 35.0 degrees Celsius, outputs a warning message 'Warning: Greenhouse [Number] is too hot!', and increments a count.
6. Outputs the total number of greenhouses that required a warning at the end of the program.

You must declare all variables used in your pseudocode.
查看答案詳解

解題

An elegant solution using standard Cambridge IGCSE pseudocode structure is shown below:

```text
DECLARE Temp : ARRAY[1:10] OF REAL
DECLARE GreenhouseNum, CountHot : INTEGER
DECLARE InputTemp, MaxTemp, Total, Average : REAL

Total <- 0
CountHot <- 0
MaxTemp <- -100.0

FOR GreenhouseNum <- 1 TO 10
REPEAT
OUTPUT "Enter temperature for greenhouse ", GreenhouseNum, " (-10.0 to 50.0):"
INPUT InputTemp
IF InputTemp < -10.0 OR InputTemp > 50.0 THEN
OUTPUT "Error: Temperature out of range. Please re-enter."
ENDIF
UNTIL InputTemp >= -10.0 AND InputTemp <= 50.0

Temp[GreenhouseNum] <- InputTemp
Total <- Total + InputTemp

IF InputTemp > MaxTemp THEN
MaxTemp <- InputTemp
ENDIF
NEXT GreenhouseNum

Average <- Total / 10
OUTPUT "Average temperature: ", Average
OUTPUT "Highest temperature recorded: ", MaxTemp

OUTPUT "Greenhouses with the highest temperature:"
FOR GreenhouseNum <- 1 TO 10
IF Temp[GreenhouseNum] = MaxTemp THEN
OUTPUT "Greenhouse ", GreenhouseNum
ENDIF
NEXT GreenhouseNum

FOR GreenhouseNum <- 1 TO 10
IF Temp[GreenhouseNum] > 35.0 THEN
OUTPUT "Warning: Greenhouse ", GreenhouseNum, " is too hot!"
CountHot <- CountHot + 1
ENDIF
NEXT GreenhouseNum

OUTPUT "Total greenhouses requiring ventilation warning: ", CountHot
```

評分準則

Marks are awarded for the following points (up to a maximum of 15 marks):

**Variable Declarations & Initialization (Max 2 marks):**
- 1 mark: Declaring the 1D array `Temp` with 10 elements and of REAL data type.
- 1 mark: Initializing running total variables (`Total`, `CountHot`) to 0 and `MaxTemp` to a logically low starting point (e.g. -11.0 or lower).

**Input Loop & Validation (Max 3 marks):**
- 1 mark: A structured loop running exactly 10 times to control greenhouse data entry.
- 1 mark: A nested validation loop (e.g., REPEAT...UNTIL or WHILE) that correctly rejects values outside the range [-10.0, 50.0].
- 1 mark: Informative error message output when an invalid value is entered.

**Array Storage and Cumulative Calculations (Max 2 marks):**
- 1 mark: Storing the validated input temperature inside the `Temp` array at the correct index.
- 1 mark: Adding the validated temperature to a running total variable.

**Finding and Outputting Max Temperature (Max 2 marks):**
- 1 mark: Finding the maximum temperature value by comparing each validated input to `MaxTemp`.
- 1 mark: Outputting the correct maximum temperature value after the input loop completes.

**Identifying Greenhouses with the Highest Temperature (Max 2 marks):**
- 1 mark: Using a separate loop to check each array value against the calculated maximum temperature.
- 1 mark: Correctly outputting the index/greenhouse number of all matching greenhouses.

**Warning Messages and Counting (Max 3 marks):**
- 1 mark: Comparing array values to find temperatures greater than 35.0.
- 1 mark: Outputting a descriptive warning message containing the specific greenhouse number.
- 1 mark: Correctly incrementing and outputting the final count of greenhouses exceeding 35.0.

**General Coding Structure (Max 1 mark):**
- 1 mark: Correct use of programming construct syntax (meaningful variable names, properly closed IF/FOR/REPEAT blocks).

想知道自己有幾分把握?

Thinka 是 DSE 學生用的 AI 練習應用程式,有無限量練習題、即時自動批改和詳細解題步驟。逾 100,000 名學生用它確認自己真的識,而不只是「以為識」。

想練更多類似題型?在 Thinka 無限量操練,即時知道答案。

免費開始練習