📚 A-Level Edexcel Programming: Fundamentals, Algorithms and Object-Oriented Design | A-Level Edexcel 编程核心:基础、算法与面向对象设计
This revision guide covers the programming skills assessed in Pearson Edexcel A Level Computer Science, including data types, control structures, subroutines, recursion, searching and sorting algorithms, and object-oriented programming. Each section offers exam-focused explanations paired in English and Chinese.
本复习指南涵盖皮尔森爱德思 A Level 计算机科学考核的编程技能,包括数据类型、控制结构、子程序、递归、搜索与排序算法以及面向对象编程。每个小节都提供中英文对照的考点讲解。
1. Programming Paradigms | 编程范式
In Edexcel A Level Computer Science, you need to compare procedural, object-oriented, and event-driven programming. Procedural code is organised as a sequence of instructions and subroutines, while object-oriented programming models real-world entities as objects that combine state and behaviour.
在爱德思 A Level 计算机科学中,你需要比较过程式、面向对象和事件驱动编程。过程式代码按指令和子程序组织,而面向对象编程将现实世界实体建模为同时包含状态和行为的对象。
Procedural programming uses top-down design and modular decomposition. The problem is broken into functions and procedures, which makes complex programs easier to read, test, and maintain.
过程式编程采用自顶向下设计和模块化分解。问题被拆分成函数和过程,这使得复杂程序更容易阅读、测试和维护。
Event-driven programming responds to events such as button clicks, key presses, or timer ticks. It is commonly used in graphical user interfaces because the flow of execution is controlled by user actions rather than by a fixed sequence.
事件驱动编程响应按钮点击、按键或定时器触发等事件。它常用于图形用户界面,因为执行流程由用户操作控制,而不是由固定顺序控制。
- Procedural: top-down design, subroutines, global and local variables | 过程式:自顶向下设计、子程序、全局与局部变量
- Object-oriented: classes, objects, encapsulation, inheritance, polymorphism | 面向对象:类、对象、封装、继承、多态
- Event-driven: event loops, event handlers, GUI controls | 事件驱动:事件循环、事件处理程序、GUI 控件
2. Data Types and Variables | 数据类型与变量
Variables store values in memory, and each variable has a data type that determines its possible values and operations. Edexcel expects you to know integer, real or float, Boolean, character, string, date/time, and pointer or reference types.
变量在内存中存储值,每个变量都有决定其取值范围和操作的数据类型。爱德思要求你了解整型、实型或浮点型、布尔型、字符、字符串、日期/时间以及指针或引用类型。
Choosing the correct data type affects range, precision, memory usage, and the operations that can be performed. For example, integer division truncates the result, while real division keeps the fractional part.
选择正确的数据类型会影响范围、精度、内存使用以及可以执行的操作。例如,整数除法会截断结果,而实数除法保留小数部分。
Constants are named values that cannot be changed during program execution. They improve readability and prevent accidental modification of fixed values.
常量是在程序执行期间不能更改的命名值。它们可以提高可读性并防止意外修改固定值。
| Data type | Example | Typical use |
|---|---|---|
| Integer | 42 | Counts, indexes |
| Real / Float | 3.14 | Measurements, currency |
| Boolean | TRUE / FALSE | Conditions, flags |
| Character | ‘A’ | Single letters, symbols |
| String | “hello” | Text, names, messages |
| Date/Time | 2025-01-01 | Scheduling, timestamps |
3. Control Structures: Sequence, Selection, Iteration | 控制结构:顺序、选择、迭代
All algorithms can be built from three basic control structures: sequence, selection, and iteration. Sequence means statements are executed one after another in the order written.
所有算法都可以用三种基本控制结构构建:顺序、选择和迭代。顺序意味着语句按照编写顺序一条接一条执行。
Selection changes the flow based on a condition. Common selection statements include IF, ELSE IF, ELSE, and CASE or SWITCH. A CASE statement is useful when there are many mutually exclusive conditions.
选择根据条件改变流程。常见的选择语句包括 IF、ELSE IF、ELSE 以及 CASE 或 SWITCH。当存在多个互斥条件时,CASE 语句非常有用。
Iteration repeats a block of code. Count-controlled loops such as FOR run a known number of times, while condition-controlled loops such as WHILE and REPEAT…UNTIL run until a condition changes.
迭代重复执行一段代码。FOR 等计数控制循环运行已知次数,而 WHILE 和 REPEAT…UNTIL 等条件控制循环运行直到条件改变。
IF condition THEN statements ELSE statements ENDIF
WHILE condition DO statements ENDWHILE
A REPEAT…UNTIL loop always executes at least once because the condition is tested at the end. A WHILE loop may execute zero times because the condition is tested at the start.
REPEAT…UNTIL 循环至少执行一次,因为条件在末尾测试。WHILE 循环可能一次也不执行,因为条件在开头测试。
4. Subroutines, Parameters and Scope | 子程序、参数与作用域
Subroutines break a problem into manageable parts and support code reuse. A procedure performs a task without returning a value, while a function performs a task and returns a value.
子程序将问题分解为可管理的部分并支持代码重用。过程执行任务但不返回值,而函数执行任务并返回一个值。
Parameters allow data to be passed into a subroutine. Passing by value gives the subroutine a copy of the data, so changes do not affect the original variable. Passing by reference gives the subroutine access to the original variable, allowing it to modify the value.
参数允许将数据传入子程序。按值传递将数据副本交给子程序,因此更改不会影响原变量。按引用传递使子程序可以访问原变量,从而修改其值。
Local variables are declared inside a subroutine and exist only while the subroutine runs. Global variables are declared outside any subroutine and can be accessed throughout the program, but they increase the risk of side effects.
局部变量在子程序内部声明,只在子程序运行期间存在。全局变量在任何子程序之外声明,可以在整个程序中访问,但会增加副作用的风险。
Using local variables and parameters instead of global variables makes subroutines easier to test, reuse, and debug.
使用局部变量和参数而不是全局变量,可以使子程序更容易测试、重用和调试。
5. Recursion and Stack Frames | 递归与栈帧
A recursive subroutine calls itself. Every recursive algorithm must have a base case that stops the recursion and a recursive case that reduces the problem towards the base case.
递归子程序会调用自身。每个递归算法必须有一个停止递归的基准情形,以及一个将问题向基准情形推进的递归情形。
Each recursive call creates a stack frame containing its parameters and local variables. The call stack stores these frames until the base case is reached, then the calls unwind and return their results.
每次递归调用都会创建一个包含其参数和局部变量的栈帧。调用栈存储这些栈帧,直到达到基准情形,然后调用逐层返回结果。
n! = n × (n – 1)! , with 0! = 1
factorial(n): if n = 0 then return 1 else return n × factorial(n – 1)
If the base case is missing or unreachable, the recursion continues until the call stack overflows, causing a runtime error. Recursion is elegant for tree and graph problems, but iteration is often more memory-efficient.
如果缺少基准情形或基准情形无法达到,递归会一直持续,直到调用栈溢出,导致运行时错误。递归对于树和图问题非常优雅,但迭代通常更节省内存。
6. Arrays, Records and Lists | 数组、记录与列表
A one-dimensional array is an indexed collection of items of the same data type. Elements are accessed using an index, often starting at 0. Two-dimensional arrays form tables with rows and columns and use two indexes.
一维数组是相同数据类型的项的索引集合。元素通过索引访问,索引通常从 0 开始。二维数组形成有行和列的表,使用两个索引。
Records are user-defined data types that group fields of different types under one name. For example, a Student record may contain name as string, age as integer, and averageMark as real.
记录是用户定义的数据类型,将不同类型的字段组合在一个名称下。例如,Student 记录可以包含姓名为字符串、年龄为整数以及平均分为实数。
Lists are dynamic data structures that can grow and shrink during execution. They support insertion and deletion more flexibly than fixed-length arrays, although direct access by index may be slower depending on implementation.
列表是动态数据结构,可以在执行期间增长和缩小。它们比固定长度数组更灵活地支持插入和删除,不过根据实现方式,按索引直接访问可能较慢。
7. Stacks and Queues | 栈与队列
A stack is a last-in-first-out (LIFO) structure. The core operations are push, pop, peek, isEmpty, and isFull. The last item added is the first item removed.
栈是一种后进先出(LIFO)结构。核心操作是压入(push)、弹出(pop)、查看栈顶(peek)、判断空(isEmpty)和判断满(isFull)。最后加入的项最先被移除。
A queue is a first-in-first-out (FIFO) structure. The core operations are enqueue, dequeue, peek, isEmpty, and isFull. The first item added is the first item removed.
队列是一种先进先出(FIFO)结构。核心操作是入队(enqueue)、出队(dequeue)、查看队首(peek)、判断空(isEmpty)和判断满(isFull)。最先加入的项最先被移除。
St
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课程辅导,国外大学本科硕士研究生博士课程论文辅导