📚 Year 12 CIE Computer Science: Mock Unit Test Analysis | A-Level 计算机单元测试模拟卷解析
This article presents a detailed walkthrough of a typical Year 12 CIE Computer Science unit test, covering data representation, computer architecture, networking, databases, and programming. Each section dissects a question from the mock paper, providing model answers and explanations to help students identify common pitfalls and master the required concepts for the AS level syllabus.
本文对一份典型的 A-Level 计算机科学单元测试模拟卷进行逐题解析,涵盖数据表示、计算机体系结构、网络、数据库和编程等模块。每个小节剖析一道题目,给出标准答案与知识点讲解,帮助学生发现常见错误,扎实掌握 CIE 考试大纲要求的核心概念。
1. Binary Addition and Overflow | 二进制补码加法与溢出检测
Question: Using 8-bit two’s complement representation, perform the addition of 0110 1101 and 0101 0010. Show the result and determine whether an overflow occurs. State how the overflow is detected.
题目:使用八位二进制补码表示法,计算 0110 1101 与 0101 0010 的和。展示结果并判断是否发生溢出,说明溢出是如何被检测到的。
Answer: The two binary numbers are both positive because the most significant bit (MSB) is 0. Adding them: 0110 1101 + 0101 0010 = 1011 1111. The MSB of the result is 1, which indicates a negative value in two’s complement. Since the two positive operands produced a negative result, an overflow has occurred. Overflow in two’s complement can be detected by checking the carry into the sign bit and the carry out of the sign bit. Here, carry into bit 7 is 1, carry out of bit 7 is 0; they are different, confirming overflow.
解析:两个加数最高位都是 0,表示正数。相加得到 1011 1111,结果的最高位为 1,在补码中代表负数。两个正数相加出现了负数结果,说明发生了溢出。在补码加法中,溢出可以通过比较进入符号位的进位和出符号位的进位来检测。此处进入第 7 位的进位为 1,出第 7 位的进位为 0,两者不同,证实溢出。
2. Logic Gate Simplification | 逻辑门电路化简
Question: Given the Boolean expression X = (A + B) ⋅ (A’ + C), simplify it using Boolean algebra laws and draw the equivalent logic circuit using only NAND gates.
题目:已知布尔表达式 X = (A + B) ⋅ (A’ + C),用布尔代数定律将其化简,并仅用与非门画出等效逻辑电路。
Answer: Apply the distributive law: X = A⋅A’ + A⋅C + B⋅A’ + B⋅C. Since A⋅A’ = 0, we get X = A⋅C + A’⋅B + B⋅C. Using the consensus theorem, the term B⋅C is redundant, so X = A⋅C + A’⋅B. To implement with only NAND gates, convert to NAND form: double-negate the expression, then use De Morgan’s theorem to push inversions to the inputs. The circuit can be built by three NAND gates: first NAND of A and C, second NAND of A’ (obtained by NAND of A with itself) and B, then a final NAND combining the outputs of the first two.
解析:应用分配律展开,再使用合意定理消去冗余项 B⋅C,得到 X = A⋅C + A’⋅B。为使用全与非门实现,对表达式两次取反,并利用德·摩根定律将内部与或形式转化为与非-与非形式。实际电路可用三个与非门:第一个与非门输入 A 和 C;第二个与非门先取 A’(通过将 A 自身与非得到),再与 B 与非;第三个与非门将前两个输出作为输入并取反,即可得到 X。
3. Fetch–Execute Cycle | 取指-执行周期详解
Question: Describe the steps of the fetch–execute cycle for the instruction ‘LDR R1, [R2]’ in a von Neumann architecture. Explain the role of the program counter, memory address register, memory data register, and current instruction register.
题目:描述冯·诺依曼架构下指令“LDR R1, [R2]”的取指-执行周期步骤。解释程序计数器、存储器地址寄存器、存储器数据寄存器和当前指令寄存器的作用。
Answer: In the fetch stage, the address in the Program Counter (PC) is copied to the Memory Address Register (MAR). The control unit sends a read signal to memory, and the instruction stored at that address is placed into the Memory Data Register (MDR). The instruction is then transferred to the Current Instruction Register (CIR), and the PC is incremented. In the execute stage, the instruction is decoded: LDR R1, [R2] means load into R1 the contents of the memory location whose address is held in R2. The value in R2 is sent to the MAR, a memory read is performed, and the data from MDR is written into R1.
解析:取指阶段,程序计数器 PC 中的地址被复制到存储器地址寄存器 MAR,控制单元发送读信号,对应指令被加载到存储器数据寄存器 MDR,然后移入当前指令寄存器 CIR,同时 PC 自增。执行阶段,指令被解码:LDR R1, [R2] 表示将 R2 中所存地址对应的内存单元内容加载到寄存器 R1。于是 R2 的值送入 MAR,执行存储器读操作,MDR 获得的数据最终写入 R1。
4. Interrupt Handling | 中断处理过程
Question: Explain how a processor handles an interrupt, including the saving of context and the role of the interrupt vector table. Why is interrupt latency critical in real-time systems?
题目:解释处理器如何处理中断,包括上下文的保存和中断向量表的作用。为什么中断延迟在实时系统中至关重要?
Answer: When an interrupt occurs, the processor completes the current instruction to avoid leaving the system in an inconsistent state. It then saves the processor context—the contents of the PC, status register, and general-purpose registers—onto the stack. The interrupt controller provides an interrupt number, which is used as an index into the interrupt vector table to fetch the starting address of the corresponding Interrupt Service Routine (ISR). After the ISR executes, the saved context is restored, and the original program resumes. Interrupt latency is the time from the interrupt assertion to the start of the ISR. In real-time systems, long latency may cause missed deadlines and system failure.
解析:中断发生时,处理器首先完成当前指令,然后保存上下文——包括 PC、状态寄存器和通用寄存器的内容——到堆栈。中断控制器提供中断号,作为索引从中断向量表中取出对应中断服务程序 ISR 的起始地址。ISR 执行完毕后,恢复之前保存的上下文,原程序继续运行。中断延迟是指从中断信号发出到 ISR 开始执行的时间。在实时系统中,延迟过长可能导致错失截止时间,引发系统失效。
5. Network Topologies and Performance | 网络拓扑结构与性能
Question: Compare star and bus topologies in terms of fault tolerance, scalability, and cost. A small office needs to expand from 5 to 30 workstations; which topology would you recommend? Justify your answer.
题目:从容错性、可扩展性和成本角度比较星型拓扑与总线型拓扑。某小型办公室需要从 5 台工作站扩展到 30 台,你会推荐哪种拓扑?请说明理由。
Answer: In a bus topology, all devices share a single backbone cable; a break in the cable can bring down the entire network, so fault tolerance is low. Adding more devices degrades performance due to collisions and signal attenuation. It is inexpensive to install initially. In a star topology, each device has a dedicated cable to a central switch/hub. A single cable failure only affects one node, offering better fault tolerance. Scalability is excellent: adding a node simply requires another port on the switch. Although the initial cost is higher due to cabling and the switch, for 30 workstations the star topology is far more practical. It isolates faults, allows higher throughput with switching, and simplifies troubleshooting. I recommend a star topology with a manageable switch.
解析:总线型拓扑所有设备共享同一主干电缆,一旦主干断裂全网瘫痪,容错性差;增加设备会使碰撞加剧、性能下降,尽管初始成本较低。星型拓扑中每台设备通过独立线缆连接到中心交换机/集线器,单一线路故障只影响该节点,容错性更好。扩展性极佳:只需交换机有足够的端口即可。尽管线缆和交换机的初始成本较高,但对于 30 台工作站,星型拓扑更为实际,能隔离故障、提高吞吐量并简化故障排查。推荐采用带可管理交换机的星型拓扑。
6. SQL Query Construction | SQL 查询编写
Question: A database has a table Student(ID, Name, Form, AverageScore). Write SQL statements to: (i) list all students in Form 12A with AverageScore above 80; (ii) update the AverageScore of the student with ID 205 to 88; (iii) delete all records where AverageScore is below 40.
题目:数据库中有表 Student(ID, Name, Form, AverageScore)。编写 SQL 语句实现:(i) 列出所有 Form 为 12A 且 AverageScore 大于 80 的学生;(ii) 将 ID 为 205 的学生的 AverageScore 更新为 88;(iii) 删除所有 AverageScore 低于 40 的记录。
Answers: (i) SELECT * FROM Student WHERE Form = '12A' AND AverageScore > 80; (ii) UPDATE Student SET AverageScore = 88 WHERE ID = 205; (iii) DELETE FROM Student WHERE AverageScore < 40; It is essential to use the WHERE clause in UPDATE and DELETE to target specific rows; otherwise, all rows would be affected. String literals should be enclosed in single quotes.
解析:(i) 使用 SELECT 配合 WHERE 条件筛选,字符串用单引号括起,逻辑运算符 AND 连接两个条件。(ii) UPDATE 语句一定要加 WHERE 子句限定行,否则会修改全表数据。(iii) DELETE 同样依赖 WHERE 子句精准删除。注意在删除操作前可先用相同条件的 SELECT 核查将要影响的行,确保安全。
7. Pseudocode Algorithm: Find Max and Second Max | 伪代码算法:寻找最大值与次大值
Question: Write a pseudocode algorithm that takes an array of at least two distinct integers and outputs the largest and the second largest values. Your algorithm must complete in a single pass through the array.
题目:编写伪代码算法,输入至少包含两个不同整数的数组,输出最大值和次大值。算法必须只遍历数组一次。
Answer:
PROCEDURE FindTopTwo(Arr: ARRAY OF INTEGER)
max1 ← Arr[0]
max2 ← Arr[1]
IF max1 < max2 THEN
SWAP max1, max2
ENDIF
FOR i ← 2 TO LENGTH(Arr)-1
IF Arr[i] > max1 THEN
max2 ← max1
max1 ← Arr[i]
ELSE IF Arr[i] > max2 AND Arr[i] != max1 THEN
max2 ← Arr[i]
ENDIF
ENDFOR
OUTPUT max1, max2
ENDPROCEDURE
The algorithm initialises the top two values with the first two elements, then updates them as it scans the rest. This ensures O(n) time complexity.
解析:先将前两个元素赋值为 max1 和 max2,并保证 max1 ≥ max2。然后从第三个元素开始遍历,若当前元素大于 max1,则将原 max1 存入 max2,新值存为 max1;若仅大于 max2 且不等于 max1,则更新 max2。这种方法只遍历一次数组,时间复杂度为 O(n),且不使用额外的排序操作。
8. File Handling and Exception Management | 文件处理与异常管理
Question: A program attempts to open a file named 'data.txt' and read its contents line by line. Explain how you would implement robust error handling to manage situations such as the file not existing, the file being inaccessible, or the file containing corrupted data. Provide a pseudocode outline.
题目:某程序尝试打开文件 'data.txt' 并逐行读取内容。说明如何实现健壮的错误处理,以应对文件不存在、文件不可访问或数据损坏等情况。给出伪代码提纲。
Answer: Use exception handling structures. Attempt to open the file inside a TRY block. Catch specific exceptions: FileNotFoundError to prompt the user to check the filename; PermissionError to report insufficient access rights; and a general IOException for other I/O issues. While reading lines, validate each data format (e.g., expected integer or pattern). If a line fails validation, log the error and skip or terminate gracefully. Use a FINALLY block to close the file resource if it was successfully opened.
Pseudocode outline:
TRY
file ← OPEN 'data.txt', READ
FOR each line IN file
TRY
process(line)
CATCH DataFormatError
OUTPUT 'Corrupted line ignored'
ENDTRY
ENDFOR
CATCH FileNotFoundError
OUTPUT 'File not found'
CATCH PermissionError
OUTPUT 'Access denied'
FINALLY
IF file IS OPEN THEN file.CLOSE()
ENDTRY
解析:利用异常处理结构,将打开文件的操作放在 TRY 块中,针对不同异常类型分别处理:FileNotFoundError 提示用户检查文件名,PermissionError 报告权限不足,通用的 IOException 处理其他输入输出故障。在逐行读取时,对每行数据格式进行验证,若格式不符则记录错误并可选择跳过,避免程序崩溃。无论是否发生异常,利用 FINALLY 块确保已打开的文件被关闭,防止资源泄漏。
9. Memory Management: Paging | 内存管理:分页技术
Question: With the aid of a diagram, explain how paging works in a virtual memory system. Discuss the role of the page table and the translation lookaside buffer (TLB). How does paging prevent external fragmentation?
题目:借助示意图说明虚拟内存系统中分页的工作原理。讨论页表和转换后备缓冲器 TLB 的作用。分页如何避免外部碎片?
Answer: Paging divides logical memory into fixed-size blocks called pages and physical memory into frames of the same size. When a process needs a page, the memory management unit (MMU) uses the page number to index into the page table, which stores the corresponding frame number. The TLB is a small, high-speed cache that stores recent page table entries to accelerate address translation. Paging eliminates external fragmentation because any free frame can be allocated to any page; there is no requirement for contiguous physical memory. Internal fragmentation can still occur if the process does not use the entire last page.
解析:分页将逻辑内存划分为固定大小的页,物理内存划分为同样大小的帧。进程需要某页时,内存管理单元 MMU 以页号为索引查找页表,获得对应的帧号。TLB 是高速缓存,存放最近使用的页表项,加速地址转换。分页彻底避免了外部碎片,因为任何空闲帧都可分配给任何页,无需物理连续内存。但进程的最后一个页若未用完,可能会产生内部碎片。
10. Network Security: Symmetric vs Asymmetric Encryption | 网络安全:对称加密与非对称加密
Question: Compare symmetric and asymmetric encryption in terms of key distribution, computational speed, and typical use cases. Explain how a hybrid approach is used in protocols such as TLS.
题目:从密钥分发、计算速度和典型应用场景三个方面比较对称加密与非对称加密。说明 TLS 等协议如何采用混合加密方式。
Answer: Symmetric encryption uses a single shared key for both encryption and decryption. It is fast and suitable for bulk data encryption, but secure key distribution is challenging because the same key must be shared secretly between parties. Asymmetric encryption uses a public/private key pair; the public key encrypts, the private key decrypts. It solves the key distribution problem (only the public key needs to be shared openly) but is computationally expensive. In TLS, a handshake uses asymmetric encryption (e.g., RSA or ECDHE) to securely exchange a session key, then symmetric encryption (e.g., AES) handles the data transfer for efficiency. This hybrid approach combines the security of asymmetric keys with the speed of symmetric ciphers.
解析:对称加密使用同一把密钥进行加密和解密,速度快,适合大量数据加密,但密钥的安全分发是难题。非对称加密采用公钥/私钥对,公钥加密、私钥解密,解决了密钥分发问题(只需公开公钥),但计算开销大。TLS 协议先通过非对称加密(如 RSA 或 ECDHE)安全交换会话密钥,随后数据传输使用对称加密(如 AES)以提高效率。这种混合方式兼顾了安全性和性能。
11. CPU Performance Factors | CPU 性能影响因素
Question: A processor has a clock speed of 2.4 GHz, a CPI of 1.5, and executes a program of 3 billion instructions. Calculate the execution time. Explain how pipelining and superscalar architecture can reduce the CPI and thus the execution time.
题目:某处理器主频 2.4 GHz,CPI 为 1.5,执行一个包含 30 亿条指令的程序。计算执行时间。解释流水线技术和超标量架构如何降低 CPI 从而缩短执行时间。
Answer: Execution time = (Instruction count × CPI) / Clock rate = (3×10⁹ × 1.5) / (2.4×10⁹) = 4.5×10⁹ / 2.4×10⁹ = 1.875 seconds. Pipelining overlaps the execution of multiple instructions by splitting the instruction cycle into stages (e.g., fetch, decode, execute, write-back). Ideally, it achieves a CPI close to 1 because one instruction can complete every clock cycle after the pipeline is full. Superscalar architectures have multiple execution units and can issue more than one instruction per clock cycle, reducing CPI below 1. Both techniques exploit instruction-level parallelism to improve throughput.
解析:执行时间 = (指令数 × CPI) / 时钟频率 = (3×10⁹ × 1.5) / (2.4×10⁹) = 1.875 秒。流水线将指令周期划分为多个阶段并行执行,理想情况下能在每个时钟周期完成一条指令,使 CPI 趋近于 1。超标量架构拥有多个执行单元,每个时钟周期可发射多条指令,CPI 可低于 1。二者均利用指令级并行性提升吞吐量。
12. Object-Oriented Programming: Inheritance and Polymorphism | 面向对象编程:继承与多态
Question: Using a class diagram example, explain the concepts of inheritance and polymorphism. Show how a base class 'Vehicle' with derived classes 'Car' and 'Motorcycle' can override a method 'calculateTax()' to provide different implementations.
题目:结合类图示例,解释继承与多态的概念。演示基类 'Vehicle' 和派生类 'Car'、'Motorcycle' 如何重写方法 'calculateTax()' 以提供不同实现。
Answer: Inheritance allows a derived class to inherit attributes and methods from a base class, promoting code reuse. For instance, 'Vehicle' defines properties like 'price' and a method 'calculateTax()'. 'Car' and 'Motorcycle' inherit these and can provide their own implementations of 'calculateTax()' (e.g., car tax based on CO₂ emissions, motorcycle tax based on engine capacity). Polymorphism means that a reference variable of type 'Vehicle' can point to an object of any derived class, and the correct overridden method is called at runtime based on the actual object type (dynamic binding). This enables writing flexible code that works with the base class interface without knowing the specific subclass.
解析:继承允许派生类获得基类的属性和方法,实现代码复用。例如 'Vehicle' 定义属性 'price' 和方法 'calculateTax()','Car' 和 'Motorcycle' 继承后可以各自重写 'calculateTax()'(汽车按碳排放计,摩托车按排量计)。多态指一个基类类型的引用变量可以指向任意派生类对象,运行时根据实际对象类型调用正确的重写方法(动态绑定)。这使得代码能够面向基类接口编写,无需关心具体子类,提高了扩展性。
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课程辅导,国外大学本科硕士研究生博士课程论文辅导