← 返回资讯屏轩教育 · 行业资讯

Cambridge Year 9 Computing: Case Study Practical Drill | 剑桥Year 9计算机:案例分析实战演练

2026-07-19 10:29 · 本文部分内容由AI辅助创作

📚 Cambridge Year 9 Computing: Case Study Practical Drill | 剑桥Year 9计算机:案例分析实战演练

In this article, we will walk through a complete case study to strengthen your computational thinking and programming skills. You will analyse a real‑world scenario, design a solution, and implement it using Python. By working step by step, you will see how abstract concepts like decomposition, algorithms and testing come together in a practical project. This exercise is tailored for Year 9 Cambridge Computing, focusing on problem‑solving and clear documentation.

在这篇文章中,我们将通过一个完整的案例来强化你的计算思维和编程技能。你将分析一个真实场景,设计解决方案,并用 Python 实现它。通过逐步操作,你会看到分解、算法和测试等抽象概念如何在一个实际项目中协同工作。本次练习专为剑桥 Year 9 计算机课程设计,着重培养问题解决能力和清晰的文档记录。

1. Introduction to the Case Study | 案例介绍

Imagine your school library wants a simple digital system to track book loans. Librarians currently use paper cards, which often get lost or contain mistakes. The goal is to create a program that allows them to borrow and return books by entering a book ID and a student ID. The program should check whether a book is available before lending it, record the loan date, and update the stock count automatically. This small but useful tool will be our case study.

假设你学校的图书馆想要一个简单的数字系统来跟踪图书借阅。目前,管理员使用纸质卡片,这些卡片经常丢失或出错。目标是创建一个程序,通过输入图书编号和学生编号来借书和还书。程序应在借出前检查图书是否可借,记录借阅日期,并自动更新库存数量。这个虽小但实用的工具就是我们的案例。


2. Problem Definition and Requirements | 问题定义与需求

We must first list clear requirements. The user needs to: (1) borrow a book – associate a student ID with an available book ID and record today's date; (2) return a book – mark the book as available again and remove the loan record; (3) view current stock – show how many copies of each book are on the shelf. Error messages must appear if a book is not in the catalogue or if it is already on loan. The system must handle multiple copies of the same title.

我们必须首先列出清晰的需求。用户需要:(1)借书——将学生编号与可借的图书编号关联,并记录当天日期;(2)还书——将图书重新标记为可借,并移除借阅记录;(3)查看当前库存——显示每种图书在架上的册数。如果图书不在目录中或者已被借出,必须显示错误消息。系统需要处理同一书名的多个副本。

A well‑defined problem statement saves time later. Write down the scope: we will store data in a Python dictionary during a single session (no permanent database). Inputs are book ID and student ID. Outputs are confirmation messages and stock displays. Edge cases include trying to borrow a nonexistent book, returning a book that is not on loan, and borrowing when all copies are taken.

一个明确的问题陈述可以节省后期时间。写下范围:我们将在单个会话期间用 Python 字典存储数据(没有永久数据库)。输入是图书编号和学生编号。输出是确认消息和库存显示。边界情况包括:尝试借阅不存在的书、归还一本未借出的书,以及在所有副本都被借走时借书。


3. Decomposition: Breaking Down the Task | 分解任务

Decomposition helps us manage complexity. We split the system into manageable parts: a data module for storing book information, an input handler to receive user commands, a borrowing function, a returning function, and a display function. Each part can be designed and coded independently.

分解有助于我们管理复杂性。我们将系统拆分为可管理的部分:一个用于存储图书信息的数据模块、一个接收用户命令的输入处理程序、一个借书函数、一个还书函数和一个显示函数。每个部分都可以独立设计和编码。

We also identify repeated patterns. The check 'is the book ID valid?' appears in both borrowing and returning. By writing a separate validation function, we avoid duplicate code. Decomposition makes the solution easier to test because we can verify each function in isolation before combining them.

我们还识别出重复的模式。‘图书编号是否有效?’这一检查同时出现在借书和还书中。通过编写一个单独的验证函数,我们避免了重复代码。分解使解决方案更易于测试,因为我们可以在组合功能之前单独验证每个函数。


4. Identifying Inputs, Processes, and Outputs | 识别输入、处理与输出

eck if book_id exists in catalogue; (2) If yes, check number of available copies > 0; (3) If available, reduce stock by 1, add loan record with date; (4) Else, display error. Output: a success or error message, and updated stock count shown on screen.

对于每个函数,我们定义一个输入‑处理‑输出表。先关注借书操作。输入:book_id(字符串类型),student_id(字符串类型)。处理:(1)检查 book_id 是否在目录中;(2)如果是,检查可用副本数是否大于 0;(3)如果可用,库存减 1,添加带日期的借阅记录;(4)否则,显示错误。输出:成功或错误消息,以及屏幕上显示的更新后库存数。

InputsProcessOutputs
book_id, student_idValidate book, check copies, updateConfirmation/Error message

输入:book_id、student_id。处理:验证图书、检查副本、更新。输出:确认/错误消息。


5. Algorithm Design: Flowchart | 算法设计:流程图

e borrowing flow: Start → Input book_id and student_id → Decision: Is book_id in catalogue? (No → Output 'Book not found' → End) (Yes → Decision: Are copies available? > 0?) (No → Output 'No copies left' → End) (Yes → Reduce stock by 1, record loan (book_id, student_id, date) → Output 'Book borrowed successfully' → End).

流程图将处理过程转化为清晰的视觉计划。我们可以用标准符号绘制,但这里用文字描述。借书流程:开始 → 输入 book_id 和 student_id → 判断:book_id 是否在目录中?(否 → 输出 ‘Book not found’ → 结束)(是 → 判断:可用副本数 > 0?)(否 → 输出 ‘No copies left’ → 结束)(是 → 库存减 1,记录借阅信息(book_id, student_id, date) → 输出 ‘Book borrowed successfully’ → 结束)。

Using a flowchart helps spot logic errors early. Arrows show the direction, and diamonds represent decisions. Year 9 students often draw these on paper before coding. The return process is similar but checks if the book is currently on loan before adding the copy back.

使用流程图有助于尽早发现逻辑错误。箭头表示方向,菱形表示判断。Year 9 的学生经常在编码前在纸上画出这些图。还书流程类似,但在将副本加回之前,要检查该书当前是否处于借出状态。


广告 / Sponsored

6. Pseudocode | 伪代码

Pseudocode bridges the gap between flowchart and actual code. It uses structured English and avoids strict syntax rules. Below is the borrowing function in pseudocode:

伪代码是连接流程图和实际代码的桥梁。它使用结构化的英语,避免严格的语法规则。以下是借书函数的伪代码:

FUNCTION borrow_book(book_id, student_id)
    IF book_id NOT IN catalogue THEN
        PRINT "Book not found"
        RETURN
    ENDIF
    IF catalogue[book_id]["available"] EQUALS 0 THEN
        PRINT "No copies available"
        RETURN
    ENDIF
    catalogue[book_id]["available"] = catalogue[book_id]["available"] - 1
    loans.APPEND({book_id: book_id, student_id: student_id, date: TODAY})
    PRINT "Book borrowed successfully"
END FUNCTION

我们从伪代码开始,以便专注逻辑而非 Python 细节。注意关键结构:IF 语句、缩进和数组操作。你可以将上面的每一行译成 Python。还书伪代码会检查借阅记录中是否存在该图书编号和学生编号,然后增加可用副本数并移除该条记录。


7. Python Implementation – Part 1: Setting Up | Python 实现 – 第一部分:初始化

Use a dictionary for the catalogue: keys are book_id strings, values are dictionaries with 'title' and 'available' (integer). We also create an empty list for loans. A sample setup:

现在,我们将设计转换为真正的 Python 代码。我们首先在 Python 脚本中初始化数据结构。目录使用字典:键是 book_id 字符串,值是一个包含 'title' 和 'available'(整数)的字典。我们还创建一个空列表用于存放借阅记录。一个示例设置:

catalogue = {
    "B101": {"title": "Computer Science Basics", "available": 3},
    "B102": {"title": "Python for Beginners", "available": 2}
}
loans = []  # list of dictionaries

我们还将导入 datetime 模块,以便为每笔借阅自动获取当前日期。from datetime import date。主程序循环会显示一个菜单,要求输入选项(借书、还书、查看库存、退出),然后调用对应的函数。清晰的初始化使后续测试更加一致。


8. Python Implementation – Part 2: Main Functions | Python 实现 – 第二部分:主要功能

ollowing the pseudocode. It takes two parameters, performs validation, updates the catalogue, and appends a loan dictionary. Error messages provide feedback to the librarian. Here is a simplified version:

我们按照伪代码编写 borrow_book() 函数。它接受两个参数,执行验证,更新目录,并追加一个借阅字典。错误消息向管理员提供反馈。以下是简化版本:

def borrow_book(book_id, student_id):
    if book_id not in catalogue:
        print("Error: Book ID not recognised.")
        return
    if catalogue[book_id]["available"] == 0:
        print("All copies are currently on loan.")
        return
    catalogue[book_id]["available"] -= 1
    loans.append({"book_id": book_id, "student_id": student_id, "date": date.today()})
    print("Book borrowed successfully.")

return_book() 函数循环遍历 loans 列表,查找匹配的条目。找到后,使用 list.remove() 移除该条目,并将 catalogue 中对应图书的 available 值加 1。如果找不到匹配项,则输出一条错误消息,表明该书并未被该学生借出。


9. Testing and Debugging | 测试与调试

Testing is crucial to verify correctness. We plan test cases covering normal scenarios, boundary cases, and invalid inputs. A test table like the one below helps document results.

测试对于验证正确性至关重要。我们设计的测试用例覆盖正常场景、边界情况和无效输入。类似下面的测试表有助于记录结果。

Test IDDescriptionInputsExpectedPass/Fail
1Borrow available bookB101, STU01Success, available drops to 2Pass
2Borrow when 0 copies(after 3 loans of B101)Error messagePass
3Invalid book IDB999, STU01'Book not found'Pass

测试 1:借阅在架图书 — 成功,可用数降为 2。测试 2:副本为 0 时借阅 — 显示错误。测试 3:无效图书编号 — 显示“未找到图书”。我们还测试还书错误情况,比如归还未借出的书。调试时,使用 print() 语句追踪变量值。


10. Evaluation and Reflection | 评估与反思

After the system works, we reflect on what went well and what could be improved. The program successfully handles basic borrowing and returning, gives clear feedback, and prevents common mistakes. However, it does not save data permanently; once the program closes, all records are lost. Future versions could use a file or a database.

系统可以运行后,我们反思哪些方面做得好,哪些可以改进。程序成功处理了基本的借阅和归还,给出清晰的反馈,并防止了常见错误。然而,它不会永久保存数据;程序关闭后,所有记录都会丢失。未来的版本可以使用文件或数据库。

Another limitation is the text‑based interface. A graphical user interface (GUI) would be more user‑friendly. Additionally, we could add features such as due dates, fines for late returns, and search by title. Documenting the development process, including the flowchart and pseudocode, is valuable for maintenance.

另一个局限是文本界面。图形用户界面(GUI)会更加友好。此外,我们可以添加诸如到期日期、逾期罚款以及按书名搜索等功能。记录开发过程,包括流程图和伪代码,对维护工作很有价值。

This case study demonstrates that a systematic approach – define, decompose, design, implement, test, evaluate – leads to robust software. Even a simple library tracker teaches transferable skills applicable to larger projects.

本案例研究表明,系统化的方法——定义、分解、设计、实现、测试、评估——能打造出健壮的软件。即便是简单的图书跟踪器,也能传授适用于更大项目的可迁移技能。


Published by TutorHao | 计算机 Revision Series | aleveler.com

广告 / Sponsored
现货 Cambridge International AS & ALevel IT Coursebook剑桥国际IGC…
计算机 备考教辅 · 正版现货 · 与本文内容相关
查看详情 / View on Taobao参考价 ¥467.0

更多咨询请联系16621398022(同微信)

备考资讯每日更新,关注不错过
考纲变化 · 科目分析 · 学习方法
扫码关注公众号 tutorhao
在微信里长按二维码识别关注
或截图后用「扫一扫 → 相册」选择本图
公众号:tutorhao