📚 Unit Test Mock Paper Analysis | 单元测试模拟卷解析
This article takes you through a complete unit test mock paper covering core topics from the CAIE A-Level Computer Science syllabus (9618). Each question is followed by a detailed solution that explains the underlying concepts, common pitfalls, and effective revision strategies. Use this walkthrough to refine your understanding and sharpen your exam technique for both Paper 3 and Paper 4 components.
本文带你完整解析一份覆盖 CAIE A-Level 计算机科学(9618)核心专题的单元测试模拟卷。每道题均配有详尽解析,阐释底层概念、常见误区及高效复习策略。通过这份逐题精讲,你可以巩固知识并提升 Paper 3 与 Paper 4 的应试能力。
1. Data Representation & Bit Manipulation | 数据表示与位运算
Question: The denary number 214 is to be stored in an 8-bit register. Convert 214 into binary and hexadecimal. Then perform a logical left shift of two places on the binary value and state the denary result. Explain whether an overflow has occurred.
问题:十进制数 214 将存入一个 8 位寄存器。将 214 转换为二进制和十六进制。然后对该二进制值执行两次逻辑左移操作,并给出结果的十进制值。解释是否发生了溢出。
Solution: 214 in binary is 11010110. Check: 128 + 64 + 16 + 4 + 2 = 214. In hexadecimal, 1101 0110 becomes D6. A logical left shift of two places gives 01011000 (the two rightmost bits are filled with zeros, and the two leftmost bits 11 are lost). This new binary value is 01011000, which is 88 in denary. Overflow occurs when bits shifted out change the sign bit incorrectly, but here we are using an 8-bit register for a positive number where the MSB is originally 1, indicating a negative number if we consider two’s complement. However, the question did not specify two’s complement representation; if we assume unsigned integer, shifting out nonzero bits causes a loss of the most significant part of the number, resulting in 88 instead of the expected 214 × 4 = 856, which would require more than 8 bits. Therefore, overflow has occurred in the sense that the true arithmetic result cannot be stored in 8 bits.
解答:214 的二进制为 11010110。验证:128 + 64 + 16 + 4 + 2 = 214。十六进制分组 1101 0110 得到 D6。两次逻辑左移后得到 01011000(右端补两个 0,左端两位 11 移出丢失)。新的二进制值 01011000 即十进制 88。当移位导致数值超出寄存器可表示范围时发生溢出;如果将 11010110 视为无符号数,左移两位相当于乘以 4,期望结果为 856,但 8 位最大只能表示 255,因此确实发生了溢出——移出的非零位丢失使结果不正确。
2. Processor Architecture & Assembly Language | 处理器架构与汇编语言
Question: A processor uses the Little Man Computer (LMC) instruction set. The following partial program is executed. Explain the role of the program counter (PC) and the current instruction register (CIR) during the fetch–decode–execute cycle for the instruction at mailbox 02.
问题:某处理器采用小人类计算机(LMC)指令集。执行以下程序片段。请解释在取指–译码–执行周期中,程序计数器(PC)和当前指令寄存器(CIR)对邮箱 02 中指令所起的作用。
| Mailbox | Instruction |
|---|---|
| 00 | LDA 07 |
| 01 | ADD 08 |
| 02 | STO 09 |
| 03 | HLT |
Solution: Before fetching the instruction at mailbox 02, the PC holds the address 02. During the fetch phase, the address stored in the PC (02) is placed onto the address bus, the memory is read, and the instruction STO 09 is transferred into the CIR. The PC is then incremented to 03 to point to the next instruction. In the decode phase, the control unit interprets the contents of the CIR: the opcode STO means “store accumulator to memory” and the operand 09 is extracted. Finally, during the execute phase, the data in the accumulator is written to mailbox 09. The PC and CIR thus coordinate the sequential flow and temporary holding of the instruction being processed.
解答:取指前 PC 保存地址 02。取指阶段 PC 内容 (02) 被送上地址总线,存储器被读取,指令 STO 09 传送到 CIR。之后 PC 递增为 03 以指向下一条指令。译码阶段控制单元译码 CIR 内容:操作码 STO 表示“将累加器值存入存储器”,操作数 09 被提取。执行阶段累加器数据写入邮箱 09。PC 和 CIR 协同实现了指令的顺序流转和对当前指令的暂存。
3. Operating Systems & Memory Management | 操作系统与内存管理
Question: A multitasking operating system uses paging with a page size of 2 KiB. A logical address is 16 bits. Calculate the number of pages in the logical address space and the number of bits used for the offset within a page. Describe how the page table translates a logical address to a physical address when a page fault occurs.
问题:某多任务操作系统采用分页管理,页大小为 2 KiB,逻辑地址 16 位。计算逻辑地址空间的页数和页内偏移所用的位数。描述当发生缺页时页表如何将逻辑地址转换为物理地址。
Solution: Logical address space = 216 bytes = 65536 bytes = 64 KiB. Page size = 2 × 1024 = 2048 bytes = 211 bytes. Number of pages = 64 KiB / 2 KiB = 32 pages. Offset bits = log2(2048) = 11 bits. The remaining 16 – 11 = 5 bits form the page number. During a page fault, the desired page is not present in main memory. The MMU signals a trap to the OS; the OS locates the required page on disk, chooses a frame in RAM (possibly evicting an existing page using a replacement algorithm like LRU), loads the page into that frame, and updates the page table entry to map the page number to the new frame number and sets the valid bit. The faulting instruction is then re-executed, and the MMU recalculates the physical address using the frame number from the updated page table entry combined with the original offset.
解答:逻辑地址空间 = 216 字节 = 65536 字节 = 64 KiB。页大小 = 2 × 1024 = 2048 字节 = 211 字节。页数 = 64 KiB / 2 KiB = 32 页。偏移位数 = log2(2048) = 11 位。剩下 16 – 11 = 5 位构成页号。发生缺页时,所需页面不在主存。MMU 发出陷阱信号给操作系统;OS 在磁盘上定位所需页,在 RAM 中选取一个帧(可能需要根据 LRU 等替换算法换出一个现有页),将页面载入该帧,然后更新页表项,将页号映射到新帧号并置有效位。随后重新执行缺页指令,MMU 利用更新后的页表项中的帧号与原始偏移组合计算出物理地址。
4. Communication & Network Protocols | 通信与网络协议
Question: Explain the purpose of the TCP three-way handshake and describe the sequence of messages exchanged. Then discuss how this process contributes to reliable data transfer.
问题:说明 TCP 三次握手的用途并描述交换的消息序列。接着论述该过程如何有助于可靠数据传输。
Solution: The three-way handshake establishes a connection-oriented session between a client and a server before data transmission. It synchronises sequence numbers and acknowledges each side’s readiness. The three steps are: (1) Client sends a SYN segment with a random initial sequence number, say SEQ=x. (2) Server replies with a SYN-ACK, acknowledging the client’s sequence number (ACK=x+1) and providing its own initial sequence number (SEQ=y). (3) Client sends an ACK acknowledging the server’s sequence number (ACK=y+1). The connection is now established. This exchange ensures both parties are alive and capable of communication, prevents old duplicate connection requests from being confused with current ones, and agrees on initial sequence numbers used for detecting lost, duplicated, or reordered segments. Together with mechanisms like checksum, acknowledgements, and retransmission timers, the handshake underpins TCP’s reliable byte-stream service.
解答:三次握手在数据传输前建立客户端与服务器之间的面向连接会话。它同步序列号并确认双方准备就绪。三步如下:(1) 客户端发送 SYN 段,携随机初始序列号 SEQ=x。(2) 服务器回复 SYN-ACK,确认客户端序列号(ACK=x+1)并给出自己初始序列号(SEQ=y)。(3) 客户端发送 ACK 确认服务器序列号(ACK=y+1)。连接随之建立。此交换确保双方活跃且可通信,防止旧有重复连接请求混淆,并约定初始序列号用于检测丢失、重复或乱序的报文段。握手与校验和、确认及重传定时器等机制共同构成 TCP 可靠字节流服务的基石。
5. Data Structures: Stacks, Queues & Linked Lists | 数据结构:栈、队列与链表
Question: Compare the use of a stack and a queue for implementing a breadth-first search (BFS) of a graph versus a depth-first search (DFS). Include in your answer a brief illustration using a linked list representation for the frontier structure.
问题:比较栈和队列在图的广度优先搜索(BFS)与深度优先搜索(DFS)中的使用。回答中请用链表示意说明前沿结构。
Solution: BFS explores nodes level by level, processing all neighbours of a node before moving deeper. It uses a queue (FIFO) as the frontier: newly discovered nodes are enqueued at the tail, while the next node to explore is dequeued from the head. DFS plunges as deep as possible along a branch before backtracking, so it uses a stack (LIFO) as the frontier: newly discovered nodes are pushed onto the stack, and the next node to visit is popped from the top. Both can be implemented with a singly linked list: for a queue, we maintain two pointers (head and tail) to allow O(1) enqueue (insert at tail) and dequeue (remove from head); for a stack, we only need a pointer to the head (top), performing push and pop at the head in O(1) time. The choice of data structure directly shapes the traversal order and, consequently, the memory usage patterns—DFS can be memory-efficient on deep narrow graphs, whereas BFS may require storing many nodes at a shallow breadth.
解答:BFS 逐层探索,先处理当前节点所有邻居再深入,因此前沿使用队列(FIFO):新发现节点入队至尾部,下一个探索节点从头部出队。DFS 沿分支尽可能深入,回溯前不断下钻,因此前沿使用栈(LIFO):新发现节点压入栈顶,下一个访问节点从栈顶弹出。两者都可用单链表实现:队列需维护头、尾两个指针,使入队(尾插入)和出队(头删除)均为 O(1);栈只需头部指针,在头部进行压入和弹出操作均为 O(1)。数据结构的选择直接决定了遍历顺序,进而影响内存占用——在深而窄的图上 DFS 可能更省内存,而 BFS 往往需在浅层宽度下存储大量节点。
6. Algorithms & Pseudocode Tracing | 算法与伪代码追踪
Question: Consider the following pseudocode that sorts an array using an improved bubble sort with a flag. Trace the algorithm on the array [5, 1, 4, 2, 8] and determine the number of swaps and passes executed.
问题:以下伪代码用含标志位的改进冒泡排序对数组排序。跟踪算法在数组 [5, 1, 4, 2, 8] 上的执行过程,确定执行的交换次数和趟数。
PROCEDURE BubbleSort(A)
n ← length(A)
REPEAT
swapped ← FALSE
FOR i ← 0 TO n-2
IF A[i] > A[i+1] THEN
SWAP A[i], A[i+1]
swapped ← TRUE
ENDIF
ENDFOR
n ← n - 1
UNTIL swapped = FALSE
ENDPROCEDURE
Solution: Pass 1: compare 5 and 1 -> swap -> [1,5,4,2,8]; 5 and 4 -> swap -> [1,4,5,2,8]; 5 and 2 -> swap -> [1,4,2,5,8]; 5 and 8 -> no swap. Swapped flag is true, swaps=3. Pass 2: compare 1,4 -> no swap; 4,2 -> swap -> [1,2,4,5,8]; 4,5 -> no swap; (n is reduced so last element 8 ignored). Swapped=true, swaps total=4. Pass 3: 1,2 -> no swap; 2,4 -> no swap; no swaps performed, swapped becomes false after loop. Procedure terminates. Total passes = 3, total swaps = 4. The flag prevents an extra unnecessary pass, demonstrating the improvement over classic bubble sort.
解答:第 1 趟:比较 5 和 1→交换→[1,5,4,2,8];5 和 4→交换→[1,4,5,2,8];5 和 2→交换→[1,4,2,5,8];5 和 8→无交换。交换标志为真,交换次数=3。第 2 趟:比较 1,4→无交换;4,2→交换→[1,2,4,5,8];4,5→无交换;(n 递减较多忽略末尾的 8)。标志仍为真,总交换=4。第 3 趟:1,2→无交换;2,4→无交换;循环结束后 swapped 为假。过程终止。总趟数=3,总交换=4。标志位避免了一次多余的趟,体现了对经典冒泡排序的改进。
7. Object-Oriented Programming & Inheritance | 面向对象编程与继承
Question: A software system models different types of publications in a library. Design a class hierarchy with a base class Publication, and derived classes Book and Journal. The Publication class should have attributes title and year, and a method getSummary() that returns a string. Override getSummary() in Book to include author and ISBN, and in Journal to include volume and issue. Explain the protection level (public, private, protected) you would choose for the attributes so that derived classes can access them without exposing them publicly.
问题:一个软件系统对图书馆中不同类型出版物建模。设计类层次结构:基类 Publication,派生类 Book 和 Journal。Publication 类应具有属性 title 和 year,以及返回字符串的方法 getSummary()。在 Book 中重写 getSummary() 以包含 author 和 ISBN;在 Journal 中包含 volume 和 issue。解释你会为属性选择哪种访问修饰符(public, private, protected),使得派生类可以访问它们但又不暴露给外部。
Solution: The attributes title and year should be declared as protected. This allows any derived class (Book, Journal) to access them directly in overridden methods while preventing external code from modifying them accidentally. Private would make them inaccessible to derived classes, forcing the use of getters; public would violate encapsulation. In the Book override: getSummary() can return a string concatenating title, year, author, and ISBN. In Journal: it returns title, year, volume, issue. Example code outline in pseudocode:
解答:属性 title 和 year 应声明为 protected。这样任何派生类(Book、Journal)都能在重写的方法中直接访问它们,而外部代码无法随意修改。Private 将使派生类无法访问,必须依赖 getter;public 则破坏封装性。Book 重写的 getSummary() 可返回连接 title、year、author 和 ISBN 的字符串。Journal 则返回 title、year、volume、issue。伪代码轮廓如下:
CLASS Publication
PROTECTED title : STRING
PROTECTED year : INTEGER
PUBLIC FUNCTION getSummary() RETURNS STRING
RETURN title + " (" + STR(year) + ")"
ENDFUNCTION
ENDCLASS
CLASS Book INHERITS Publication
PRIVATE author : STRING
PRIVATE isbn : STRING
PUBLIC FUNCTION getSummary() RETURNS STRING
RETURN title + " by " + author + ", ISBN: " + isbn + " (" + STR(year) + ")"
ENDFUNCTION
ENDCLASS
Protected provides the right balance between inheritance accessibility and encapsulation.
Protected 在继承可访问性与封装之间提供了恰当的平衡。
8. Boolean Algebra & Logic Circuit Simplification | 布尔代数与逻辑电路化简
Question: Simplify the Boolean expression F = A’B’C’ + A’B’C + A’BC’ + AB’C’ using algebraic laws, and draw the simplified logic circuit using only NAND gates. Assume A, B, C are inputs.
问题:用代数定律化简布尔表达式 F = A’B’C’ + A’B’C + A’BC’ + AB’C’,并画出仅使用与非门的简化逻辑电路图。假设 A、B、C 为输入。
Solution: Group terms: F = A’B’C’ + A’B’C + A’BC’ + AB’C’. Combine first two: A’B'(C’ + C) = A’B’ (1) = A’B’. Now F = A’B’ + A’BC’ + AB’C’. Factor A’ from the second group: A’ (B’ + BC’). Using distribution: B’ + BC’ = (B’ + B)(B’ + C’) = 1 · (B’ + C’) = B’ + C’. Thus F = A’B’ + A'(B’ + C’) + AB’C’ = A’B’ + A’B’ + A’C’ + AB’C’ (since A’B’ + A’B’ = A’B’). So F = A’B’ + A’C’ + AB’C’. Observe that A’B’ + AB’C’ = B'(A’ + AC’) = B'(A’ + A)(A’ + C’) = B'(1)(A’ + C’) = B’A’ + B’C’. This seems to give F = A’B’ + B’C’ + A’C’. However, we can attempt a Karnaugh map to verify: minterms: m0=000 (A’B’C’), m1=001 (A’B’C), m2=010 (A’BC’), m4=100 (AB’C’). K-map shows grouping: A’B’ covers m0,m1; B’C’ covers m0,m4; A’C’ covers m0,m2. So simplest SOP: F = A’B’ + A’C’ + B’C’. To implement with NAND gates only, double-negate and use De Morgan: F = ( (A’B’)’ (A’C’)’ (B’C’)’ )’. Each term, e.g., A’B’, can be generated by a NAND gate with inputs A and B (since NAND of A and B is (AB)’ = A’ + B’, not directly A’B’; need NOTs). Actually, to get A’ we can tie inputs of NAND together to form an inverter. To get A’B’ we can do (A NAND B) followed by NOT? Wait: A NAND B = (AB)’. (AB)’ is not A’B’; it’s A’ + B’. We need AND of A’ and B’. So generate A’ = A NAND A, B’ = B NAND B, then NAND A’ and B’ gives (A’B’)’ which when inverted yields A’B’. But we want final expression as NAND of three NAND combinations. F = (A’B’ + A’C’ + B’C’)’. Double complement: F = ( (A’B’)’ (A’C’)’ (B’C’)’ )’. So we need to produce (A’B’)’, (A’C’)’, (B’C’)’ using NAND gates. Observe that (A’B’)’ = (A NAND B)?? No. A’B’ = (A+B)’. So (A’B’)’ = A+B. Not simple. Alternative: Express F = (A’B’ + A’C’ + B’C’) then convert to NAND-NAND circuit. F = ((A’B’ + A’C’ + B’C’)’)’ = ( (A’B’)’ (A’C’)’ (B’C’)’ )’. Now (A’B’)’ = (A+B). We can produce A+B by NAND(A’, B’)? A’ NAND B’ = (A’B’)’ = A+B. And A’ = A NAND A, B’ = B NAND B. So: X = (A NAND A) NAND (B NAND B) => (A + B) = (A’B’)’. Similarly Y = (A NAND A) NAND (C NAND C) => (A’C’)’. Z = (B NAND B) NAND (C NAND C) => (B’C’)’. Then final output = (X NAND Y NAND Z) NAND (X NAND Y NAND Z)? Actually final NAND of X, Y, Z: F = (X Y Z)’ = ( (A’B’)’ (A’C’)’ (B’C’)’ )’ = A’B’ + A’C’ + B’C’ = F. Perfect. So circuit: three inverters (NAND with tied inputs) to get A’, B’, C’; then three NAND gates producing X, Y, Z; then one NAND gate combining X,Y,Z. All NAND.
解答:分组并化简:F = A’B’C’ + A’B’C + A’BC’ + AB’C’. 前两项合并为 A’B'(C’+C)=A’B’。得 F = A’B’ + A’BC’ + AB’C’。提取 A’ 得 A'(B’ + BC’)。利用 B’ + BC’ = (B’+B)(B’+C’) = 1·(B’+C’) = B’+C’。故 F = A’B’ + A'(B’+C’) + AB’C’ = A’B’ + A’B’ + A’C’ + AB’C’ = A’B’ + A’C’ + AB’C’。注意到 A’B’ + AB’C’ = B'(A’ + AC’) = B'(A’+C’),因此 F = A’B’ + A’C’ + B’C’。卡诺图验证:最小项 m0(000), m1(001), m2(010), m4(100)。化简得最简与或式 F = A’B’ + A’C’ + B’C’。为仅用与非门实现,双重取补并应用德摩根律:F = ( (A’B’)’ (A’C’)’ (B’C’)’ )’。A’B’ 的反相 (A’B’)’ = A + B,可由两个与非门实现:A’ = A NAND A, B’ = B NAND B, 然后 X = A’ NAND B’ = A + B。同理生成 Y = A + C, Z = B + C。最后,F = (X · Y · Z)’,由一个三输入与非门输出,再经过一个与非门当反相器?实际上 (X Y Z)’ 就是 F,所以直接用一个三输入与非门即可,若只有两输入门还需再组合,但原理成立。电路全部由与非门构成。
9. Database Design & SQL Queries | 数据库设计与 SQL 查询
Question: A database has two tables: Student(StudentID, Name, Class) and Result(StudentID, Subject, Grade). Write an SQL query to list the names of students who have obtained a grade ‘A’ in at least two different subjects. Also explain the use of GROUP BY and HAVING in the query.
问题:数据库有两张表:Student(StudentID, Name, Class) 和 Result(StudentID, Subject, Grade)。编写 SQL 查询,列出至少在两个不同科目中获得 ‘A’ 等级的学生姓名。并解释查询中 GROUP BY 和 HAVING 的用法。
Solution:
SELECT Student.Name FROM Student JOIN Result ON Student.StudentID = Result.StudentID WHERE Result.Grade = 'A' GROUP BY Student.StudentID, Student.Name HAVING COUNT(DISTINCT Result.Subject) >= 2;
The GROUP BY clause groups rows by student, so that aggregate functions can be applied per student. COUNT(DISTINCT Subject) counts the number of unique subjects with grade ‘A’ for each group. The HAVING clause filters groups based on the aggregate condition, retaining only those students with two or more distinct subjects. Without HAVING, we could not filter on the result of an aggregate function; WHERE acts on individual rows before grouping, while HAVING acts on grouped results.
解答:上述查询将 Student 与 Result 按 StudentID 连接,筛选出 Grade=’A’ 的行,然后按 StudentID 和 Name 分组。GROUP BY 将行按学生分组,使聚合函数可按组计算。COUNT(DISTINCT Subject) 统计每个学生获得 ‘A’ 的不同科目数。HAVING 子句根据聚合条件过滤分组,仅保留不同科目数 ≥2 的学生。WHERE 在分组前对单行进行筛选,而 HAVING 针对分组后的聚合结果进行过滤;二者作用阶段不同。
10. Cybersecurity & Ethical Considerations | 网络安全与伦理考量
Question: A company suffers a data breach in which personal customer records are leaked. Discuss the ethical responsibilities of the company under data protection legislation, and explain how encryption could have reduced the impact of the breach.
问题:一家公司遭遇数据泄露,客户个人记录被泄漏。讨论该公司在数据保护法规下的伦理责任,并解释加密如何可能降低此次泄露的影响。
Solution: Ethically, the company has a duty of care to protect customer data, as it holds sensitive personal information. Under legislation such as the Data Protection Act, it must ensure data is processed lawfully, stored securely, and not kept longer than necessary. Following a breach, it must notify the relevant supervisory authority and affected individuals without delay. Failure to do so can lead to loss of trust and legal penalties. Encryption converts plaintext data into ciphertext using an algorithm and a key; without the key, leaked data remains unintelligible. Strong encryption at rest and in transit reduces the risk that breached data can be misused for identity theft or fraud. While encryption cannot prevent the breach itself, it acts as a critical layer of defence, making stolen data worthless to unauthorised parties.
解答:伦理上,公司持有敏感个人信息,负有保护客户数据的注意义务。根据《数据保护法》等法律,必须确保数据合法处理、安全存储且保留时间不超过必要期限。发生泄露后必须立即通知相关监管机构和受影响个人。未履行此责任会导致信任丧失和法律处罚。加密通过算法和密钥将明文数据转换为密文;没有密钥,泄露的数据仍无法解读。强加密技术应用于静态存储和传输中,可降低泄露数据被用于身份盗窃或欺诈的风险。虽然加密无法阻止泄露本身,但它作为关键防御层使窃取的数据对未授权方毫无价值。
Published by TutorHao | Computer Science Revision Series | aleveler.com
更多咨询请联系16621398022(同微信)
屏轩国际教育cambridge primary/secondary checkpoint, cat4, ukiset,ukcat,igcse,alevel,PAT,STEP,MAT, ibdp,ap,ssat,sat,sat2课程辅导,国外大学本科硕士研究生博士课程论文辅导