OCR计算机编程 伪代码 追踪表 查找排序
OCR 的 GCSE Computer Science J277 分成两份卷,Component 02 专门考计算思维、算法与编程,卷面 80 分,其中 Section A 占 50 分,Section B 占 30 分。很多学生以为编程题只要把代码写出来就能得分,实际评分看的是算法结构、变量追踪和边界处理有没有交代清楚。这篇把 Component 02 里出现频率最高的十三个考点拆开讲,每个考点给一个能直接搬进考场的写法。考纲自 2020 年 9 月首教,2022 年首次考评,两份卷各 1 小时 30 分钟、各占 50%。
OCR's GCSE Computer Science J277 is assessed through two papers of 1 hour 30 minutes and 80 marks each, and Component 02 carries the programming half of the course with Section A at 50 marks and Section B at 30 marks. Marks come from the shape of an algorithm, the accuracy of a trace table and the way edge cases are handled, not from whether the code would run on a real machine. The specification was first taught in September 2020 and first assessed in 2022, and within Section A you may answer in pseudocode, a flowchart, bullet points, the OCR Exam Reference Language or a high level language.
顺序、选择与循环三种结构
任何一段程序都能拆成三种结构:顺序执行、选择、循环。顺序结构按行往下走,选择结构用 if 与 else 决定走哪一条分支,循环结构用 for 或 while 反复执行同一段代码。很多学生以为嵌套的 if 写得越深越显得水平高,阅卷时看到的却是分支漏掉、条件重复的情况。判断该用 for 还是 while,看循环次数是否事先确定:次数确定用 for,条件满足才停用 while。循环里控制条件的那个变量必须在循环体内被更新,否则就是死循环。写答案时先搭三行骨架,再往里填细节,比直接堆代码少出错。
Every program in J277 reduces to sequence, selection and iteration. Selection decides which branch runs, iteration repeats a block while a condition holds, and the choice between for and while normally comes down to whether the number of repetitions is known before the loop starts. A loop whose controlling variable is never updated inside the body becomes an infinite loop, which is one of the most common faults in exam answers.
变量、常量与数据类型
变量是内存里一个带名字的存储位置,常量在程序运行期间不能改。J277 要求区分 integer、real、boolean、character 与 string 五种基本类型,选择类型的依据是数据本身的性质,不是它看起来像什么。常见的错误是把 "3" 和 3 当成同一个东西,前者是字符串,后者是整数,拼接与相加的结果完全不同。整数除法要看清题目用的是整除还是取余,DIV 取商的整数部分,MOD 取余数。类型转换写成显式的函数调用,别指望语言自动帮你转换。声明时给一个有意义的变量名,totalScore 放到追踪表里比 x 容易对上。
A variable is a named store whose value can change, while a constant keeps the same value for the whole run. J277 expects you to separate integer, real, boolean, character and string, and integer division is usually tested through DIV for the quotient and MOD for the remainder. Mixing the string "3" with the integer 3 changes what concatenation and addition produce, so write conversions explicitly rather than relying on the language to guess.
字符串的拼接、长度与取子串
字符串题最常考拼接、求长度、取子串和大小写转换四件事。长度从 1 数起,而下标在很多语言里从 0 数起,这个差别是丢分重灾区。题目给出 name = "Alice" 时长度是 5,最后一个字符的位置是 4 还是 5,要看题目用哪种约定。取子串要写清起点与长度,两个参数写反了结果完全不同。用循环逐个字符扫描是处理回文、统计字母次数的通用套路。把每一步的中间结果写进追踪表,比在心里默算可靠得多。
String questions in J277 usually test concatenation, length, substring and case conversion. Length counts characters from one while many languages index from zero, so a five character name has its last character at position four whenever the answer follows the zero based convention; check which one the question uses. Walking a string one character at a time with a loop is the standard way to count letters or test whether a word reads the same backwards.
数组与下标越界
数组是一组同类型数据共用同一个名字,靠下标区分彼此。长度为 n 的数组,合法下标是 0 到 n 减 1,写成 1 到 n 就是越界。很多学生以为循环条件写成小于等于 n 更保险,结果在最后一次迭代读到空位置。遍历数组的标准写法是从 0 开始、到 n 减 1 结束,循环体内不对下标做额外加减。二维数组先定行再定列,读题时把行列顺序写在草稿上。找最大值时先把第一个元素当作最大值,再从第二个开始逐个比较。
An array stores several values of the same type under one name and separates them by index. A set of n items occupies positions 0 to n-1, so a loop that runs all the way to n reads past the end and triggers an index out of range error. For a two dimensional array fix the row first and the column second, and write that order down before you begin tracing.
子程序、参数与返回值
子程序把一段重复使用的逻辑包起来,函数返回一个值,过程不返回值只做事情。参数是调用时传进去的数据,形参在子程序内部当局部变量使用。值传递把副本交给子程序,子程序改了也不影响外面的变量。很多学生以为在函数里改了参数,主程序里就跟着变,这在多数考试语言里并不成立。返回值只能有一个,需要带回多个结果时用数组或者全局变量。把子程序写成只做一件事,测试时更容易定位问题出在哪一段。
A subroutine wraps logic that is used more than once, and a function returns a value while a procedure does not. Parameters are copied into the subroutine under value passing, so changing a parameter inside the body leaves the caller's variable untouched in most exam languages. Keep each subroutine to a single job, because a routine that does three things is hard to test and harder to mark.
布尔逻辑与真值表
布尔值只有 true 与 false,运算符是 AND、OR、NOT 三个。AND 要求两边都成立,OR 只要一边成立,NOT 把结果取反。运算符的优先级是 NOT 最高、AND 其次、OR 最低,拿不准就加括号。真值表把输入的每种组合列出来,n 个输入有 2 的 n 次方行。常见的错误是漏掉某一组合,或者把 AND 与 OR 的位置写反。题目要求用逻辑门画图时,先把表达式化简再画,门的数量会少一半。
Boolean values are limited to true and false, and the operators are AND, OR and NOT. NOT binds tightest, AND comes next and OR last, so brackets are the safe way to make the order of evaluation explicit. A truth table needs 2 to the power n rows for n inputs, and a missing row is the usual reason a truth table loses marks.
流程图符号与伪代码写法
流程图用固定的几种符号:椭圆表示开始与结束,矩形表示处理,平行四边形表示输入输出,菱形表示判断。判断框一定有两个出口,一个标注是,一个标注否。伪代码不必符合任何一门语言的语法,只要结构清楚、变量变化可追。Section A 明确接受伪代码、流程图、要点式说明、OCR 的 Exam Reference Language 和高级语言,选自己写得最稳的一种即可。伪代码里把循环的起点、终点和步长写全,别只写一句重复十次。判断框的条件写成可以比较的表达式,别写一整句话。
Flowcharts use a fixed set of shapes: an oval for start and end, a rectangle for a process, a parallelogram for input or output and a diamond for a decision. A decision box always has two exits, and labelling them yes and no is part of the answer rather than decoration. Section A accepts pseudocode, flowcharts, bullet points, the OCR Exam Reference Language or a high level language, so pick the form you can keep consistent from the first line to the last.
追踪表逐步执行
追踪表把每一轮循环里每个变量的值列成一行,是编程题里最容易拿满分的部分。表头写变量名,行数等于循环次数加一次初始状态。很多学生以为追踪表只填结果,其实每一步的中间值都要写,否则看不出错在哪一轮。循环条件是小于还是小于等于,会直接改变最后一行的内容。遇到嵌套循环,外层每变一次,内层就要完整走一遍。写完用最后一个值回代题目条件,加减写反的情况立刻现形。
A trace table records the value of every variable at each pass through a loop, with one row per iteration plus the initial state. Fill in intermediate values rather than only the final result, because the marker is looking for the row where a value first goes wrong. With nested loops the inner loop runs to completion for every single change of the outer variable, which is why the table grows so quickly.
线性查找与二分查找
线性查找从头到尾逐个比较,数据不用先排序,最坏情况下要看完全部 n 个元素。二分查找要求数据已经有序,每次砍掉一半,最坏比较次数大约是 log2 n 向上取整。一千个数据线性查找最坏一千次,二分查找不超过十次,差距来自每次排除的范围。常见的错误是在二分查找里把中间位置写成 n 除以 2,却忘了随区间更新。写二分查找时维护 low 与 high 两个指针,循环条件是 low 小于等于 high。二分查找只适用于已排序数据,这一句在比较题里必须写出来。
A linear search compares every item from the start and needs no ordering, so its worst case is n comparisons. A binary search only works on sorted data and halves the remaining range each time, which brings the worst case to about log2 n comparisons; for a thousand items that is ten rounds against a thousand. Maintain low and high pointers and update both inside the loop, because a midpoint that never moves turns the search into an infinite loop.
冒泡、插入与归并排序
冒泡排序反复比较相邻两项,顺序不对就交换,每一轮把最大的元素推到末尾。n 个元素最多比较 n 乘 n 减一除以二 次,一百个数就是 4950 次。插入排序把每个新元素插进前面已排好的部分,数据接近有序时它很快。归并排序先拆到单个元素再两两合并,量级是 n 乘 log2 n,一千个数大约一万次比较。考试里比较两种算法时,写清比较次数与是否需要额外空间,这两个维度就够拿分。交换两个变量的值要用临时变量,直接互相赋值会把其中一个覆盖掉。
Bubble sort compares adjacent pairs and swaps them when they are out of order, pushing the largest remaining item to the end on each pass. Its worst case is n(n-1)/2 comparisons, which is 4,950 for a hundred items, while merge sort splits down to single items and merges back at a cost of about n log2 n. When a question asks you to compare algorithms, name the number of comparisons and say whether extra memory is needed.
正常、边界与错误测试数据
测试要覆盖三类数据:正常数据、边界数据和错误数据。正常数据验证程序在常见输入下算得对,边界数据卡在范围的两端,错误数据故意给程序不该接受的值。很多学生以为多测几组随机数就算充分,实际上边界上错一位的情况最多。整数范围的边界包括 0、1、最大值和最大值加一。错误数据要检查程序是否给出提示,而不是直接崩溃。每组测试都写清输入、预期输出和实际输出三栏,缺一栏就说明不了问题。
Test data falls into three groups: normal data, boundary data and erroneous data. Normal values check the ordinary path, boundary values sit at the edges of the accepted range where off by one faults appear, and erroneous data checks that the program rejects input instead of crashing. Write the input, the expected output and the actual output for every test, because a test without an expected result proves nothing.
分解、抽象与算法思维
分解是把一个大问题拆成能单独解决的小问题,抽象是只保留与解题有关的细节。J277 的 Component 02 把这两项列为计算思维的组成部分,题目常问某个程序用了哪一种方法。很多学生以为抽象就是删掉代码,真正的抽象是决定哪些信息可以忽略。以学生成绩系统为例,分解成录入、计算平均分、排序输出三个子问题,每个子问题对应一个子程序。抽象之后,成绩对象只保留分数与科目,住址与电话这类信息根本不需要进入模型。算法思维解决的是步骤顺序,先做哪一步会改变后面能做什么。
Decomposition breaks a problem into smaller parts that can be solved and tested on their own, while abstraction keeps only the detail that the solution needs. In Component 02 these two ideas are part of computational thinking, and questions often ask which one a given program has used. A grade book splits naturally into data entry, average calculation and sorted output, and the address of each student never needs to enter the model at all.
Section A 与 Section B 的卷面分工
Component 02 卷面 80 分,Section A 占 50 分,Section B 占 30 分,两部分的作答要求不一样。Section A 允许用伪代码、流程图、要点式说明、Exam Reference Language 或高级语言,评分看结构不看语法细节。Section B 更偏向完整程序与算法设计,答案要能从第一行跑到最后一行。时间分配按分值走,选择题与短答不要停留太久。写完整程序时先声明变量、再写输入、然后处理、最后输出,这个骨架能保住结构分。J277 不要求 Big O 记号,效率只说比较次数与循环轮数就够。
Component 02 carries 80 marks with Section A at 50 and Section B at 30, and the two sections ask for different kinds of answer. Section A accepts pseudocode, flowcharts, bullet points, the Exam Reference Language or a high level language, and the marking rewards structure rather than precise syntax. Section B expects a program that could run from first line to last, so declare the variables, read the input, process it and output the result in that order; J277 does not require Big O notation, and a comparison count per pass is enough.
戴睿(dere)Neo优选系列 创意双触摸屏高性能笔记本电脑大学生AI学习商务办公设计炒股娱乐手提轻薄本32/1TB¥4586.0📱 去京东购买京东精选
需要一对一辅导?Need One-on-One Tutoring?
A-Level / GCSE / IB / KS2-KS3 全科辅导,GCSE Computer Science J277 与编程入门均可安排
16621398022 同微信
Visit aleveler.com

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

