📚 A-Level Programming Fundamentals: Data, Logic and Algorithms | Edexcel A-Level 编程基础:数据、逻辑与算法
This guide covers the core programming skills assessed in the Edexcel A-Level Computer Science specification. You will revise data types, control structures, functions, arrays, file handling, error handling, algorithm analysis and exam strategies. The focus is on writing accurate pseudocode and understanding how code behaves at runtime.
本指南涵盖 Edexcel A-Level 计算机科学考试中评估的核心编程技能。你将复习数据类型、控制结构、函数、数组、文件处理、错误处理、算法分析和考试策略。重点在于编写准确的伪代码,并理解代码在运行时的行为。
1. Data Types and Variables | 数据类型与变量
Every value in A-Level programming belongs to a data type: integer, real, Boolean, character or string. Choosing the correct type determines the memory used and the operations available. For example, you cannot perform MOD on a real number in most pseudocode dialects.
在 A-Level 编程中,每个值都属于某种数据类型:整数、实数、布尔值、字符或字符串。选择正确的类型决定内存使用和可用的操作。例如,在大多数伪代码方言中,不能对实数执行 MOD 运算。
You must distinguish between constants and variables. A constant does not change during execution, whereas a variable can be updated. Assignment is often shown with an arrow: total ← 0, not the equals sign. Using ‘=’ for comparison and ‘←’ for assignment avoids confusion in trace tables.
你必须区分常量和变量。常量在执行期间不改变,而变量可以更新。赋值通常用箭头表示:total ← 0,而不是等号。使用 “=” 表示比较、”←” 表示赋值可以避免在跟踪表中产生混淆。
| Data type | Example | Notes |
| Integer | 42 | Whole numbers only |
| Real / Float | 3.14159 | Decimal numbers |
| Boolean | TRUE or FALSE | Used in conditions |
| Char | ‘A’ | One character |
| String | “hello” | Sequence of characters |
A common error is treating the string “42” as an integer. In Edexcel pseudocode, data types matter when evaluating expressions, and exam questions often ask you to identify a type mismatch.
一个常见错误是将字符串 “42” 当作整数处理。在 Edexcel 伪代码中,数据类型在计算表达式时很重要,考试题经常要求你识别类型不匹配。
2. Operators and Expressions | 运算符与表达式
Operators combine values to produce a result. Arithmetic operators include +, -, *, /, MOD and DIV. MOD returns the remainder of integer division, while DIV returns the integer quotient. For example, 17 MOD 5 evaluates to 2, and 17 DIV 5 evaluates to 3.
运算符将值组合起来产生结果。算术运算符包括 +、-、*、/、MOD 和 DIV。MOD 返回整数除法的余数,DIV 返回整数商。例如,17 MOD 5 的计算结果为 2,17 DIV 5 的计算结果为 3。
Comparison operators produce Boolean values: =, <, >, <=, >= and <>. Boolean operators AND, OR and NOT follow precedence rules. In most pseudocode, NOT has highest priority, then AND, then OR. Parentheses should be used to make logic unambiguous.
比较运算符产生布尔值:=、<、>、<=、>= 和 <>。布尔运算符 AND、OR 和 NOT 遵循优先级规则。在大多数伪代码中,NOT 具有最高优先级,然后是 AND,最后是 OR。应使用括号使逻辑明确。
x ← (a > b) AND (c < d)
In a trace table, you must show the intermediate Boolean results. For example, if a = 5, b = 3, c = 8 and d = 10, then the expression above evaluates to TRUE AND TRUE, which gives TRUE.
在跟踪表中,你必须显示中间的布尔结果。例如,如果 a = 5、b = 3、c = 8、d = 10,则上面的表达式计算为 TRUE AND TRUE,结果为 TRUE。
3. Selection Statements | 选择语句
Selection statements allow a program to take different paths based on a condition. The basic form is IF condition THEN … ELSE … ENDIF. In Edexcel pseudocode, the ELSE branch is optional. Each branch must be indented consistently to show structure.
选择语句允许程序根据条件选择不同的执行路径。基本形式是 IF 条件 THEN … ELSE … ENDIF。在 Edexcel 伪代码中,ELSE 分支是可选的。每个分支必须一致缩进以显示结构。
A multi-way selection can be written with nested IF statements or a CASE statement. The CASE statement compares a variable against multiple values and runs the matching block. For example:
多路选择可以用嵌套 IF 语句或 CASE 语句编写。CASE 语句将变量与多个值进行比较,并运行匹配的块。例如:
CASE grade OF
‘A’: PRINT “Excellent”
‘B’: PRINT “Good”
‘C’: PRINT “Pass”
OTHERWISE: PRINT “Fail”
ENDCASE
When tracing selection, make sure the condition is evaluated before updating variables. If a variable is changed inside a branch, subsequent statements use the new value. A missing ENDIF or ENDCASE is a common syntax error.
在跟踪选择语句时,务必先计算条件再更新变量。如果变量在分支内被改变,后续语句将使用新值。缺少 ENDIF 或 ENDCASE 是常见的语法错误。
4. Iteration and Loops | 迭代与循环
Iteration repeats a block of code. Edexcel pseudocode uses three main loop types: FOR … TO … NEXT, WHILE … DO … ENDWHILE and REPEAT … UNTIL. Each has a different check timing and use case.
迭代会重复一段代码。Edexcel 伪代码使用三种主要循环类型:FOR … TO … NEXT、WHILE … DO … ENDWHILE 和 REPEAT … UNTIL。每种循环的检查时机和用途不同。
A FOR loop runs a fixed number of times. It is ideal when you know the maximum count. A WHILE loop tests the condition before each iteration, so it may run zero times. A REPEAT loop tests after each iteration, so the body always runs at least once.
FOR 循环运行固定次数,适合已知最大次数的情况。WHILE 循环在每次迭代之前测试条件,因此可能运行零次。REPEAT 循环在每次迭代之后测试,因此循环体至少运行一次。
In trace tables, include a column for the loop counter and the condition result. For example, a WHILE loop with condition count < 5 stops when count becomes 5. If the condition never becomes FALSE, the loop is infinite.
在跟踪表中,要为循环计数器和条件结果设置列。例如,条件为 count < 5 的 WHILE 循环在 count 变为 5 时停止。如果条件永远不为 FALSE,则循环是无限循环。
5. Functions and Procedures | 函数与过程
A function returns a single value, while a procedure performs a task without returning a value. In Edexcel pseudocode, a function uses RETURN to send a result back to the caller. A procedure can change variables through parameters passed by reference.
函数返回单个值,而过程执行任务但不返回值。在 Edexcel 伪代码中,函数使用 RETURN 将结果发送回调用者。过程可以通过按引用传递的参数修改变量。
Parameters can be passed by value or by reference. By value means a copy is used, so changes inside the subprogram do not affect the original variable. By reference means the original memory location is used, so changes are visible outside.
参数可以按值传递或按引用传递。按值传递意味着使用副本,因此子程序内部的更改不影响原始变量。按引用传递意味着使用原始内存位置,因此更改在外部可见。
When writing functions, choose meaningful names and state the parameter list clearly. For example, FUNCTION getLarger(a, b) could return the larger value. Modular programming reduces duplication and makes code easier to test.
编写函数时,应选择有意义的名称并清晰说明参数列表。例如,FUNCTION getLarger(a, b) 可以返回较大的值。模块化编程减少重复,使代码更易于测试。
6. Arrays and Data Structures | 数组与数据结构
A one-dimensional array stores multiple elements of the same type at consecutive indexes. The first index is often 0 or 1 depending on the question. A two-dimensional array is useful for tables, grids and matrices.
一维数组在连续索引中存储多个相同类型的元素。根据题目,第一个索引通常是 0 或 1。二维数组适用于表格、网格和矩阵。
Records group related fields of different types. For example, a student record might contain name (string), age (integer) and grade (char). Lists are dynamic structures that can grow or shrink, unlike fixed-size arrays.
记录将不同类型的相关字段组合在一起。例如,学生记录可能包含姓名(字符串)、年龄(整数)和成绩(字符)。列表是动态结构,可以增长或缩小,这与固定大小的数组不同。
| Structure | Use case | Key feature |
| 1D array | List of marks | Fixed size |
| 2D array | Chess board | Rows and columns |
| Record | Customer details | Mixed types |
You should be able to read from and write to array elements using index notation, such as marks[3] ← 87. In a two-dimensional array, the notation grid[row, col] is common.
你应该能够使用索引表示法读写数组元素,例如 marks[3] ← 87。在二维数组中,通常使用 grid[row, col] 表示法。
7. File Input and Output | 文件输入与输出
File handling allows a program to read from or write to external files. Text files contain plain characters, while binary files store data in a non-human-readable format. Edexcel questions often focus on text files with one record per line.
文件处理允许程序读取或写入外部文件。文本文件包含纯字符,而二进制文件以非人类可读的格式存储数据。Edexcel 考试题通常关注每行一条记录的文本文件。
Before reading, the file must be opened. After use, it should be closed. In pseudocode, a loop may read until the end of the file is reached: WHILE NOT EOF(file). This prevents attempts to read beyond the last record.
读取之前必须打开文件。使用后应关闭文件。在伪代码中,循环可以读取到文件末尾:WHILE NOT EOF(file)。这样可以防止尝试读取最后一条记录之外的内容。
When writing to a file, the mode matters. Appending adds new data to the end, while writing creates or overwrites the file. Exam questions may ask you to trace how a file changes after a series of operations.
写入文件时,模式很重要。追加模式将新数据添加到文件末尾,而写入模式会创建或覆盖文件。考试题可能要求你跟踪文件在一系列操作后的变化。
8. Error Handling and Debugging | 错误处理与调试
Errors are classified as syntax errors, runtime errors or logic errors. A syntax error occurs when code breaks the language rules, such as a missing ENDIF. A runtime error occurs during execution, such as dividing by zero. A logic error produces a wrong result without crashing.
错误分为语法错误、运行时错误和逻辑错误。语法错误在代码违反语言规则时发生,例如缺少 ENDIF。运行时错误在执行期间发生,例如除以零。逻辑错误在不崩溃的情况下产生错误结果。
Debugging is the process of finding and fixing errors. Trace tables help you manually step through code to see variable changes. Breakpoints and print statements can also isolate bugs in real programming environments.
调试是查找并修复错误的过程。跟踪表可以帮助你手动逐步执行代码以查看变量变化。在实际编程环境中,断点和打印语句也可以隔离错误。
Testing should use normal, boundary and erroneous data. For a grade range 0-100, normal data might be 50, boundary data 0 and 100, and erroneous data -5 or 105. Good tests cover all three categories.
测试应使用正常数据、边界数据和错误数据。对于 0-100 的分数范围,正常数据可以是 50,边界数据是 0 和 100,错误数据是 -5 或 105。良好的测试覆盖所有三类。
9. Algorithms and Efficiency | 算法与效率
Algorithms are step-by-step procedures for solving problems. Common A-Level algorithms include linear search, binary search, bubble sort and insertion sort. You must be able to write pseudocode and compare their efficiency.
算法是解决问题的分步程序。A-Level 常见算法包括线性查找、二分查找、冒泡排序和插入排序。你必须能够编写伪代码并比较它们的效率。
Linear search checks each element in turn, so its worst-case time complexity is O(n). Binary search repeatedly halves the search space but requires a sorted array. Its worst-case complexity is O(log n).
线性查找逐个检查每个元素,因此其最坏情况时间复杂度为 O(n)。二分查找反复将查找范围减半,但要求数组已排序。其最坏情况复杂度为 O(log n)。
Bubble sort compares adjacent elements and swaps them if they are out of order. After one pass, the largest value moves to the end. Its worst-case and average-case complexity is O(n²). Insertion sort is often faster on partially sorted data.
冒泡排序比较相邻元素,如果顺序错误则交换它们。经过一趟后,最大值移动到末尾。其最坏情况和平均情况复杂度为 O(n²)。插入排序在部分有序的数据上通常更快。
Time complexity: O(1) < O(log n) < O(n) < O(n log n) < O(n²)
Big-O notation describes how the running time grows as the input size n increases. Constant O(1) means the time does not depend on n. Quadratic O(n²) means doubling the input roughly quadruples the time.
大 O 表示法描述运行时间如何随着输入规模 n 增长。常数 O(1) 表示时间与 n 无关。二次方 O(n²) 意味着输入增加一倍,时间大约增加四倍。
10. Exam Skills and Common Pitfalls | 考试技巧与常见误区
In the written exam, you may be asked to complete a trace table, write pseudocode or explain an algorithm. Start by identifying the inputs, outputs and variables. Then follow the code line by line, updating values accurately.
在笔试中,你可能被要求完成跟踪表、编写伪代码或解释算法。首先识别输入、输出和变量。然后逐行执行代码,准确更新值。
Common pitfalls include forgetting to initialise variables before use, using ‘=’ for assignment instead of ‘←’, missing loop termination, and mixing data types. Always check boundary conditions and the direction of comparison operators.
常见误区包括在使用变量前忘记初始化、将赋值写成 “=” 而不是 “←”、缺少循环终止条件以及混合数据类型。始终检查边界条件和比较运算符的方向。
When writing pseudocode, use consistent indentation and clear variable names. If a question says ‘write an efficient algorithm’, choose binary search over linear search when the data is sorted. Justify your choice using Big-O complexity.
编写伪代码时,使用一致的缩进和清晰的变量名。如果题目要求“编写高效算法”,当数据已排序时选择二分查找而不是线性查找。使用大 O 复杂度证明你的选择。
Finally, leave time to reread the question and verify that your pseudocode matches the specification. Marks are awarded for correct logic, not for perfect syntax. A small logic slip can lose several marks, so trace your own solution before moving on.
最后,留出时间重读题目并验证伪代码是否符合要求。分数是根据正确逻辑给出的,而不是完美语法。小的逻辑错误可能丢失好几分,所以在继续之前先跟踪一下自己的答案。
Published by TutorHao | Programming Revision Series | aleveler.com
更多咨询请联系16621398022(同微信)
屏轩国际教育cambridge primary/secondary checkpoint, cat4, ukiset,ukcat,igcse,alevel,PAT,STEP,MAT, ibdp,ap,ssat,sat,sat2课程辅导,国外大学本科硕士研究生博士课程论文辅导