📚 Edexcel A-Level Programming: Topic 1.4 Combined Programming Skills | 爱德思 A-Level 编程:1.4 综合编程技能
This revision guide focuses on the core programming skills required for the Edexcel A-Level Computer Science specification, particularly the combined programming techniques found in Topic 1.4. You will learn to design, write, test and refine programs using structured constructs, data types, subroutines and file handling.
本复习指南聚焦爱德思 A-Level 计算机科学考试大纲所要求的核心编程技能,尤其是专题 1.4 中的综合编程技术。你将学习使用结构化控制结构、数据类型、子程序和文件处理来设计、编写、测试和改进程序。
1. Sequence, Selection and Iteration | 顺序、选择与迭代
Every program is built from three fundamental control structures: sequence, selection and iteration. Sequence means statements execute one after another in order. Selection allows the program to make decisions using if, else if and else. Iteration repeats a block of code using while, for or do-while loops.
每个程序都由三种基本的控制结构构建:顺序、选择和迭代。顺序意味着语句按顺序一条接一条执行。选择允许程序使用 if、else if 和 else 做决策。迭代使用 while、for 或 do-while 循环重复执行一段代码。
A common mistake is to confuse definite iteration with indefinite iteration. A for loop is definite because the number of repetitions is known in advance, while a while loop is indefinite because it depends on a condition being true.
常见错误是混淆确定循环和不确定循环。for 循环是确定性的,因为重复次数事先已知;while 循环是不确定性的,因为它取决于条件是否为真。
- Sequence: executing statements line by line | 顺序:逐行执行语句
- Selection: IF, ELSE IF, ELSE, SWITCH | 选择:IF、ELSE IF、ELSE、SWITCH
- Iteration: FOR (definite), WHILE (indefinite), DO…WHILE | 迭代:FOR(确定)、WHILE(不确定)、DO…WHILE
2. Data Types and Variables | 数据类型与变量
Variables are named storage locations whose values can change during execution. In A-Level pseudocode, you must declare variables with data types such as INTEGER, REAL, CHAR, STRING and BOOLEAN. Choosing the correct type affects memory usage and the operations that can be performed.
变量是命名的存储位置,其值可以在执行过程中改变。在 A-Level 伪代码中,必须声明变量及其数据类型,如 INTEGER(整型)、REAL(实数)、CHAR(字符)、STRING(字符串)和 BOOLEAN(布尔型)。选择正确的类型会影响内存使用和可执行的操作。
Constants are fixed values that cannot be changed after declaration. They improve code readability and prevent accidental modification. For example, declaring CONST PI = 3.14159 makes the intent clear.
常量是声明后不能改变的值。它们提高了代码的可读性并防止意外修改。例如,声明 CONST PI = 3.14159 使意图更清晰。
| Data type | 数据类型 | Example | 示例 | Typical use | 典型用途 |
|---|---|---|
| INTEGER | 42 | counting, indexing | 计数、索引 |
| REAL | 3.14 | measurements, prices | 测量值、价格 |
| CHAR | ‘A’ | single character | 单个字符 |
| STRING | “hello” | text | 文本 |
| BOOLEAN | TRUE/FALSE | conditions | 条件 |
3. Operators and Expressions | 运算符与表达式
Expressions combine variables, literals and operators to produce a value. Arithmetic operators include +, −, ×, ÷, MOD and DIV. MOD gives the remainder, while DIV gives integer division. For example, 17 MOD 5 = 2 and 17 DIV 5 = 3.
表达式将变量、字面量和运算符组合起来产生一个值。算术运算符包括 +、−、×、÷、MOD 和 DIV。MOD 给出余数,DIV 给出整数除法。例如,17 MOD 5 = 2,17 DIV 5 = 3。
Comparison operators (=, ≠, <, >, ≤, ≥) return BOOLEAN values. Logical operators AND, OR and NOT combine conditions. Remember that AND requires both conditions true, while OR requires at least one true.
比较运算符(=、≠、<、>、≤、≥)返回布尔值。逻辑运算符 AND、OR 和 NOT 用于组合条件。请记住,AND 要求两个条件都为真,而 OR 只要求至少一个为真。
(2 + 3) × 4 = 20 because parentheses change order of evaluation | (2 + 3) × 4 = 20,因为括号改变了求值顺序
4. Arrays and Lists | 数组与列表
Arrays store multiple elements of the same data type in contiguous memory locations. In pseudocode, you can declare ARRAY scores[0:9] OF INTEGER to hold ten test scores. Lists are dynamic and can grow or shrink, making them useful when the number of items is unknown.
数组在连续的内存位置中存储相同类型的多个元素。在伪代码中,可以声明 ARRAY scores[0:9] OF INTEGER 来保存十个测试成绩。列表是动态的,可以增长或缩小,因此在元素数量未知时很有用。
Accessing elements uses an index. Most pseudocode uses zero-based indexing, but some exam questions use one-based indexing, so always check the question. To access the third element in a zero-based array, write scores[2].
访问元素需要使用索引。大多数伪代码使用从 0 开始的索引,但有些考题使用从 1 开始的索引,因此务必检查题目。在从 0 开始的数组中访问第三个元素,应写作 scores[2]。
Two-dimensional arrays are also common, such as a grid for a board game: ARRAY board[0:7][0:7] OF CHAR. Each dimension is accessed with a separate index.
二维数组也很常见,例如棋盘游戏的网格:ARRAY board[0:7][0:7] OF CHAR。每个维度用单独的索引访问。
5. Functions and Procedures | 函数与过程
Functions and procedures are subroutines that break a large problem into smaller, reusable parts. A function returns a single value, whereas a procedure does not return a value but may change global variables or output data. In pseudocode, you write PROCEDURE displayMenu() or FUNCTION getAverage(nums) RETURNS REAL.
函数和过程是将大问题分解为更小的、可重用部分的子程序。函数返回单个值,而过程不返回值,但可能改变全局变量或输出数据。在伪代码中,可以写 PROCEDURE displayMenu() 或 FUNCTION getAverage(nums) RETURNS REAL。
Parameters can be passed by value or by reference. 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 are reflected outside. Choosing the correct method is a common exam question.
参数可以按值传递或按引用传递。按值传递会复制数据,因此子程序内部的更改不会影响原始变量。按引用传递传递的是内存地址,因此更改会在外部体现。选择正确的方法是常见考试题。
6. Recursion | 递归
Recursion occurs when a function calls itself. It must have a base case to stop the recursion and a recursive case that reduces the problem. A classic example is factorial: n! = n × (n−1)! with base case 1! = 1.
递归发生在函数调用自身时。它必须有一个停止递归的基准情型和一个缩小问题的递归情型。经典例子是阶乘:n! = n × (n−1)!,基准情型为 1! = 1。
FUNCTION Factorial(n)
IF n = 1 THEN RETURN 1
ELSE RETURN n × Factorial(n−1)
Recursion can be elegant but may use more memory because each call is placed on the call stack. Iterative solutions using loops are often more efficient in terms of stack space, but recursion is better for problems with a naturally recursive structure such as tree traversal.
递归可能简洁,但会占用更多内存,因为每次调用都会放入调用栈。使用循环的迭代方案在栈空间方面通常更高效,但递归更适合具有自然递归结构的问题,如树遍历。
7. File Handling | 文件处理
Programs often need to read from and write to files. In pseudocode, you open a file with a mode such as READ, WRITE or APPEND. After processing, you must close the file to ensure data is saved and resources are released.
程序经常需要读写文件。在伪代码中,可以使用 READ、WRITE 或 APPEND 等模式打开文件。处理完后必须关闭文件,以确保数据被保存并释放资源。
Common operations include reading all lines, writing a line, and checking for end-of-file. For example, OPEN file FOR READ, WHILE NOT EOF file THEN line = file.readLine(). Always handle the possibility that the file does not exist by using error handling.
常见操作包括读取所有行、写入一行以及检查文件结束。例如,OPEN file FOR READ,然后 WHILE NOT EOF file 时执行 line = file.readLine()。应始终通过错误处理来处理文件可能不存在的情况。
8. Error Handling and Debugging | 错误处理与调试
Three categories of error are syntax errors, runtime errors and logic errors. Syntax errors occur when the code does not follow the language rules and are caught at compile time. Runtime errors occur during execution, such as division by zero or file not found. Logic errors produce incorrect output without crashing, making them the hardest to detect.
错误分为三类:语法错误、运行时错误和逻辑错误。语法错误在代码不符合语言规则时发生,并在编译时被发现。运行时错误在执行过程中发生,如除以零或文件未找到。逻辑错误产生错误输出但不会导致程序崩溃,因此最难检测。
Debugging techniques include trace tables, breakpoints, print statements and rubber duck debugging. A trace table tracks variable values line by line and is frequently examined in Edexcel papers.
调试技术包括追踪表、断点、打印语句和橡皮鸭调试。追踪表逐行记录变量值,在爱德思考试中经常出现。
9. Algorithms and Pseudocode | 算法与伪代码
An algorithm is a step-by-step procedure for solving a problem. Common exam algorithms include linear search, binary search, bubble sort and insertion sort. You must be able to write pseudocode and compare their time complexities.
算法是解决问题的分步过程。常见考试算法包括线性搜索、二分搜索、冒泡排序和插入排序。你必须能够编写伪代码并比较它们的时间复杂度。
Linear search has O(n) because it scans each item. Binary search has O(log n) but requires a sorted list. Bubble sort and insertion sort both average O(n²), but insertion sort is often faster on nearly sorted lists
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课程辅导,国外大学本科硕士研究生博士课程论文辅导