📚 Year 11 OCR Computer Science: Case Study Practice | Year 11 OCR 计算机:案例分析实战演练
Case study questions in OCR GCSE Computer Science are designed to test how well you can apply computational thinking to real-world scenarios. You'll be given a detailed context, such as a library lending system or a cinema booking app, and asked to analyse requirements, design algorithms, and consider testing and evaluation. This article walks you through a complete case study workout, giving you the tools and techniques to tackle any similar challenge with confidence.
OCR GCSE 计算机科学中的案例分析题旨在考察你将计算思维应用到真实情境中的能力。你会拿到一个详细的场景,比如图书借阅系统或电影院订票应用,然后需要分析需求、设计算法并考虑测试与评估。本文带你进行一次完整的案例分析实战演练,让你掌握应对任何类似题目的工具和技巧。
1. Introduction to the Case Study Method | 案例分析题型简介
OCR case study questions usually appear in Paper 2 (Computational Thinking, Algorithms and Programming). They require more than just recalling facts; you must show that you can break down a complex problem, recognise patterns, abstract away unnecessary details, and produce a clear, step-by-step solution. The marks are spread across analysis, design, algorithm writing, and testing.
OCR 的案例分析题通常出现在 Paper 2(计算思维、算法与编程)中。这些题目不仅要求你回忆知识点,更要你能分解复杂问题、识别模式、忽略无关细节,并提出清晰的逐步解决方案。分值会分布在分析、设计、算法编写和测试等环节。
Even if your current specification (J277) does not include a pre-release case study, many schools use them for revision because they mirror the style of extended exam questions. By practising with a structured approach, you'll build the skills needed to pick up marks on the trickiest parts of the paper.
即使当前的考纲 (J277) 不包含预先发布的案例研究材料,很多学校仍然用这类题目来复习,因为它们与试卷中的拓展题风格一致。通过系统化的练习,你将建立起在试卷最难部分获取分数的能力。
2. Scenario Deconstruction | 场景解构
Let's work with a typical case study: A local library wants a program to manage book loans. Members can borrow and return books. The system must keep track of which books are out on loan, who has them, and the due dates. Overdue fines are charged at £0.10 per day. The librarian needs to be able to view all currently borrowed books and generate a report of overdue items.
我们以一个典型场景为例:当地图书馆希望用一个程序来管理图书借阅。会员可以借阅和归还图书。系统必须记录哪些书当前在借、借阅者是谁以及到期日。逾期罚款按每天 0.10 英镑收取。图书管理员需要能够查看所有当前借出的图书,并生成逾期项报告。
When you first read a scenario, underline the nouns and noun phrases (book, member, loan, due date, fine, report) – these often become data items. Then circle the verbs and verb phrases (borrow, return, view, generate report, calculate fine) – these are the processes your system must carry out. This simple technique gives you an instant head start on listing inputs, outputs, and required procedures.
初读场景时,在名词和名词短语(图书、会员、借阅、到期日、罚款、报告)下划线——它们往往会成为数据项。再圈出动词和动词短语(借阅、归还、查看、生成报告、计算罚款)——这些就是系统必须实现的处理过程。这个简单的技巧能让你立刻上手,整理出输入、输出和所需的过程清单。
3. Identifying Inputs, Outputs and Processes | 识别输入、输出和处理
From the scenario we can extract inputs: member ID, book ISBN, the action (borrow or return), and the current date. Outputs include a list of all books currently on loan with borrower details, and a report of overdue books showing fines owed. Processes are borrowBook, returnBook, calculateFines, displayCurrentLoans, and generateOverdueReport.
从场景中我们可以提取出以下输入:会员 ID、图书 ISBN、操作(借阅或归还)以及当前日期。输出包括所有当前借出图书及其借阅者详情的列表,以及显示欠款的逾期图书报告。处理过程包括 borrowBook、returnBook、calculateFines、displayCurrentLoans 和 generateOverdueReport。
It is essential to be specific. Instead of just saying "fine calculation", note that the fine depends on the number of days between the due date and the return date (or today's date for a report). The rate is £0.10 per day. This precision will help you write accurate pseudocode and test data later.
具体化非常关键。不要只说“罚款计算”,而要明确罚款取决于到期日与归还日期(或报告时的当前日期)之间的天数。费率是每天 0.10 英镑。这种精确度将帮助你后续写出准确的伪代码和测试数据。
4. Decomposition and Structure Charts | 分解与结构图
Decomposition is the process of breaking a large problem into smaller, manageable sub-problems. For the library system, the top-level task "Manage Library Loans" can be split into: Input Handling, Loan Processing, Fine Calculation, and Report Generation. Each of these can be broken down further. Loan Processing, for example, divides into Borrow Book and Return Book.
分解是将一个大问题拆分成更小、更易管理的子问题的过程。对于图书馆系统,顶层任务“管理图书馆借阅”可以拆分为:输入处理、借阅处理、罚款计算和报告生成。这些子任务还可以继续拆分,比如借阅处理可进一步分为借书和还书。
A structure chart helps visualise this hierarchy. The main module sits at the top and controls the sub-modules beneath it. Data such as member details and loan records may be passed between modules. You can draw a simple chart in an exam, but even a written hierarchy demonstrates your ability to decompose.
结构图有助于直观展现这一层次关系。主模块位于顶部,控制其下方的子模块。会员详情和借阅记录等数据可能会在模块之间传递。考试时你可以画一张简单的结构图,但即便只是用文字写出层次关系,也能展示你的分解能力。
Main: Library System
|
+-- Get Input (member ID, ISBN, action, date)
|
+-- Process Loan
| |
| +-- Borrow Book
| +-- Return Book
|
+-- Calculate Fines
|
+-- Generate Reports
|
+-- Current Loans
+-- Overdue Report
文本结构图示例:主控模块 Library System 下有四个子模块 Get Input、Process Loan、Calculate Fines 和 Generate Reports,而 Process Loan 又包含 Borrow Book 和 Return Book。这种分层设计使每个模块职责单一,便于开发和测试。
5. Data Structures and Variables | 数据结构与变量
Choosing the right data structures is a key design decision. Loan records could be stored in a 2D array, a list of lists, or a list of dictionaries. A record might contain: memberID (string), ISBN (string), dueDate (date), and status (on loan/returned). A separate list or file would hold valid member IDs and book details.
选择合适的数据结构是一项关键设计决策。借阅记录可以存储在二维数组、列表嵌套列表或字典列表中。一条记录可能包含:memberID(字符串)、ISBN(字符串)、dueDate(日期)以及状态(借阅中/已归还)。另一个独立的列表或文件用于存放有效的会员 ID 和图书详情。
onstant). You might also use a currentDate variable and loop counters for generating reports. Remember to define data types clearly in your design – this is often assessed in written exam questions.
需要声明的变量:loans(当前借阅列表),finePerDay = 0.10(常量),maxBooksPerMember = 5(常量)。还可能会用到 currentDate 变量以及循环计数器来生成报告。在你的设计中,务必清晰地定义数据类型——这在笔试中经常会被考察。
6. Algorithm Design with Pseudocode | 用伪代码设计算法
Now we write the core procedures. OCR pseudocode uses a syntax similar to Python but with keywords like PROCEDURE, ENDPROCEDURE, IF...THEN...ELSE...ENDIF, and FOR...ENDFOR. Assignment uses the ← symbol. Arrays are indexed from 0. The following examples illustrate borrowing and returning.
现在我们来编写核心过程。OCR 的伪代码使用类似于 Python 的语法,但关键字如 PROCEDURE、ENDPROCEDURE、IF...THEN...ELSE...ENDIF 以及 FOR...ENDFOR。赋值使用 ← 符号。数组索引从 0 开始。以下示例演示了借书和还书过程。
PROCEDURE borrowBook(memberID, ISBN, currentDate)
found ← FALSE
FOR i ← 0 TO LEN(memberList)-1
IF memberList[i] = memberID THEN
found ← TRUE
EXIT FOR
ENDIF
ENDFOR
IF NOT found THEN
OUTPUT "Invalid member ID"
RETURN
ENDIF
count ← 0
FOR i ← 0 TO LEN(loans)-1
IF loans[i].memberID = memberID AND loans[i].status = "on loan" THEN
count ← count + 1
ENDIF
ENDFOR
IF count >= maxBooksPerMember THEN
OUTPUT "Borrowing limit reached"
RETURN
ENDIF
dueDate ← currentDate + 14 days
newLoan ← [memberID, ISBN, dueDate, "on loan"]
loans.APPEND(newLoan)
OUTPUT "Book borrowed successfully, due: " + dueDate
ENDPROCEDURE
这个 borrowBook 过程首先验证会员 ID 是否存在,然后检查该会员当前借阅数量是否已达上限。如果通过,就计算到期日(借阅日加 14 天),创建一条新记录并追加到 loans 列表中。所有的防御性检查都内嵌在逻辑中。
PROCEDURE returnBook(memberID, ISBN, returnDate)
found ← FALSE
FOR i ← 0 TO LEN(loans)-1
IF loans[i].memberID = memberID AND loans[i].ISBN = ISBN AND loans[i].status = "on loan" THEN
found ← TRUE
loanIndex ← i
EXIT FOR
ENDIF
ENDFOR
IF NOT found THEN
OUTPUT "Loan record not found"
RETURN
ENDIF
IF returnDate > loans[loanIndex].dueDate THEN
daysOverdue ← returnDate - loans[loanIndex].dueDate
fine ← daysOverdue * finePerDay
OUTPUT "Fine: £" + fine
ENDIF
loans[loanIndex].status ← "returned"
OUTPUT "Book returned successfully"
ENDPROCEDURE
returnBook 过程查找匹配且状态为“借阅中”的记录,若归还日期晚于到期日则计算罚款,并将记录状态设为“已归还”。罚款金额以 £ 符号输出,精确到小数点后两位仍需进一步格式化,但在算法层面这样表达已经足够清晰。
7. Flowcharts for Visualisation | 流程图可视化
Although it’s not mandatory to draw flowcharts in every question, they can help you think through decision points and loops. For the borrowBook procedure, the flowchart would start with an oval “Start”, then a process box for input, followed by a decision diamond “Is member valid?” with two branches, and a loop to count active loans.
尽管并非每道题都要求画流程图,但它们能帮助你理清决策点和循环。对于 borrowBook 过程,流程图以椭圆形“开始”开始,然后是输入的处理框,接着是菱形判断“会员是否有效?”并有两个分支,以及一个统计活跃借阅数量的循环。
In an exam, you can use standard symbols: rectangle for processes, diamond for decisions, parallelogram for input/output. Always label arrows with Yes/No for decisions, and remember to connect all paths back to a single End symbol. A well-structured flowchart reinforces your algorithmic thinking and can be drawn quickly.
考试中,你可以使用标准符号:矩形表示处理,菱形表示决策判断,平行四边形表示输入/输出。务必在判断分支的箭头上标注 Yes/No,并确保所有路径最终都回到同一个结束符号。一个结构良好的流程图能强化你的算法思维,画起来也很快。
8. Validation and Defensive Design | 验证与防御性设计
Defensive design anticipates misuse and errors. For the library system, we need to validate inputs: member ID must match an entry in the member database; ISBN must be 13 digits and possibly include a check digit; the action must be either 'Borrow' or 'Return'; the current date must be reasonable. Intentionally bad inputs should be rejected with a clear message.
防御性设计需要预判误用和错误。对图书馆系统而言,我们必须验证输入:会员 ID 必须与会员数据库中的条目匹配;ISBN 必须是 13 位数字并可能包含校验位;操作必须是“借阅”或“归还”;当前日期必须合理。故意的错误输入应被拒绝并给出明确的提示信息。
Authentication is also part of design: a librarian might need to log in before running reports. In a full solution, you would add a simple login procedure. Additionally, consider maintainability – using constants for fine rates and loan durations makes the code easier to update.
身份验证也是设计的一部分:图书管理员在运行报告前可能需要登录。在完整的解决方案中,你会增加一个简单的登录过程。此外,还要考虑可维护性——使用常量表示罚款费率和借阅期限会使代码更易于更新。
Edge cases include the very first loan, the last copy of a book, a member who has never borrowed before, and a member returning all books at once. Your algorithms should handle all of these without crashing or losing data.
边界情况包括首次借阅、某本书的最后一本库存、从未借过书的会员,以及会员一次性归还所有图书。你的算法必须能处理所有这些情况,不发生崩溃或丢失数据。
9. Trace Tables and Dry Runs | 追踪表与人工运行
A trace table is an excellent way to verify your algorithms. You set up columns for each variable and a column for output. Then you manually work through the code line by line, updating values at each step. This exposes logic errors like off‑by‑one loop mistakes or incorrectly placed conditions.
追踪表是验证算法的一个极好方法。你为每个变量设置一列,再加一列用于输出,然后逐行手动执行代码,每一步更新变量值。这能暴露出逻辑错误,比如循环差一错误或条件放置不当等。
For the borrowBook procedure, test with a valid member, an invalid member, and a member who already has 5 books on loan. A partial trace for a valid member borrow might look like this:
对于 borrowBook 过程,用有效会员、无效会员以及已有 5 本书在借的会员进行测试。一个有效会员借阅的部分追踪表可能如下所示:
| Line | found | count | dueDate | newLoan | Output |
|---|---|---|---|---|---|
| 1 | FALSE | - | - | - | |
| After member check | TRUE | - | - | - | |
| After count loop | TRUE | 2 | - | - | |
| Date calc | TRUE | 2 | 2025-10-15 | - | |
| After APPEND | TRUE | 2 | 2025-10-15 | [mem01, 1234567890123, 2025-10-15, on loan] | Book borrowed successfully, due: 2025-10-15 |
像这样走查一遍,你能确信当 count=2(小于最大借阅量 5)时流程正确进入借阅创建步骤,且输出与预期相符。如果初始 count 意外地达到了 5,你就会看到“Borrowing limit reached”输出,从而验证边界逻辑。
10. Testing and Refinement | 测试与优化
A thorough test plan should cover normal data, boundary values, and erroneous data. For the library system, normal tests: first borrow, returning on time, and checking current loans. Boundary tests: borrowing when already holding maxBooksPerMember-1 books (should succeed) and when holding max books (should fail). Erroneous tests: invalid member ID, invalid ISBN format, return date before due date (no fine) and far in the future (large fine).
一份全面的测试计划应涵盖正常数据、边界值和错误数据。对图书馆系统而言,正常测试包括:首次借阅、准时归还、查看当前借阅。边界测试包括:在持有 maxBooksPerMember - 1 本书时借阅(应成功)和满额时借阅(应失败)。错误测试包括:无效会员 ID、无效的 ISBN 格式、到期日之前归还(无罚款)以及远在到期日之后归还(产生大额罚款)。
| Test ID | Data Type | Input | Expected Outcome |
|---|---|---|---|
| T1 | Normal | Valid member, valid ISBN, borrow | Loan recorded, due date = today+14 |
| T2 | Boundary | Member with 4 active loans, borrow again | 广告 / Sponsored Linux高级程序设计(高等院校计算机技术十二五规划教材)/刘加海/季江民/浙江大学出版社 计算机 备考教辅 · 正版现货 · 与本文内容相关 查看详情 / View on Taobao参考价 ¥55.6
更多咨询请联系16621398022(同微信) 备考资讯每日更新,关注不错过 考纲变化 · 科目分析 · 学习方法 ![]() 在微信里长按二维码识别关注 或截图后用「扫一扫 → 相册」选择本图 公众号:tutorhao |
