📚 Programming Constructs and Paradigms for Edexcel A-Level | Edexcel A-Level编程构造与范式
This revision guide covers the core programming constructs and paradigms assessed in the Edexcel A-Level Computer Science specification. Programming questions often ask you to read, trace and write code using sequence, selection, iteration, subroutines, parameter passing and object-oriented concepts. A clear understanding of how code executes helps you answer both Paper 1 theory questions and the practical programming component.
本复习指南涵盖Edexcel A-Level计算机科学考试大纲中的编程构造与编程范式。编程题常要求阅读、跟踪和编写使用顺序、选择、迭代、子程序、参数传递以及面向对象概念的代码。清晰理解代码的执行过程有助于解答Paper 1的理论题和编程实践部分。
1. Sequence, Selection and Iteration | 顺序、选择与迭代
Every program is built from three basic control structures: sequence, selection and iteration. Sequence means statements execute one after another; selection uses IF, ELSE IF and ELSE to make decisions; iteration repeats a block using FOR, WHILE or REPEAT...UNTIL loops. Edexcel pseudocode questions often mix these structures, so you must be able to read the flow of control line by line.
每个程序都由三种基本控制结构组成:顺序、选择和迭代。顺序表示语句逐条执行;选择使用IF、ELSE IF和ELSE做决策;迭代使用FOR、WHILE或REPEAT...UNTIL循环重复执行代码块。Edexcel伪代码题经常混合使用这些结构,因此你必须能够逐行阅读控制流程。
- Sequence:
INPUT x, y; total ← x + y - Selection:
IF score ≥ 60 THEN OUTPUT 'Pass' ELSE OUTPUT 'Retake' - Iteration:
FOR i ← 1 TO 10 OUTPUT i NEXT i
2. Data Types and Variables | 数据类型与变量
Edexcel expects you to know common data types: integer, real/float, Boolean, character and string. Variables are named storage locations whose values can change during execution; constants stay fixed after declaration to reduce "magic numbers" and make code easier to update. Choosing the right data type also affects memory usage and the operations available.
Edexcel要求掌握常见数据类型:整数、实数/浮点、布尔、字符和字符串。变量是命名的存储位置,其值在程序执行过程中可以改变;常量在声明后保持不变,可减少“魔法数字”并使代码更易于更新。选择正确的数据类型还会影响内存使用和可用的操作。
| Data type | Example value | Use |
| Integer | 42, -7 | Counting, indexing |
| Real/float | 3.14, -0.5 | Measurements, calculations |
| Boolean | TRUE, FALSE | Conditions, flags |
| Character | 'A', '7' | Single symbol |
| String | 'Hello' | Text handling |
3. Subroutines: Procedures and Functions | 子程序:过程与函数
A subroutine is a named block of code that can be called from elsewhere in a program. A procedure performs an action but does not return a value; a function returns a single value using RETURN. Dividing a program into subroutines improves readability, reusability and testing because each subroutine can be developed and checked separately.
子程序是可以从程序其他位置调用的命名代码块。过程执行操作但不返回值;函数通过RETURN返回一个值。将程序划分为子程序可提高可读性、可复用性并便于测试,因为每个子程序都可以单独开发和检查。
For example, a function calculateArea(radius) might return π × radius², while a procedure displayResult(area) only prints the value. Edexcel pseudocode questions may ask you to identify whether a subroutine should be a function or a procedure.
例如,函数 calculateArea(radius) 可以返回 π × radius²,而过程 displayResult(area) 只打印该值。Edexcel伪代码题可能要求你判断某个子程序应该是函数还是过程。
4. Parameter Passing by Value and Reference | 按值传递与按引用传递参数
Parameters allow data to be passed into subroutines. Passing by value copies the data, so changes inside the subroutine do not affect the original variable. Passing by reference passes the memory address, so changes inside the subroutine do affect the original variable. Edexcel expects you to trace both mechanisms and explain their effects.
参数允许将数据传入子程序。按值传递会复制数据,因此子程序内部的修改不会影响原变量。按引用传递传递的是内存地址,因此子程序内部的修改会影响原变量。Edexcel要求你跟踪这两种机制并解释其作用。
For example, if x = 5 is passed by value to addOne(x), the original x remains 5 after the call. If x is passed by reference, the original x becomes 6. This distinction is essential for understanding side effects and avoiding unintended changes.
例如,如果 x = 5 按值传递给 addOne(x),调用后原 x 仍为 5。如果 x 按引用传递,原 x 将变为 6。理解这一区别对于掌握副作用并避免意外修改至关重要。
5. Local and Global Variables | 局部变量与全局变量
Local variables are declared inside a subroutine and exist only while that subroutine is running. Global variables are declared at the top of the program and can be accessed anywhere. Overuse of global variables makes debugging difficult and can create side effects, so local variables are preferred for modular code. Edexcel trace questions often test whether a variable is accessible in a given scope.
局部变量在子程序内部声明,只在该子程序运行期间存在。全局变量在程序顶部声明,可以在任何位置访问。过度使用全局变量会增加调试难度并产生副作用,因此模块化代码更推荐使用局部变量。Edexcel跟踪题常测试某个变量在给定作用域内是否可访问。
A key exam point is that a local variable with the same name as a global variable shadows the global variable inside that subroutine. This means the local value is used, and the global value remains unchanged unless it is explicitly modified or passed by reference.
一个重要的考试要点是:如果局部变量与全局变量同名,在该子程序内部局部变量会遮蔽全局变量。这意味着使用的是局部值,全局值保持不变,除非显式修改或按引用传递。
6. Recursion | 递归
Recursion is when a subroutine calls itself. A recursive function must have a base case to stop and a recursive case that reduces the problem size. For example, the factorial function can be defined as factorial(0) = 1 and factorial(n) = n × factorial(n - 1) for n > 0. Recursion is elegant but can use more stack memory than iteration because each call creates a new stack frame.
递归是指子程序调用自身。递归函数必须有一个终止条件作为基线,以及一个缩小问题规模的递归情况。例如,阶乘函数可以定义为 factorial(0) = 1 以及对于 n > 0 有 factorial(n) = n × factorial(n - 1)。递归简洁,但比迭代占用更多栈内存,因为每次调用都会创建一个新的栈帧。
factorial(n) = n × factorial(n − 1) for n > 0; factorial(0) = 1
Edexcel questions often ask you to trace a recursive algorithm for a small input, such as factorial(3) = 3 × 2 × 1 = 6, or to identify the base case that prevents infinite recursion. If the base case is missing or unreachable, the recursion will continue until a stack overflow error occurs.
Edexcel题目常要求你对较小的输入跟踪递归算法,例如 factorial(3) = 3 × 2 × 1 = 6,或识别防止无限递归的基线条件。如果基线条件缺失或无法到达,递归将持续进行,直到出现栈溢出错误。
7. Programming Paradigms: Procedural vs Object-Oriented | 编程范式:面向过程与面向对象
A paradigm is a style of programming. Procedural programming decomposes a problem into functions and data, while object-oriented programming (OOP) models real-world entities as objects that contain both data and methods. Edexcel questions may compare these paradigms and identify which is more suitable for a given scenario, such as a large team project with reusable components.
编程范式是一种编程风格。面向过程编程将问题分解为函数和数据,而面向对象编程将现实世界实体建模为同时包含数据和方法的对象。Edexcel题目可能要求比较这些范式,并判断哪种更适合特定场景,例如具有可复用组件的大型团队项目。
- Procedural:
calculatePay(hours, rate) → amount; data and functions are separate. - Object-oriented:
employee.calculatePay(); theemployeeobject owns its data and methods.
8. Object-Oriented Concepts: Encapsulation, Inheritance, Polymorphism | 面向对象概念:封装、继承、多态
OOP has three key ideas. Encapsulation hides an object's internal data and only exposes public methods, protecting the data from invalid changes. Inheritance allows a subclass to reuse and extend a parent class, reducing duplication. Polymorphism lets the same method name behave differently depending on the object type, enabling flexible and reusable code.
面向对象有三个关键概念。封装隐藏对象的内部数据,只公开公共方法,保护数据免受无效修改。继承允许子类复用并扩展父类,减少重复。多态允许同一方法名根据对象类型产生不同行为,从而实现灵活且可复用的代码。
For example, a parent class Animal may define a method speak(). Subclasses Dog and Cat inherit from Animal and override speak() to output 'Woof' and 'Meow'. A single call to animal.speak() produces different behaviour depending on the actual object type, demonstrating polymorphism.
例如,父类 Animal 可以定义方法 speak()。子类 Dog 和 Cat 继承自 Animal 并重写 speak() 以输出 'Woof' 和 'Meow'。对 animal.speak() 的一次调用会根据实际对象类型产生不同行为,这体现了多态。
9. Translators and IDEs | 翻译器与集成开发环境
Source code must be translated into machine code before a computer can execute it. A compiler translates the whole program once and creates an executable file; an interpreter translates and runs the source code line by line; an assembler converts assembly language into machine code. Each translator has advantages and disadvantages that Edexcel may ask you to discuss.
源代码必须先翻译成机器码,计算机才能执行。编译器一次翻译整个程序并生成可执行文件;解释器逐行翻译并运行源代码;汇编器将汇编语言转换为机器码。每种翻译器都有优点和缺点,Edexcel可能要求你讨论这些内容。
| Translator | Process | Typical advantage |
| Compiler | Translates whole program once | Faster execution after compilation |
| Interpreter | Translates and runs line by line | Easier to test and debug |
| Assembler | Converts assembly code to machine code | Low-level control, efficient code |
Integrated Development Environments (IDEs) provide tools such as an editor, translator, debugger and run-time environment. Features like syntax highlighting, breakpoints and step-through execution help programmers find errors quickly. Edexcel may ask about the purpose of each IDE tool in a practical scenario.
集成开发环境提供编辑器、翻译器、调试器和运行时环境等工具。语法高亮、断点和单步执行等功能可帮助程序员快速查找错误。Edexcel可能在实践场景中询问每个IDE工具的用途。
10. Exam Technique: Trace Tables and Dry Runs | 考试技巧:跟踪表与干运行
Many Edexcel programming questions expect you to trace code by hand. A trace table records the value of each variable after each line of execution. Dry runs help you identify logic errors, understand recursion and answer 'what is the output?' questions reliably. Always update variables in the order the code executes, and check loop conditions carefully.
许多Edexcel编程题要求手动跟踪代码。跟踪表记录每一行执行后各变量的值。干运行有助于识别逻辑错误、理解递归,并可靠地回答“输出是什么?”类问题。务必按照代码执行的顺序更新变量,并仔细检查循环条件。
For example, consider the pseudocode:
例如,考虑以下伪代码:
total ← 0FOR i ← 1 TO 3total ← total + iNEXT iOUTPUT total
The trace table shows i = 1, total = 1; then i = 2, total = 3; then i = 3, total = 6. The final output is 6. Writing such a table in the exam earns method marks even if a later value is wrong, so show your working clearly.
跟踪表显示 i = 1, total = 1;然后 i = 2, total = 3;然后 i = 3, total = 6。最终输出为 6。在考试中写出这样的表格,即使后续值错误也能获得方法分,因此要清晰地展示解题过程。
Published by TutorHao | Programming Revision Series | aleveler.com
更多咨询请联系16621398022(同微信)

或截图后用「扫一扫 → 相册」选择本图