📚 Programming Constructs, Data Structures and Algorithms for Edexcel A Level | Edexcel A Level 编程构造、数据结构与算法
Programming is the heart of Edexcel A Level Computer Science Topic 6: Problem Solving with Programming. You need to master core constructs, data structures, algorithm design and testing if you want to score well on both the written examination and the non-exam assessment.
编程是 Edexcel A Level 计算机科学主题 6「用编程解决问题」的核心。如果你想在笔试和非考试评估中都取得好成绩,就必须掌握核心构造、数据结构、算法设计和测试。
1. Programming fundamentals and Edexcel expectations | 编程基础与 Edexcel 考试要求
Edexcel does not prescribe a single language, but most centres use Python, Java or C#. Exam questions use a clear pseudocode style so your answers can be written independently of any one syntax. You should be able to read, trace and write algorithms in pseudocode.
Edexcel 并不指定某一种编程语言,但大多数学校使用 Python、Java 或 C#。考试题使用清晰的伪代码风格,因此你的答案可以独立于具体语法。你应当能够阅读、跟踪并编写伪代码算法。
Marks are awarded for correct logic, appropriate use of constructs, and clear variable naming, not for memorising a particular API. Keep your pseudocode simple, with indentation to show blocks. The examiner expects a consistent style, so choose one convention and stick to it.
得分点在于正确的逻辑、恰当使用构造以及清晰的变量命名,而不是死记某种 API。写伪代码时要保持简洁,并用缩进表示代码块。考官期望风格一致,所以请选择一种约定并始终遵循。
2. Variables, constants and data types | 变量、常量与数据类型
A variable is a named storage location whose value can change at runtime. A constant is similar but its value cannot change after initialisation. Edexcel pseudocode often uses CONSTANT for constants and plain assignment for variables.
变量是一个命名的存储位置,其值在运行时可以改变。常量类似,但初始化后值不能改变。Edexcel 伪代码通常用 CONSTANT 表示常量,用普通赋值表示变量。
Common data types include integer, real/float, Boolean, character and string. Some languages also support date/time and enumeration types. Choosing the correct type prevents logic errors and makes type checking possible before execution.
常见数据类型包括整数、实数/浮点数、布尔、字符和字符串。有些语言还支持日期/时间和枚举类型。选择正确的类型可以防止逻辑错误,并在执行前进行类型检查。
| Data type | 中文 | Example |
|---|---|---|
| Integer | 整数 | 42, -7 |
| Real / Float | 实数/浮点数 | 3.14, -0.5 |
| Boolean | 布尔 | TRUE, FALSE |
| Character | 字符 | ‘A’, ‘5’ |
| String | 字符串 | “hello” |
Always initialise variables before reading them. Uninitialised variables can hold garbage values in some languages, leading to unpredictable behaviour that is hard to debug.
读取变量之前务必初始化。未初始化的变量在某些语言中可能保存垃圾值,导致难以调试的不可预测行为。
3. Operators and expression evaluation | 运算符与表达式求值
Arithmetic operators include +, −, *, /, MOD and DIV. Integer division (DIV) and modulo (MOD) are tested frequently. For example, 17 DIV 5 gives 3 and 17 MOD 5 gives 2.
算术运算符包括 +、−、*、/、MOD 和 DIV。整数除法(DIV)和取模(MOD)经常出现在考试中。例如 17 DIV 5 结果是 3,17 MOD 5 结果是 2。
17 = 5 × 3 + 2 → 17 DIV 5 = 3 and 17 MOD 5 = 2
Comparison operators are =, ≠, <, >, ≤, ≥. Logical operators AND, OR and NOT combine conditions. Use parentheses to make compound expressions clear, especially when mixing AND and OR.
比较运算符有 =、≠、<、>、≤、≥。逻辑运算符 AND、OR 和 NOT 组合条件。使用括号使复合表达式更清晰,尤其是同时使用 AND 和 OR 时。
Operator precedence determines the order of evaluation: parentheses first, then division and multiplication, then addition and subtraction. Comparison operators have lower precedence than arithmetic, and logical operators are evaluated last.
运算符优先级决定计算顺序:先括号,再乘除,后加减。比较运算符的优先级低于算术运算符,逻辑运算符最后计算。
4. Selection and conditional logic | 选择结构与条件逻辑
Selection allows a program to take different paths based on a condition. The simplest form is IF…THEN…ELSE…ENDIF. Edexcel accepts ELSE IF or ELIF for multiple branches.
选择结构允许程序根据条件执行不同路径。最简单的形式是 IF…THEN…ELSE…ENDIF。Edexcel 接受使用 ELSE IF 或 ELIF 表示多个分支。
A CASE or SWITCH statement is useful when one variable can take several discrete values. It often produces clearer code than nested IF statements, because each case is separate and the structure is easier to read.
当一个变量可以取多个离散值时,CASE 或 SWITCH 语句很有用。它通常比嵌套 IF 语句更清晰,因为每个分支都是独立的,结构更容易阅读。
Always test boundary conditions: for age ≥ 18, test 17, 18 and 19 to confirm the branch behaves correctly. Off-by-one errors are common and cost marks in exams.
务必测试边界条件:比如 age ≥ 18 时,测试 17、18 和 19,以确认分支行为正确。差一错误非常常见,在考试中会丢分。
5. Definite and indefinite iteration | 确定与不确定迭代
Definite iteration uses a FOR loop, executed a known number of times. In pseudocode: FOR i ← 1 TO 10 … NEXT i. Note the left arrow for assignment is common in Edexcel papers.
确定迭代使用 FOR 循环,执行已知次数。伪代码写法:FOR i ← 1 TO 10 … NEXT i。注意 Edexcel 试卷中常用左箭头表示赋值。
Indefinite iteration uses WHILE or REPEAT…UNTIL. A WHILE loop checks the condition before each pass; a REPEAT loop checks after, so it runs at least once. Choose WHILE when the body may be skipped entirely.
不确定迭代使用 WHILE 或 REPEAT…UNTIL。WHILE 循环在每次执行前检查条件;REPEAT 循环在执行后检查,因此至少运行一次。当循环体可能完全跳过时,选择 WHILE。
Every loop must have a reachable exit. Consider counting variables, sentinel values or flags to avoid infinite loops. In an exam, a missing loop exit is a serious logic error.
每个循环必须有可达的退出条件。考虑使用计数变量、哨兵值或标志,避免死循环。在考试中,缺少循环出口是严重的逻辑错误。
6. Subroutines: procedures, functions and parameters | 子程序:过程、函数与参数
Procedures perform a task but do not return a value. Functions return a value. Both can accept parameters by value or by reference. By value copies the data; by reference passes the address, allowing modification.
过程执行任务但不返回值。函数返回一个
Published by TutorHao | A-Level 编程 Revision Series | aleveler.com
更多咨询请联系16621398022(同微信)
屏轩国际教育cambridge primary/secondary checkpoint, cat4, ukiset,ukcat,igcse,alevel,PAT,STEP,MAT, ibdp,ap,ssat,sat,sat2课程辅导,国外大学本科硕士研究生博士课程论文辅导