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

A-Level Edexcel Programming: Operators, Control Structures and OOP | A-Level Edexcel 编程:运算符、控制结构与面向对象

2026-08-29 15:00 · 本文部分内容由AI辅助创作

📚 A-Level Edexcel Programming: Operators, Control Structures and OOP | A-Level Edexcel 编程:运算符、控制结构与面向对象

Programming is the backbone of the Edexcel A-Level Computer Science specification, and Paper 2 rewards candidates who can express algorithms clearly in the exam board's own pseudocode. This guide walks through data types, operators, selection, iteration, subroutines, file handling and object-oriented programming, using the exact vocabulary and structures the mark scheme expects.

编程是 Edexcel A-Level 计算机科学课程的主干,Paper 2 尤其奖励那些能用考试局规定的伪代码清晰表达算法的考生。本文系统梳理数据类型、运算符、选择结构、迭代结构、子程序、文件处理与面向对象编程,并使用评分标准所期待的确切术语与结构。


1. Data Types and Variables | 数据类型与变量

Every value in a program belongs to a data type, and every variable must be declared with a name and a type before it is used. The most common primitive types tested by Edexcel are integer, real, Boolean, character and string. A constant, declared with CONST, stores a value that cannot be changed while the program is running.

程序中的每个值都属于某种数据类型,每个变量在使用前都必须用名称和类型进行声明。Edexcel 考查的最常见原始类型包括整型、实数型、布尔型、字符型和字符串型。用 CONST 声明的常量,在程序运行期间其值不能被修改。

Type | 类型 Meaning | 含义 Example | 示例
Integer whole numbers | 整数 -3, 0, 42
Real decimal numbers | 小数 3.14, -0.001
Boolean two logical states | 两种逻辑状态 TRUE, FALSE
Character a single symbol | 单个符号 'a', '7'
String a sequence of characters | 字符序列 'hello'

Variables are named storage locations held in main memory. You should declare them with a name and type before use, for example DECLARE age AS INTEGER. Choosing the wrong type wastes memory or causes a runtime error, such as storing 3.5 in an integer field.

变量是主存中命名的存储位置。你应该在使用前用名称和类型声明它们,例如 DECLARE age AS INTEGER。选错类型会浪费内存或引发运行时错误,例如把 3.5 存入整型字段。

RING are needed when input from a keyboard arrives as text but must be used in arithmetic.

像 totalMark 这样有意义的标识符远好于单个字母;当键盘输入的文本需要参与运算时,就必须使用 STRING_TO_INT 或 INT_TO_STRING 之类的类型转换函数。


2. Operators: Arithmetic, Relational and Boolean | 运算符:算术、关系与布尔

Edexcel divides operators into three families. Arithmetic operators produce numbers, relational operators produce Boolean values, and Boolean operators combine Boolean values. You must know the difference between division, DIV and MOD, because exam questions often ask for the remainder of a calculation.

Edexcel 把运算符分为三大类:算术运算符产生数值,关系运算符产生布尔值,布尔运算符则组合布尔值。你必须分清除法、DIV 与 MOD 的区别,因为考题经常要求计算余数。

17 DIV 5 = 3     17 MOD 5 = 2     17 / 5 = 3.4

seudocode answers, including the concatenation operator & and the exponent operator ^.

下表总结了你在伪代码作答中需要识别并使用的运算符,包括连接运算符 & 和乘方运算符 ^。

Category | 类别 Operators | 运算符
Arithmetic | 算术 +   -   *   /   DIV   MOD   ^
Relational | 关系 =   <>   <   >   &lt;=   &gt;=
Boolean | 布尔 AND   OR   NOT
String | 字符串 & (concatenation | 连接)

A common exam trap is confusing assignment with comparison. In Edexcel pseudocode the left arrow, as in total ← total + 1, assigns a value, while a single equals sign inside an IF statement tests equality.

常见的考试陷阱是混淆赋值与比较。在 Edexcel 伪代码中,左箭头如 total ← total + 1 表示赋值,而 IF 语句中的单个等号表示判断是否相等。


3. Operator Precedence and Expression Evaluation | 运算符优先级与表达式求值

Expressions are evaluated in a fixed order, and getting that order wrong is one of the most frequent causes of lost marks in trace questions. Brackets are always evaluated first, followed by exponentiation, then multiplication, division, DIV and MOD, then addition and subtraction.

表达式按固定顺序求值,弄错顺序是追踪题失分最常见的原因之一。括号最先计算,其次是乘方,然后是乘法、除法、DIV 与 MOD,最后是加法与减法。

( ) → ^ → * / DIV MOD → + - → = <> < > &lt;= &gt;= → NOT → AND → OR

Consider the expression 3 + 4 * 2. Because multiplication binds more tightly than addition, the result is 11, not 14. Adding brackets changes the meaning completely: (3 + 4) * 2 gives 14. Working through the trace table step by step protects you from careless errors.

以表达式 3 + 4 * 2 为例。由于乘法优先级高于加法,结果是 11 而不是 14。加上括号会完全改变含义:(3 + 4) * 2 等于 14。按步骤填写追踪表可以避免粗心错误。

Boolean expressions follow the same logic: NOT is applied before AND, and AND before OR. De Morgan's laws, in which NOT (A AND B) is equivalent to (NOT A) OR (NOT B), appear in questions about simplifying logic conditions.

布尔表达式遵循同样的逻辑:NOT 先于 AND 运算,AND 先于 OR。德摩根定律中,NOT (A AND B) 等价于 (NOT A) OR (NOT B),常出现在化简逻辑条件的题目里。


4. String Handling and Built-in Functions | 字符串处理与内置函数

String manipulation is examined almost every year. You should be able to use LENGTH, SUBSTRING, LEFT, RIGHT, UPPER, LOWER, ASC and CHR, and to explain that string indexing in Edexcel pseudocode usually starts at position 1.

字符串操作几乎每年必考。你应该会使用 LENGTH、SUBSTRING、LEFT、RIGHT、UPPER、LOWER、ASC 和 CHR,并能说明 Edexcel 伪代码中的字符串索引通常从位置 1 开始。

SUBSTRING('COMPUTER', 4, 3) = 'PUT'     LENGTH('hello') = 5

Character codes matter too. ASC returns the numeric code of a character and CHR performs the reverse, which is how a program can convert 'A' to 'a' by adding 32 in ASCII. Validation routines for passwords or postcodes rely on these functions plus LENGTH checks.

字符编码同样重要。ASC 返回字符的数字编码,CHR 则执行相反操作,程序正是通过把 ASCII 中的 'A' 加 32 得到 'a'。密码或邮编的验证程序就依赖这些函数以及 LENGTH 检查。

When concatenating, remember that joining a string to a number requires conversion first, otherwise the pseudocode is type-unsafe and will not gain the mark: output 'Total: ' & INT_TO_STRING(total).

进行连接时请注意,字符串与数字相加必须先转换类型,否则伪代码类型不安全,无法得分:output 'Total: ' & INT_TO_STRING(total)。


5. Selection: IF, ELSEIF and CASE | 选择结构:IF、ELSEIF 与 CASE

Selection allows a program to follow different paths depending on a condition. The basic form is IF ... THEN ... ELSE ... ENDIF, and multiple branches use ELSEIF. Every IF must be closed by exactly one ENDIF, and indentation is expected so the structure is readable.

选择结构让程序根据条件走不同分支。基本形式是 IF ... THEN ... ELSE ... ENDIF,多分支则使用 ELSEIF。每个 IF 必须由唯一一个 ENDIF 闭合,并且要求缩进书写以保持结构清晰。

Where a single variable is compared with several possible constant values, a CASE statement is clearer and often earns a mark for efficiency. CASE ... OF ... OTHERWISE ... ENDCASE avoids a long chain of ELSEIF lines.

当同一个变量需要与多个可能的常量值比较时,CASE 语句更清晰,并常因效率更高而得分。CASE ... OF ... OTHERWISE ... ENDCASE 避免了冗长的 ELSEIF 链条。

Nested selection is used when a second test only makes sense after the first one passes, for example checking that a password is long enough before checking whether it contains a digit. Conditions can also be combined with AND and OR to reduce nesting.

当第二个判断必须建立在第一个判断成立的基础上时,就使用嵌套选择,例如先检查密码长度是否足够,再检查是否包含数字。条件也可以用 AND 与 OR 组合,以减少嵌套层数。


6. Iteration: Count-Controlled and Condition-Controlled Loops | 迭代结构:计数型循环与条件型循环

Iteration repeats a block of code. A count-controlled loop, written FOR i ← 1 TO 10 ... NEXT i, runs a known number of times and uses STEP to change the increment, for example STEP 2 for odd numbers.

迭代用于重复执行一段代码。计数型循环写作 FOR i ← 1 TO 10 ... NEXT i,执行次数已知,并可用 STEP 改变步长,例如用 STEP 2 处理奇数。

A condition-controlled loop runs while a test remains true. WHILE ... ENDWHILE tests the condition before the body, so the body may never run; REPEAT ... UNTIL tests after the body, so it always runs at least once. Choosing the wrong one is a classic exam error.

条件型循环在条件成立时持续执行。WHILE ... ENDWHILE 在循环体之前测试条件,因此循环体可能一次都不执行;REPEAT ... UNTIL 在循环体之后测试,因此至少执行一次。选错类型是经典考试错误。

WHILE test = TRUE    vs    REPEAT ... UNTIL test = TRUE

广告 / Sponsored

Every condition-controlled loop needs a line inside the body that changes the test variable, otherwise the program enters an infinite loop. When asked how many times a loop runs, calculate (final − initial) ÷ step + 1 for a count-controlled loop.

每个条件型循环的循环体内都必须有一行改变判断变量的语句,否则程序将陷入死循环。当被问到循环执行多少次时,计数型循环可用(终值 − 初值)÷ 步长 + 1 计算。


7. Subroutines, Parameters and Scope | 子程序、参数与作用域

A subroutine is a named block of code that performs one task and can be called repeatedly. A procedure performs an action, while a function returns a single value to the calling statement. Both reduce duplication and make programs easier to test and maintain.

子程序是完成单一任务、可被反复调用的具名代码块。过程执行一个动作,函数则向调用语句返回一个值。二者都能减少重复代码,并让程序更易于测试与维护。

Data is passed in through parameters. Passing by value copies the data, so changes inside the subroutine do not affect the original variable; passing by reference passes the address, so changes do affect the caller. Edexcel expects you to state which is safer and why.

数据通过参数传入。按值传递复制数据,子程序内的修改不影响原变量;按引用传递传递地址,修改会影响调用方。Edexcel 要求你说明哪种更安全以及原因。

Scope describes where a variable can be seen. Local variables exist only inside their subroutine, which prevents accidental interference; global variables are visible everywhere but make debugging harder. Recursion, in which a subroutine calls itself, always needs a base case to stop.

作用域描述变量在何处可见。局部变量只存在于其子程序内部,可防止意外干扰;全局变量处处可见,但会增加调试难度。递归即子程序调用自身,必须设置基线情形才能终止。


8. File Handling, Validation and Exception Handling | 文件处理、验证与异常处理

Programs often must persist data beyond a single run. In pseudocode this means OPEN, READ, WRITE and CLOSE statements on a named text file, commonly processing one line at a time until an end-of-file condition is detected.

程序常需要把数据保存到本次运行之后。在伪代码中就是用 OPEN、READ、WRITE 和 CLOSE 语句操作具名文本文件,通常逐行处理,直到检测到文件结束条件。

Validation checks that data is reasonable, for example a range check, a length check, a presence check or a format check. Verification is different: it checks that data has been copied correctly, for instance by double entry or a parity check.

验证检查数据是否合理,例如范围检查、长度检查、存在性检查和格式检查。核对则不同,它检查数据是否被正确复制,例如双重输入或奇偶校验。

Test data should include normal, boundary, erroneous and extreme values, and exception handling with TRY ... CATCH allows a program to respond to errors such as a missing file instead of crashing.

测试数据应包含正常值、边界值、错误值和极端值;使用 TRY ... CATCH 的异常处理,可以让程序在文件缺失等错误发生时做出响应,而不是直接崩溃。


9. OOP Fundamentals: Classes, Objects, Attributes and Methods | 面向对象基础:类、对象、属性与方法

Object-oriented programming models a system as a collection of interacting objects. A class is the blueprint, defining the attributes and methods that every object of that class will have; an object is a specific instance created from that class at run time.

面向对象编程把系统建模为相互作用的对象集合。类是蓝图,定义该类每个对象都拥有的属性与方法;对象则是在运行时由该类创建的具体实例。

Attributes store the state of an object, such as name and balance, while methods define its behaviour, such as deposit(). A constructor is a special method that runs automatically when an object is instantiated and sets the initial values of its attributes.

属性存储对象的状态,例如 name 与 balance;方法定义其行为,例如 deposit()。构造方法是特殊方法,在对象实例化时自动运行,用于设置属性的初始值。

CLASS Account   ATTRIBUTES   balance : REAL   METHODS   deposit(amount)

In the exam you may be asked to draw a UML class diagram or to write a class in pseudocode, showing the class name, the attribute list with types, and the method signatures with parameters and return types.

考试中可能要求你绘制 UML 类图或用伪代码编写一个类,需写出类名、带类型的属性列表,以及带参数和返回类型的方法签名。


10. Encapsulation, Inheritance, Polymorphism and Aggregation | 封装、继承、多态与聚合

Encapsulation hides an object's attributes behind private access and exposes only public methods, so external code cannot put the object into an invalid state. Getter and setter methods control how values are read and changed, and validation can be built into the setter.

封装通过私有访问隐藏对象属性,只暴露公有方法,使外部代码无法让对象进入无效状态。取值方法与设值方法控制数值的读取与修改,且可在设值方法中内建验证。

Inheritance lets a subclass reuse the attributes and methods of a superclass, adding or overriding behaviour. A subclass inherits everything public or protected from its parent and can override a method to give a more specific version.

继承让子类复用父类的属性与方法,并可新增或覆盖行为。子类继承父类所有公有或受保护成员,并可覆盖某方法以提供更具体的实现。

Polymorphism means the same method call behaves differently depending on the object's class; the program decides at run time which version to execute. Aggregation describes a 'has-a' relationship, where one object contains references to other objects.

多态指同一方法调用会因对象所属类而表现不同,程序在运行时决定执行哪个版本。聚合描述的是 'has-a'(拥有)关系,即一个对象包含对其他对象的引用。

Concept | 概念 Key idea | 核心要点
Encapsulation | 封装 private attributes, public methods | 私有属性、公有方法
Inheritance | 继承 subclass reuses superclass | 子类复用父类
Polymorphism | 多态 same call, different behaviour | 同一调用,不同行为
Aggregation | 聚合 object contains objects | 对象包含对象

11. Writing Pseudocode in the Exam | 考试中的伪代码写作

Marks in Paper 2 are awarded for structure and logic rather than syntax. Always declare variables and constants at the top, use the left arrow for assignment, indent inside every structure, and close loops and selection blocks correctly.

Paper 2 的分数主要给结构与逻辑,而不是语法。务必在开头声明变量与常量,用左箭头表示赋值,在每个结构内部缩进,并正确闭合循环与选择块。

Trace tables are the standard way to show working. Create one column per variable, follow the code line by line, and update values after every assignment so the examiner can see your reasoning.

追踪表是展示解题过程的标准方式。为每个变量建一列,逐行执行代码,并在每次赋值后更新数值,让评分者看到你的推理过程。

When asked to write an algorithm, answer in the exam board's pseudocode: FOR ... NEXT, WHILE ... ENDWHILE, IF ... THEN ... ELSE ... ENDIF. Python-style print() or curly braces may lose structure marks even if the logic is right.

当被要求编写算法时,请使用考试局的伪代码风格:FOR ... NEXT、WHILE ... ENDWHILE、IF ... THEN ... ELSE ... ENDIF。即使逻辑正确,Python 风格的 print() 或大括号也可能失去结构分。


12. Common Errors and Mark Scheme Keywords | 常见错误与评分关键词

Typical lost marks include using a single equals sign for assignment, forgetting ENDIF or NEXT, failing to increment a loop counter, and mixing up DIV with MOD. Another frequent error is treating a character as a string, or forgetting that indexing starts at 1.

典型失分包括用单个等号赋值、忘记写 ENDIF 或 NEXT、未对循环计数器递增,以及混淆 DIV 与 MOD。另一个高频错误是把字符当作字符串处理,或忘记索引从 1 开始。

In written answers, use the mark scheme vocabulary precisely: state, describe, explain and discuss demand different depths of response. 'State' needs one fact, while 'explain' needs a cause-and-effect chain using words such as because, therefore and so that.

在文字作答中,要精确使用评分标准词汇:state、describe、explain 与 discuss 要求的作答深度不同。'state' 只需一个事实,而 'explain' 需要因果链条,要使用 because、therefore、so that 等连接词。

Finally, link every programming answer back to the scenario in the question. Using identifiers and values from the given context, such as a named file or variable, shows the examiner that your solution is applied rather than generic.

最后,要把每个编程答案与题目情境联系起来。使用题干中给出的标识符与数值,例如指定的文件名或变量名,能向评分者表明你的解答是"应用型"的,而非套用通用模板。


Published by TutorHao | A-Level 编程 Revision Series | aleveler.com

广告 / Sponsored
之了课堂官方2027年初级会计职称师三色笔记学霸高频考点速口诀汇编重资料书电子版密押必刷题库实务教材马勇网课讲义202…
会计 备考教辅 · 正版现货 · 学习备考通用
查看详情 / View on Taobao
广告 / Sponsored
英文原版 The Cambridge Companion to Mendelssohn 剑桥门德尔松研究指南 剑桥音乐…
音乐 备考教辅 · 正版现货 · 学习备考通用
查看详情 / View on Taobao

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

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