← 返回资讯屏轩教育 · 行业资讯

Year 10 SQA Computing Science: Unit Test Mock Paper Analysis | 英国SQA十年级计算机单元测试模拟卷解析

2026-07-20 15:37 · 本文部分内容由AI辅助创作

📚 Year 10 SQA Computing Science: Unit Test Mock Paper Analysis | 英国SQA十年级计算机单元测试模拟卷解析

This article provides a complete walkthrough of a mock unit test for the SQA National 5 Computing Science course, designed for Year 10 students. The paper focuses on the Software Design and Development unit, covering data types, expressions, control structures, arrays, algorithm design, testing, and evaluation. Each question is explained in detail to help you understand the underlying concepts and avoid common pitfalls.

本文为SQA National 5计算机科学课程(适用于十年级)提供一份单元测试模拟卷的完整解析。模拟卷聚焦于“软件设计与开发”单元,涵盖数据类型、表达式、控制结构、数组、算法设计、测试与评估等主题。每道题都详细讲解,帮助理解核心概念并避开常见错误。


1. Data Types and Variable Declaration | 数据类型与变量声明

Question: Identify the data types suitable for storing the following values: a student's name, their age, the score on a test (e.g., 78.5), and whether they passed. Then, write variable declarations in a programming language of your choice.

题目: 确定存储以下值所需的合适数据类型:学生姓名、年龄、测试分数(例如78.5),以及是否通过。然后用你选择的编程语言写出变量声明。

The student's name should be stored as a String because it contains a sequence of characters. In SQA Reference Language, you might write: DECLARE pupilName AS STRING INITIALLY "Jamie".

学生姓名应存储为字符串(String)类型,因为它是一串字符。在SQA参考语言中,可声明为:DECLARE pupilName AS STRING INITIALLY "Jamie"。

Age is a whole number, so the Integer data type is appropriate. Example: DECLARE pupilAge AS INTEGER INITIALLY 15.

年龄是整数,因此适合整数(Integer)类型。例如:DECLARE pupilAge AS INTEGER INITIALLY 15。

The test score contains a decimal fraction, making it a Real (or Float) number. You could use: DECLARE testScore AS REAL INITIALLY 78.5.

测试分数包含小数部分,应使用实数(Real 或 Float)类型。声明示例:DECLARE testScore AS REAL INITIALLY 78.5。

Whether the student passed is a true/false value, which calls for a Boolean type: DECLARE hasPassed AS BOOLEAN INITIALLY TRUE.

是否通过是一个真/假值,需用布尔(Boolean)类型:DECLARE hasPassed AS BOOLEAN INITIALLY TRUE。

Choosing the correct data type ensures that operations are valid and memory is used efficiently. An integer variable can participate in arithmetic, while a string cannot be multiplied.

选择正确的数据类型能确保操作有效、内存使用高效。整型变量可参与算术,字符串则不能进行乘法运算。


2. Arithmetic Expressions | 算术表达式

Question: Given a = 10, b = 3, evaluate the expression: a % b * 2 + a / b. Also write the order of precedence for the operators used.

题目: 给定 a = 10, b = 3,求表达式 a % b * 2 + a / b 的值,并写出所用运算符的优先级顺序。

First, a % b gives the remainder when 10 is divided by 3. 10 % + 3.333... ≈ 5.333. The expression evaluates to 5.333... (or 5.33 to two decimal places).

首先,a % b 计算10除以3的余数,即 10 % 3 = 1。然后将此结果乘2:1 * 2 = 2。接着 a / b 进行实数除法:10 / 3 ≈ 3.333...。最后加法:2 + 3.333... ≈ 5.333。表达式值为5.333...(或保留两位小数5.33)。

The order of precedence in this expression: %, *, / have equal precedence and are evaluated left-to-right; then + (lower precedence) is performed last. In terms of rules:

该表达式的优先级顺序:%,*,/ 优先级相同,按从左到右求值;然后 +(优先级较低)最后执行。规则如下表:

Precedence LevelOperators
Highest( ) brackets
Middle*, /, %, DIV, MOD
Lowest+, -

Using parentheses can make the intended order clearer and prevent mistakes. For instance, (a % b) * 2 + (a / b) would be read more easily.

使用括号可以让运算顺序更清晰、减少错误。例如 (a % b) * 2 + (a / b) 的可读性就更好。


3. Conditional Statements | 条件语句

Question: ...: Explain the difference between IF...THEN...ELSE and nested IF statements. Provide an example using the grading rule: score >= 80 → 'A', 60-79 → 'B', 40-59 → 'C', below 40 → 'F'.

题目: 解释 IF...THEN...ELSE 与嵌套 IF 语句的区别。并利用评分规则(分数 ≥ 80 → 'A',60-79 → 'B',40-59 → 'C',40以下 → 'F')给出示例。

A simple IF...THEN...ELSE handles only two branches: one action when the condition is true, another action when it is false. For multiple conditions like grade bands, you can chain several IF...ELSE IF...ELSE statements. This is effectively a sequence of nested IFs because each ELSE branch may contain another IF.

简单 IF...THEN...ELSE 只处理两个分支:条件为真时一个动作,条件为假时另一个动作。对于像成绩分段这样的多重条件,可以串联多个 IF...ELSE IF...ELSE 语句。这实际上就是嵌套 IF,因为每个 ELSE 分支可能包含另一个 IF。

Example in SQA Reference Language:

SQA参考语言示例:

IF score >= 80 THEN
   SEND "Grade A" TO DISPLAY
ELSE IF score >= 60 THEN
   SEND "Grade B" TO DISPLAY
ELSE IF score >= 40 THEN
   SEND "Grade C" TO DISPLAY
ELSE
   SEND "Grade F" TO DISPLAY
END IF

IF score >= 80 THEN
   SEND "Grade A" TO DISPLAY
ELSE IF score >= 60 THEN
   SEND "Grade B" TO DISPLAY
ELSE IF score >= 40 THEN
   SEND "Grade C" TO DISPLAY
ELSE
   SEND "Grade F" TO DISPLAY
END IF

This structure is clearer than writing multiple independent IF statements that all execute regardless of earlier decisions. Nested IFs ensure only one branch runs, improving efficiency and correctness.

这种结构比编写多个独立的 IF 语句更清晰——独立IF不管前面已做的决定都会执行。嵌套 IF 确保只执行一条分支,提升效率和正确性。


4. Iteration and Loops | 迭代与循环

Question: Write an algorithm using a FOR loop to display the first 10 multiples of 7. Then rewrite it using a WHILE loop.

题目: 使用 FOR 循环写出显示7的前10个倍数的算法。然后用 WHILE 循环重写。

FOR loop solution (known number of iterations):

FOR 循环解法(已知迭代次数):

FOR counter FROM 1 TO 10 DO
   SEND (counter * 7) TO DISPLAY
END FOR

FOR counter FROM 1 TO 10 DO
   SEND (counter * 7) TO DISPLAY
END FOR

WHILE loop version (condition-based):

WHILE 循环版本(基于条件的):

SET counter TO 1
WHILE counter <= 10 DO
   SEND (counter * 7) TO DISPLAY
   SET counter TO counter + 1
END WHILE

SET counter TO 1
WHILE counter <= 10 DO
   SEND (counter * 7) TO DISPLAY
   SET counter TO counter + 1
END WHILE

The FOR loop is preferable when the number of iterations is fixed before the loop starts. The WHILE loop is more flexible and can be used when the exit condition depends on calculations or user input. Both achieve the same output but differ in structure.

FOR 循环适合迭代次数在循环开始前就能确定的情况。WHILE 循环更灵活,适用于退出条件依赖于计算或用户输入的情形。两者输出相同,但结构不同。


5. Arrays and Lists | 数组与列表

Question: An array 'temperatures' stores daily temperatures in °C for a week: [15, 17, 14, 16, 18, 13, 20]. Write an algorithm to find and output the highest temperature and its day index (Day 1 to Day 7).

题目: 数组 'temperatures' 存储了一周每天的温度(°C):[15, 17, 14, 16, 18, 13, 20]。写出算法,找出并输出最高温度及其天数索引(第1天到第7天)。

One valid approach is a linear search through the array. Initialise maxTemp to the first element and maxDay to 1. Then loop through the remaining elements, updating when a larger value is found.

一种有效的方法是对数组进行线性搜索。将 maxTemp 初始化为第一个元素,maxDay 为 1。然后循环遍历剩余元素,发现更大值时更新。

Pseudocode:

伪代码:

DECLARE temperatures AS ARRAY OF INTEGER INITIALLY [15, 17, 14, 16, 18, 13, 20]
SET maxTemp TO temperatures[0]
SET maxDay TO 1
FOR index FROM 1 TO 6 DO
   IF temperatures[index] > maxTemp THEN
     SET maxTemp TO temperatures[index]
     SET maxDay TO index + 1
   END IF
END FOR
SEND "Highest temperature: " & maxTemp & " was on day " & maxDay TO DISPLAY

DECLARE temperatures AS ARRAY OF INTEGER INITIALLY [15, 17, 14, 16, 18, 13, 20]
SET maxTemp TO temperatures[0]
SET maxDay TO 1
FOR index FROM 1 TO 6 DO
   IF temperatures[index] > maxTemp THEN
     SET maxTemp TO temperatures[index]
     SET maxDay TO index + 1
   END IF
END FOR
SEND "Highest temperature: " & maxTemp & " was on day " & maxDay TO DISPLAY

The algorithm runs with time complexity O(n), where n is the number of days. It correctly handles days with the same maximum by recording the first occurrence.

该算法的时间复杂度为 O(n),n 为天数。遇到相同最高温度时,它记录首次出现的位置。


广告 / Sponsored

6. Algorithm Design and Pseudocode | 算法设计与伪代码

Question: A program reads a list of integers terminated by -1. It should count how many numbers are positive and how many are odd. Produce a pseudocode solution using SQA Reference Language.

题目: 一个程序读取整数序列,以 -1 结束。统计其中正数个数和奇数个数。用 SQA 参考语言写出伪代码解决方案。

A REPEAT...UNTIL or WHILE loop is suitable since we don't know the number of inputs in advance. The sentinel value -1 must be excluded from counts. After the loop, output the two totals.

由于事先不知道输入个数,适合使用 REPEAT...UNTIL 或 WHILE 循环。哨兵值 -1 不计入统计数据。循环结束后输出两个总数。

WHILE-based pseudocode:

基于 WHILE 的伪代码:

SET posCount TO 0
SET oddCount TO 0
SET num TO 0
WHILE num ≠ -1 DO
   RECEIVE num FROM KEYBOARD
   IF num ≠ -1 THEN
     IF num > 0 THEN
       SET posCount TO posCount + 1
     END IF
     IF num MOD 2 ≠ 0 THEN
       SET oddCount TO oddCount + 1
     END IF
   END IF
END WHILE
SEND "Positive numbers: " & posCount TO DISPLAY
SEND "Odd numbers: " & oddCount TO DISPLAY

SET posCount TO 0
SET oddCount TO 0
SET num TO 0
WHILE num ≠ -1 DO
   RECEIVE num FROM KEYBOARD
   IF num ≠ -1 THEN
     IF num > 0 THEN
       SET posCount TO posCount + 1
     END IF
     IF num MOD 2 ≠ 0 THEN
       SET oddCount TO oddCount + 1
     END IF
   END IF
END WHILE
SEND "Positive numbers: " & posCount TO DISPLAY
SEND "Odd numbers: " & oddCount TO DISPLAY

Note that zero is neither positive nor negative, so it is not counted in the positive category. The condition num MOD 2 ≠ 0 correctly identifies odd numbers because even numbers give a remainder of 0 when divided by 2.

注意零既不是正数也不是负数,因此不计入正数。条件 num MOD 2 ≠ 0 能正确识别奇数,因为偶数除以2的余数为0。


7. Testing and Debugging | 测试与调试

Question: Examine the code snippet intended to print all elements of an array of length 5, stored with indices 0 to 4. The programmer wrote: FOR i FROM 1 TO 5 DO SEND arr[i] TO DISPLAY. Identify the logic error, explain its consequence, and describe how to test and fix it.

题目: 审视下面旨在打印长度为5、索引0到4的数组所有元素的代码段。程序员写了:FOR i FROM 1 TO 5 DO SEND arr[i] TO DISPLAY。指出逻辑错误,解释后果,并说明如何测试与修正。

The loop attempts to access arr[1] to arr[5]. In a zero-indexed array of size 5, valid indices are 0, 1, 2, 3, 4. Index 5 is out of bounds, causing a runtime error. Additionally, the element at index 0 is never printed, so the output is incomplete.

该循环试图访问 arr[1] 到 arr[5]。在大小为5的零基数组里,有效索引是 0,1,2,3,4。索引5越界,将导致运行时错误。同时,索引0的元素从未打印,输出不完整。

ta. You would see that i=1 accesses the second element, and i=5 accesses memory that doesn' ong to the array. The correct loop should be: FOR i FROM 0 TO 4 DO SEND arr[i] TO DISPLAY.

这是一个典型的差一错误。使用样例数据做跟踪表测试:会发现 i=1 访问的是第二个元素,而 i=5 会访问不属于数组的内存。正确的循环应为:FOR i FROM 0 TO 4 DO SEND arr[i] TO DISPLAY。

Testing with boundary values (first and last index) and an internal element helps uncover such errors. Good practice is to always check that the loop bounds match the array's index range.

用边界值(首、末索引)和中间元素测试有助于发现这类错误。良好实践是始终检查循环边界是否匹配数组索引范围。


8. Evaluation | 评估

Question: For the algorithm you designed in Question 6, evaluate its efficiency in terms of readability and the number of iterations. Suggest one improvement that would make the solution more robust or easier to maintain.

题目: 针对你在第6题中设计的算法,评估其在可读性和迭代次数方面的效率,并提出一项改进,使解决方案更稳健或更易维护。

The algorithm uses a clear WHILE loop with a sentinel value. Variable names like posCount and oddCount are self-documenting, enhancing readability. The structure is straightforward: input, filter out the sentinel, check conditions, update counts. Each number in the list causes one iteration, so the number of iterations equals the length of the input (minus the sentinel). That is efficient and cannot be reduced.

该算法使用了清晰的 WHILE 循环及哨兵值。变量名 posCount 和 oddCount 一目了然,提升了可读性。结构直截了当:输入、过滤哨兵、检查条件、更新计数。列表中的每个数字导致一次迭代,因此迭代次数等于输入长度(减哨兵),这已是高效,无法再减少。

One improvement would be to add an input validation step. Currently, if the user accidentally enters a non-integer, the RECEIVE statement would fail. A more robust version could first check if the input is numeric (where the language supports it) and display an error message, prompting the user to re-enter. This makes the program user-friendly and less prone to crashes.

一项改进是增加输入验证。目前,如果用户不小心输入非整数,RECEIVE 语句会失败。更稳健的版本可先用(语言支持的)方式检查输入是否为数值,若有误则显示错误信息并提示重新输入。这使程序对用户更友好,不易崩溃。


9. Algorithm Trace and State Maintenance | 算法跟踪与状态维护

Extra quick task: Use a trace table to illustrate how the variables change when the sequence 3, -2, 7, -1 is fed into the algorithm from Q6. This reinforces testing skills.

附加小任务: 用跟踪表说明将序列 3, -2, 7, -1 输入第6题算法后变量如何变化。这能强化测试技能。

InputnumposCountoddCountCondition check
–000Initial
3311>0 (yes), odd (yes)
-2-211>0 (no), even (no change)
7722>0 (yes), odd (yes)
-1-122Sentinel, exit loop

The trace confirms that -1 is excluded and the counts are correct. Practising trace tables is essential for debugging and understanding algorithm execution.

跟踪表确认 -1 被排除,计数正确。练习制作跟踪表对调试和理解算法执行至关重要。


Published by TutorHao | Computing Revision Series | aleveler.com

广告 / Sponsored
Linux高级程序设计(高等院校计算机技术十二五规划教材)/刘加海/季江民/浙江大学出版社
计算机 备考教辅 · 正版现货 · 与本文内容相关
查看详情 / View on Taobao参考价 ¥55.6

更多咨询请联系16621398022(同微信)

备考资讯每日更新,关注不错过
考纲变化 · 科目分析 · 学习方法
扫码关注公众号 tutorhao
在微信里长按二维码识别关注
或截图后用「扫一扫 → 相册」选择本图
公众号:tutorhao