📚 Edexcel A-Level Programming: Core Techniques and Algorithms | Edexcel A-Level 编程:核心技术与算法
Programming is at the heart of the Edexcel A-Level Computer Science course. This article consolidates the core techniques you must be able to read, write, trace, and debug: data types, control flow, arrays, subroutines, recursion, file handling, and searching and sorting algorithms.
编程是 Edexcel A-Level 计算机科学课程的核心。本文整合了你必须能够阅读、编写、跟踪和调试的核心技术:数据类型、控制流、数组、子程序、递归、文件处理以及查找和排序算法。
Each section gives you the key ideas in clear pseudocode style, with paired English and Chinese explanations so you can revise actively and apply the techniques under exam conditions.
每一节都以清晰的伪代码风格给出关键思想,并配有英文和中文对照解释,让你能够在考试条件下主动复习并应用这些技术。
1. Programming Fundamentals and Data Types | 编程基础与数据类型
Every program manipulates data, and Edexcel expects you to recognise primitive data types: integer, real/float, Boolean, character, and string. You should also know how to declare them in pseudocode and how type errors occur.
每个程序都操作数据,Edexcel 要求你识别基本数据类型:整数、实数/浮点数、布尔、字符和字符串。你还需要知道如何在伪代码中声明它们以及类型错误是如何发生的。
Use INTEGER for whole numbers, REAL for decimals, BOOLEAN for TRUE/FALSE values, CHAR for one character, and STRING for sequences of characters. Type compatibility matters when comparing or assigning values.
整数用 INTEGER,小数用 REAL,真/假值用 BOOLEAN,单个字符用 CHAR,字符序列用 STRING。在比较或赋值时,类型兼容性非常重要。
For example, assigning a real value to an integer variable without conversion may cause data loss or a type error. Edexcel pseudocode usually requires explicit type in declarations such as DECLARE age : INTEGER.
例如,在不进行转换的情况下将实数值赋给整数变量可能会导致数据丢失或类型错误。Edexcel 伪代码通常要求在声明中明确类型,例如 DECLARE age : INTEGER。
2. Variables, Constants, and Scope | 变量、常量与作用域
Variables store values that can change during execution, while constants hold fixed values. In pseudocode, declare constants with CONST and variables with a type. Scope refers to where an identifier is accessible: local variables exist inside a procedure, whereas global variables can be accessed throughout the program.
变量存储在执行过程中可改变的值,而常量保存固定的值。在伪代码中,用 CONST 声明常量,用类型声明变量。作用域指标识符可以访问的位置:局部变量存在于过程内部,而全局变量可被整个程序访问。
Using global variables excessively makes debugging harder and can introduce side effects. Edexcel code often uses parameter passing instead of relying on globals.
过度使用全局变量会给调试带来困难,并可能引入副作用。Edexcel 代码通常使用参数传递而不是依赖全局变量。
Always initialise variables before use. The scope of a loop variable, for example FOR i ← 1 TO 10, is normally limited to the loop block in pseudocode.
始终在使用变量之前初始化它们。循环变量的作用域,例如 FOR i ← 1 TO 10,在伪代码中通常仅限于循环块内。
3. Operators and Expressions | 运算符与表达式
Arithmetic operators such as +, -, ×, ÷, MOD, DIV, and exponentiation ^ are used to build expressions. Relational operators (=, ≠, <, >, ≤, ≥) compare values and return Boolean results. Logical operators AND, OR, NOT combine Boolean expressions.
算术运算符如 +、-、×、÷、MOD、DIV 和指数运算 ^ 用于构造表达式。关系运算符(=、≠、<、>、≤、≥)比较值并返回布尔结果。逻辑运算符 AND、OR、NOT 组合布尔表达式。
Operator precedence is essential: brackets first, then exponentiation, multiplication/division, integer division/mod, addition/subtraction, then relational and logical operators. Use brackets to make expressions clear and avoid ambiguity.
运算符优先级很重要:先括号,再指数,再乘除,再整数除法/取模,再加减,最后是关系和逻辑运算符。使用括号使表达式清晰并避免歧义。
Example: (3 + 2) × 4 DIV 2 – 1 = 9
示例:(3 + 2) × 4 DIV 2 – 1 = 9
4. Selection: IF and CASE | 选择结构:IF 与 CASE
Selection allows a program to take different paths. The IF statement tests a condition and executes a block when true; ELSE is optional. Nested IF statements can handle multiple conditions but can become hard to read.
选择结构允许程序采取不同路径。IF 语句测试条件,当条件为真时执行代码块;ELSE 可选。嵌套 IF 可以处理多个条件,但可读性可能变差。
The CASE statement is neater for several mutually exclusive values: CASE OF item: value1 → action1; value2 → action2; OTHERWISE → default; ENDCASE.
对于多个互斥的值,CASE 语句更简洁:CASE OF item: 值1 → 操作1;值2 → 操作2;OTHERWISE → 默认;ENDCASE。
Always test selection with boundary values just above and below the threshold, because programming errors often occur at the exact boundary of a condition such as IF score > 60.
始终使用恰好高于和低于阈值的边界值测试选择结构,因为编程错误通常发生在条件的精确边界处,例如 IF score > 60。
5. Iteration: FOR, WHILE, REPEAT | 迭代:FOR、WHILE、REPEAT
Iteration repeats code. A count-controlled loop uses FOR: FOR i ← 1 TO 10 ... ENDFOR. The loop variable must not be modified inside the loop.
迭代重复执行代码。计数控制循环使用 FOR:FOR i ← 1 TO 10 ... ENDFOR。循环变量不能在循环内部被修改。
Condition-controlled loops include WHILE (test at top) and REPEAT…UNTIL (test at bottom). WHILE may not execute if the condition is false initially; REPEAT always executes at least once.
条件控制循环包括 WHILE(顶部测试)和 REPEAT…UNTIL(底部测试)。如果初始条件为假,WHILE 可能不执行;REPEAT 至少执行一次。
Choose the correct loop for the problem; using the wrong type often causes logic errors such as infinite loops or off-by-one errors. Trace tables help you check loop termination.
为问题选择正确的循环类型;使用错误的类型通常会导致逻辑错误,如无限循环或差一错误。跟踪表可帮助你检查循环终止。
6. Arrays and Lists | 数组与列表
Arrays store multiple elements of the same data type under one identifier, using an index. In pseudocode, DECLARE scores : ARRAY[1:10] OF INTEGER creates a one-dimensional array with indices 1 to 10.
数组在同一个标识符下存储多个相同数据类型的元素,使用索引访问。在伪代码中,DECLARE scores : ARRAY[1:10] OF INTEGER 创建一个索引为 1 到 10 的一维数组。
Two-dimensional arrays are useful for grids or tables. You must be able to traverse arrays using loops, find highest/lowest, sum elements, and swap values.
二维数组对于网格或表格很有用。你必须能够使用循环遍历数组、查找最高/最低值、求和以及交换值。
- One-dimensional access:
scores[3]— 一维访问:scores[3] - Two-dimensional access:
grid[row, column]— 二维访问:grid[row, column]
7. String Handling | 字符串处理
String manipulation occurs in many Edexcel questions: concatenation with + or &, length functions, substring extraction, character access, and case conversion. You may be asked to trace pseudocode that builds or modifies strings.
字符串操作出现在许多 Edexcel 题目中:使用 + 或 & 进行连接、长度函数、子串提取、字符访问和大小写转换。你可能会被要求跟踪构建或修改字符串的伪代码。
A common task is to check if a string is a palindrome or to remove vowels. Make sure you can iterate character by character and build a new string.
常见任务是检查字符串是否为回文
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课程辅导,国外大学本科硕士研究生博士课程论文辅导