| 考生应能够: | 说明与指导 |
|---|---|
| 1 理解程序开发生命周期,仅限于:分析、设计、编码和测试 | • 包括识别每个阶段并为每个阶段执行以下任务: – 分析:抽象化、问题分解、识别问题和需求 – 设计:分解、结构图、流程图、伪代码 – 编码:编写程序代码并进行迭代测试 – 测试:使用测试数据对程序代码进行测试 |
| 2 (a) 理解每个计算机系统由子系统组成,而子系统又由更小的子系统组成 (b) 理解如何将问题分解为其组成部分 | • 包括: – 输入 – 处理 – 输出 – 存储 |
| (c) 使用不同的方法来设计和构建问题的解决方案 | • 包括: – 结构图 – 流程图 – 伪代码 |
| 3 解释给定算法的目的 | • 包括: – 陈述算法的目的 – 描述算法中涉及的处理过程 |
| 4 理解标准求解方法 | • 仅限于: – 线性搜索 – 冒泡排序 – 求和 – 计数 – 查找最大值、最小值和平均值 |
| 5 (a) 理解需要对输入数据进行验证检查以及不同类型的验证检查 | • 包括: – 范围检查 – 长度检查 – 类型检查 – 存在性检查 – 格式检查 – 校验位 |
| (b) 理解需要对输入数据进行核实检查以及不同类型的核实检查 | • 包括: – 视觉检查 – 双重录入检查 |
| 6 建议并应用适当的测试数据 | • 仅限于: – 正常数据 – 异常数据 – 极值数据 – 边界数据 • 极值数据是可接受的最大/最小值 • 边界数据是可接受的最大/最小值以及对应的被拒绝的最小/最大值 |
| 7 完成跟踪表以记录算法的干运行 | • 包括在算法的每一步: – 变量 – 输出 – 用户提示 |
| 8 识别给定算法中的错误并提出纠正这些错误的方法 | |
| 9 使用伪代码、程序代码和流程图编写和修改给定问题或场景的算法 | • 编写算法时需要精确,例如 x > y 是可接受的,但 x is greater than y 是不可接受的 • 参见第4节关于流程图符号 • 参见第4节关于伪代码 |
算法设计与问题求解
9:16
程序开发生命周期
你手机上的每一个应用都是由像这样的人编写的。但他们并非从敲下代码开始。在第一行代码之前,问题被研究,解决方案被设计……
英文讲解 · 可切换中英文字幕
Try it in the lab 4
All labs →教学大纲
来源:Cambridge International 教学大纲
7.1
程序开发生命周期
The program development life cycle 程序开发生命周期 is the set of stages used to make a program. There are four stages.

| Stage | What you do |
|---|---|
| analysis 分析 | study the problem and work out what is needed |
| design 设计 | plan how the program will work |
| coding 编码 | write the program code and test it as you go |
| testing 测试 | run the finished program with test data to find errors |


Analysis
In analysis you understand the problem. Two key skills help:
- abstraction 抽象 — keep only the important details and ignore the rest;
- decomposition 分解 — break a big problem into smaller, easier parts.
Design
In design you plan the solution, often using decomposition. You can show the parts as sub-systems 子系统 in a structure diagram 结构图 (a chart that splits a system into smaller boxes).
Worked example. A car park has a payment machine. The driver types in the car's number plate, the machine works out how long the car has stayed and the charge, the driver pays by cash or card, and a receipt is printed. Draw a structure diagram.

The whole system goes in the top box. Each box on the next level is one job the system does, and a box can be split again (paying splits into cash and card). Read across a level from left to right in the order the jobs happen. A structure diagram shows the parts, not the order of decisions or loops: that is what a flowchart or pseudocode is for.
Coding and testing
In coding you write the program code. You use iterative testing 迭代测试 — test small parts again and again as you build them. In testing you run the whole program with test data 测试数据 to check it works.
| English | 中文 | 拼音 |
|---|---|---|
| program development life cycle/ˈprəʊɡræm dɪˈveləpmənt laɪf ˈsaɪkl/ | 程序开发生命周期 | chéng xù kāi fā shēng mìng zhōu qī |
| analysis/əˈnæləsɪs/ | 分析 | fēn xī |
| design/dɪˈzaɪn/ | 设计 | shè jì |
| coding/ˈkəʊdɪŋ/ | 编码 | biān mǎ |
| testing/ˈtestɪŋ/ | 测试 | cè shì |
| abstraction/əbˈstrækʃn/ | 抽象 | chōu xiàng |
| decomposition/ˌdiːkɒmpəˈzɪʃn/ | 分解 | fēn jiě |
| sub-systems/sʌb ˈsɪstəmz/ | 子系统 | zǐ xì tǒng |
| structure diagram/ˈstrʌktʃə ˈdaɪəɡræm/ | 结构图 | jié gòu tú |
| iterative testing/ˈɪtərətɪv ˈtestɪŋ/ | 迭代测试 | dié dài cè shì |
| test data/test ˈdeɪtə/ | 测试数据 | cè shì shù jù |
7.2
设计工具
You can plan a solution in three main ways.
- a structure diagram — shows the parts of a system and how they fit together;
- a flowchart 流程图 — a diagram using boxes and arrows to show the steps in order;
- pseudocode 伪代码 — steps written in simple, code-like English (not a real language).

| English | 中文 | 拼音 |
|---|---|---|
| flowchart/ˈfləʊtʃɑːt/ | 流程图 | liú chéng tú |
| pseudocode/ˈsuːdəʊkəʊd/ | 伪代码 | wěi dài mǎ |
7.3
算法
An algorithm 算法 is a set of steps, in the right order, that solves a problem. Every algorithm can be split into three parts:
- input 输入 — the data that goes in;
- processing 处理 — the work done on the data;
- output 输出 — the result that comes out.
This is called decomposition into inputs, processes and outputs. For example, for “find the average of three marks”: the inputs are the three marks; the processing is adding them and dividing by 3; the output is the average.

| English | 中文 | 拼音 |
|---|---|---|
| algorithm/ˈælɡərɪθəm/ | 算法 | suàn fǎ |
| input/ˈɪnpʊt/ | 输入 | shū rù |
| processing/ˈprəʊsesɪŋ/ | 处理 | chǔ lǐ |
| output/ˈaʊtpʊt/ | 输出 | shū chū |
7.4
有效性检查与准确性检查
When data is entered, you check it to reduce mistakes.
Validation 验证 checks that the data is sensible and follows the rules. It cannot check that the data is true, only that it is allowed.
| Validation check | What it checks |
|---|---|
| range check 范围检查 | the value is between a lowest and highest allowed value |
| length check 长度检查 | the number of characters is allowed (e.g. a password ≥ 8) |
| type check 类型检查 | the data is the right type (e.g. a number, not letters) |
| presence check 存在性检查 | something has actually been entered (not left blank) |
| format check 格式检查 | the data is in the right pattern (e.g. a date as dd/mm/yyyy) |
| check digit 校验码 | an extra calculated digit helps detect errors when a number is entered |
Verification 核实 checks that data was copied or entered correctly (no mistakes while typing it in). Two methods:
- visual check 目视检查 — a person compares the typed data with the original;
- double entry 双重输入 — the data is entered twice and the two copies are compared.

Writing a validation routine
An exam often asks you to write the code for a check. Use a loop that asks again until the input is acceptable, and give the user a message when it is not.
Worked example. Write pseudocode to input a test mark, which must be a whole number from 0 to 100 (a range check), and to keep asking until a valid mark is entered.
DECLARE Mark : INTEGER
REPEAT
OUTPUT "Enter a mark from 0 to 100"
INPUT Mark
IF Mark < 0 OR Mark > 100
THEN
OUTPUT "Invalid: the mark must be from 0 to 100"
ENDIF
UNTIL Mark >= 0 AND Mark <= 100
The UNTIL condition is the accepted range, and the IF condition is its opposite. Notice OR in the IF: a mark cannot be below 0 and above 100 at the same time, so AND there would never be true.
Other checks follow the same pattern, with a different condition:
| Check | Condition for a valid value |
|---|---|
| length check (password of at least 8 characters) | LENGTH(Password) >= 8 |
| presence check (a name must be entered) | Name <> "" |
| range check (age 16 to 65) | Age >= 16 AND Age <= 65 |
A type check is usually done by the language itself, for example when an input is stored in an INTEGER variable.
| English | 中文 | 拼音 |
|---|---|---|
| validation/ˌvælɪˈdeɪʃn/ | 验证 | yàn zhèng |
| range check/reɪndʒ tʃek/ | 范围检查 | fàn wéi jiǎn chá |
| length check/leŋθ tʃek/ | 长度检查 | cháng dù jiǎn chá |
| type check/taɪp tʃek/ | 类型检查 | lèi xíng jiǎn chá |
| presence check/ˈprezəns tʃek/ | 存在性检查 | cún zài xìng jiǎn chá |
| format check/ˈfɔːmæt tʃek/ | 格式检查 | gé shì jiǎn chá |
| check digit/tʃek ˈdɪdʒɪt/ | 校验码 | jiào yàn mǎ |
| verification/ˌverɪfɪˈkeɪʃn/ | 核实 | hé shí |
| visual check/ˈvɪʒuːəl tʃek/ | 目视检查 | mù shì jiǎn chá |
| double entry/ˈdʌbl ˈentri/ | 双重输入 | shuāng chóng shū rù |
7.5
跟踪表
A trace table 追踪表 records the value of each variable as an algorithm runs, step by step. It helps you:

- check that an algorithm works correctly;
- work out what an algorithm does by following it with given data.
Example: trace this algorithm with the input 5.
INPUT N
Total ← 0
FOR I ← 1 TO N
Total ← Total + I
NEXT I
OUTPUT Total
| i | total | OUTPUT |
|---|---|---|
| 1 | 1 | |
| 2 | 3 | |
| 3 | 6 | |
| 4 | 10 | |
| 5 | 15 | 15 |
The trace shows the algorithm adds up 1 to n. With input 5 the output is 15.
Worked example. Trace this algorithm and give the output.
X ← 20
Count ← 0
WHILE X > 1
X ← DIV(X, 2)
Count ← Count + 1
ENDWHILE
OUTPUT Count
DIV gives only the whole-number part of a division. Take one row per pass: x becomes 10 (count 1), then 5 (count 2), then 2 (count 3), then 1 (count 4). Now x > 1 is false, so the loop stops and the output is 4. Two habits protect these marks: test the condition before each pass rather than after, and write a new row for every pass - trying to hold the values in your head is what makes traces go wrong.
Finding and correcting errors
A common question gives an algorithm with errors and asks you to find and correct them. Read it line by line and ask: is every variable given a starting value? Is each loop the right length? Is each comparison the right way round? Is the output in the right place?
Worked example. This algorithm should input 10 numbers and output the largest. Find the four errors and correct them.
Largest ← 1000
FOR Count ← 1 TO 9
INPUT Number
IF Number < Largest
THEN
Largest ← Number
ENDIF
OUTPUT Largest
NEXT Count
- Line 1:
Largest ← 1000is not a safe starting value for arbitrary inputs. Input the first number and assign it toLargest; then change line 2 toFOR Count ← 2 TO 10to input and compare the remaining nine numbers. - Line 2: the loop runs only 9 times. Correction:
FOR Count ← 1 TO 10. - Line 4:
<finds the smallest. Correction:IF Number > Largest.
There is also a problem with the OUTPUT: inside the loop it prints the largest so far after every input. Moving it after NEXT Count prints only the final answer. For each error, give the line, say what is wrong, and write the corrected line in full.
跟踪表
逐步执行循环并填写跟踪表,每轮通过一行。
| English | 中文 | 拼音 |
|---|---|---|
| trace table/treɪs ˈteɪbl/ | 追踪表 | zhuī zōng biǎo |
7.6
测试数据
Test data is data you use to test a program. There are four types you must know.
| Type | Meaning | Example (age 0–120 allowed) |
|---|---|---|
| normal 正常数据 | sensible data that should be accepted | 25 |
| abnormal 异常数据 | wrong data that should be rejected | -4 or “cat” |
| extreme 极端数据 | the largest and smallest values still allowed | 0 and 120 |
| boundary 边界数据 | the values on each side of a limit (one allowed, one not) | 120 and 121 |
Worked example. A program accepts the number of people booking a table, from 1 to 12. Give test data of each type, with the expected result.
| Type | Test data | Expected result |
|---|---|---|
| normal | 5 | accepted |
| abnormal | 20 (or “six”) | rejected, with an error message |
| extreme | 1 and 12 | accepted |
| boundary | 12 and 13 (or 0 and 1) | 12 accepted, 13 rejected |
Always give the expected result with the data: a test is only useful if you know what should happen. Extreme data is the edge value itself; boundary data is a pair, one value each side of the limit.

| English | 中文 | 拼音 |
|---|---|---|
| normal/ˈnɔːml/ | 正常数据 | zhèng cháng shù jù |
| abnormal/əbˈnɔːml/ | 异常数据 | yì cháng shù jù |
| extreme/ekˈstriːm/ | 极端数据 | jí duān shù jù |
| boundary/ˈbaʊndəri/ | 边界数据 | biān jiè shù jù |
7.7
标准解题方法
You must know these common algorithms.
Linear search
A linear search 线性查找 compares each item with the target, starting at the beginning. Stop when the value is found or the list ends. The list does not need to be sorted. The following example uses positions 1 to 4.
DECLARE List : ARRAY[1:4] OF INTEGER
DECLARE I, SearchValue : INTEGER
DECLARE Found : BOOLEAN
List[1] ← 8
List[2] ← 3
List[3] ← 5
List[4] ← 1
INPUT SearchValue
Found ← FALSE
I ← 1
WHILE I <= 4 AND NOT Found
IF List[I] = SearchValue
THEN
Found ← TRUE
ENDIF
I ← I + 1
ENDWHILE
OUTPUT Found
Worked comparison. Searching for 5 compares 8, 3 and then 5: three comparisons, with Found becoming TRUE. The fourth item is not checked. Searching for 9 compares all four values; Found stays FALSE. Stop before trying to read position 5, which is outside this array.

Bubble sort
A bubble sort 冒泡排序 puts a list in order. Compare neighbouring values and swap them if the left value is greater. A single pass is not enough in general. This complete version repeats passes until a whole pass makes no swaps.
DECLARE List : ARRAY[1:4] OF INTEGER
DECLARE I, Temp : INTEGER
DECLARE Swapped : BOOLEAN
List[1] ← 8
List[2] ← 3
List[3] ← 5
List[4] ← 1
REPEAT
Swapped ← FALSE
FOR I ← 1 TO 3
IF List[I] > List[I + 1]
THEN
Temp ← List[I]
List[I] ← List[I + 1]
List[I + 1] ← Temp
Swapped ← TRUE
ENDIF
NEXT I
UNTIL NOT Swapped
OUTPUT List[1], ", ", List[2], ", ", List[3], ", ", List[4]
Worked passes. Start with 8, 3, 5, 1. In the first pass the list becomes 3, 8, 5, 1, then 3, 5, 8, 1, then 3, 5, 1, 8. This puts the largest value last but leaves the rest unsorted. The second pass ends at 3, 1, 5, 8; the third at 1, 3, 5, 8. The fourth makes no swaps and confirms that this version can stop. Reset Swapped to FALSE at the start of every pass; set it to TRUE on any swap.

Totalling and counting
Totalling 求和 adds each required value to a running total: Total ← Total + Value. Counting 计数 adds 1 for each required item: Count ← Count + 1. Initialise both to zero before processing the values.
Worked example. Four attempted inputs are −20, 4, 50 and 6. Accept a value only if it is greater than −20 and less than 50. This example processes four attempts, not four accepted values.
DECLARE I, Count : INTEGER
DECLARE Value, Total : REAL
Total ← 0
Count ← 0
FOR I ← 1 TO 4
INPUT Value
IF Value > -20 AND Value < 50
THEN
Total ← Total + Value
Count ← Count + 1
ENDIF
NEXT I
IF Count > 0
THEN
OUTPUT Total, ", ", Count, ", ", Total / Count
ELSE
OUTPUT "No accepted values"
ENDIF
| Attempted value | Total after attempt | Count after attempt |
|---|---|---|
| −20 | 0 | 0 |
| 4 | 4 | 1 |
| 50 | 4 | 1 |
| 6 | 10 | 2 |
The strict limits reject −20 and 50. Both updates belong inside the acceptance test, so rejected attempts change neither total nor count. The average of the accepted values is:
Do not divide by four: only two values were added. If no value is accepted, the count is zero and an average cannot be calculated; output a message instead of dividing by zero.
Transfer to a fixed number of accepted values. If a task asks for 50 accepted values, rather than four attempts, replace the fixed FOR loop with WHILE Count < 50 and close it with ENDWHILE. Keep the same input and acceptance test inside it. Rejected inputs leave Count unchanged, so another input is requested. On completion Count is 50, although the number of attempts may be greater. Output the total and calculate the average as Total / Count.
Maximum, minimum and average
The maximum 最大值 is the largest value and the minimum 最小值 is the smallest. The average 平均值 is the total divided by the number of values. For a non-empty list, initialise both from its first item. For each remaining item, replace the maximum if the new value is larger, and replace the minimum if it is smaller.
Worked example. The list is −8, −3, −12, −5. Starting the maximum at zero would fail: no list item is greater than zero, so the algorithm would output a number that is not in the list. Starting from −8 works without assuming that the data is positive.
| Value just considered | Maximum so far | Minimum so far |
|---|---|---|
| −8 (initialisation) | −8 | −8 |
| −3 | −3 | −8 |
| −12 | −3 | −12 |
| −5 | −3 | −12 |
DECLARE List : ARRAY[1:4] OF INTEGER
DECLARE I, Maximum, Minimum, Total : INTEGER
List[1] ← -8
List[2] ← -3
List[3] ← -12
List[4] ← -5
Maximum ← List[1]
Minimum ← List[1]
Total ← List[1]
FOR I ← 2 TO 4
IF List[I] > Maximum
THEN
Maximum ← List[I]
ENDIF
IF List[I] < Minimum
THEN
Minimum ← List[I]
ENDIF
Total ← Total + List[I]
NEXT I
OUTPUT Maximum, ", ", Minimum, ", ", Total / 4
The maximum is −3 and the minimum is −12. The average uses all four values:
The average lies between the minimum and maximum; this is a useful check, not proof that the calculation is correct. Initialising from the first item requires a non-empty list. Handle an empty list separately before trying to read that item.
| English | 中文 | 拼音 |
|---|---|---|
| linear search/ˈlɪnɪə sɜːtʃ/ | 线性查找 | xiàn xìng chá zhǎo |
| bubble sort/ˈbʌbl sɔːt/ | 冒泡排序 | mào pào pái xù |
| totalling/ˈtəʊtəlɪŋ/ | 求和 | qiú hé |
| counting/ˈkaʊntɪŋ/ | 计数 | jì shù |
| maximum/ˈmæksɪməm/ | 最大值 | zuì dà zhí |
| minimum/ˈmɪnɪməm/ | 最小值 | zuì xiǎo zhí |
| average/ˈævrɪdʒ/ | 平均值 | píng jūn zhí |
7.8
考试技巧
- The four life-cycle stages: analysis → design → coding → testing. Abstraction keeps only what matters; decomposition splits a problem into parts.
- Validation checks data is sensible (range, length, type, presence, format checks); verification checks it was copied correctly (a visual check or double entry).
- Learn the four test-data types: normal (accepted), abnormal (rejected), extreme (the largest/smallest still allowed), boundary (either side of a limit).
- A trace table (every variable's value at each step) shows what an algorithm does.
- To write a validation routine, put the input in a
REPEAT … UNTILloop whoseUNTILcondition is the valid data. - When you correct an error, quote the line and write the whole corrected line.
- Know the standard algorithms: linear search (check each item in turn) and bubble sort (swap side-by-side pairs until no swaps are needed).
出了什么问题?只有网站团队能看到这些信息。
该知识点的互动课程
逐步完成,配合即时检查练习。