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

Year 8 WJEC Computer Science: Case Study Practical Exercises | Year 8 WJEC 计算机:案例分析实战演练

2026-07-17 21:40 · 本文部分内容由AI辅助创作

📚 Year 8 WJEC Computer Science: Case Study Practical Exercises | Year 8 WJEC 计算机:案例分析实战演练

This article presents a hands-on case study designed for Year 8 students following the WJEC Computer Science curriculum. You will work through a realistic project – building a simple library book borrowing system – applying computational thinking, programming, and data handling skills. Each section includes an English explanation followed by its Chinese equivalent, making it ideal for bilingual revision and classroom use.

本文专为学习 WJEC 计算机课程的八年级学生设计,通过一个真实的项目——构建一个简单的图书馆借书系统——来实践计算思维、编程和数据处理技能。每个部分都提供英文说明和对应的中文解释,非常适合双语复习和课堂教学。

1. Understanding the Problem | 理解问题

Every successful software project begins with a clear problem statement. Our library needs a system to record which books are borrowed, by whom, and when they are due. We must define the inputs (book title, borrower name, date), processes (check availability, calculate return date), and outputs (confirmation message or overdue alert).

每个成功的软件项目都始于清晰的问题陈述。我们的图书馆需要一个系统来记录哪些书被借出、借阅人是谁以及应还日期。我们需要定义输入(书名、借阅人姓名、日期)、处理(检查可借状态、计算归还日期)和输出(确认信息或逾期提醒)。

2. Decomposition and Abstraction | 分解与抽象

We break the system into smaller, manageable parts: a login module, a search function, a borrowing recorder, and a report generator. Abstraction helps us focus on essential details, such as storing only the borrower ID rather than full personal data, and ignoring the physical size of the books.

我们将系统分解成较小的、可管理的部分:登录模块、搜索功能、借阅记录器和报告生成器。抽象帮助我们关注关键细节,例如只存储借阅人 ID 而不是完整的个人数据,并忽略书籍的物理尺寸。

For example, a book can be represented by a simple record containing its ISBN and title. A borrower is just an ID and a name.

例如,一本书可以用包含 ISBN 和书名的简单记录表示。借阅人只是一个 ID 和姓名。

3. Flowchart Design | 流程图设计

A flowchart visually maps the borrowing process. Use standard symbols: ovals for Start/End, rectangles for processes, diamonds for decisions. Below is a simplified flowchart for checking out a book:

流程图以可视化方式描绘借阅过程。使用标准符号:椭圆形表示开始/结束,矩形表示处理步骤,菱形表示判断。以下是借出图书的简化流程图:

Start → Enter Book ID → Check Availability → (Available?) → Yes → Record Loan → Output Success → End

开始 → 输入图书 ID → 检查可借状态 → (可借?) → 是 → 记录借阅 → 输出成功 → 结束

If the book is not available, the flow goes to an error message and then back to the start.

如果书不可借,流程则转向错误信息,然后返回开始。

4. Writing Pseudocode | 编写伪代码

Pseudocode uses plain English (or any language) to outline the logic without worrying about syntax. Here is a borrowing routine:

伪代码使用简明英语(或任何语言)来勾勒逻辑,无需担心语法。以下是一个借阅例程:

BEGIN
  INPUT book_id, borrower_id
  IF book is available THEN
    SET due_date = today + 14 days
    UPDATE book status to "borrowed"
    DISPLAY "Book borrowed. Return by", due_date
  ELSE
    DISPLAY "Book not available"
  ENDIF
END

This makes it easy to discuss and refine the algorithm before coding.

这使得在编码之前讨论和完善算法变得容易。

5. Data Structures and Variables | 数据结构与变量

To store library data, we can use a dictionary in Python. Each book is keyed by its ID, with values for title, author, status, and current borrower.

为了存储图书馆数据,我们可以在 Python 中使用字典。每本书以其 ID 为键,值包括书名、作者、状态和当前借阅人。

Variable (变量)Data Type (数据类型)Example (示例)
book_idstring"BK101"
borrower_namestring"Alice"
due_datedate / string"2025-05-20"
statusBoolean / string"available"

Using meaningful variable names and appropriate data types is a key programming skill.

使用有意义的变量名和合适的数据类型是一项关键的编程技能。

6. Implementing in Python | 用 Python 实现

We can now code the borrowing function. Here is a simplified example using a list of dictionaries:

现在我们可以编写借阅功能的代码。以下是一个使用字典列表的简化示例:

library = [
    {"id":"BK101","title":"Python Basics","status":"available","borrower":""},
    {"id":"BK102","title":"Data Science","status":"available","borrower":""}
]

def borrow_book(book_id, borrower):
    for book in library:
        if book["id"] == book_id:
            if book["status"] == "available":
                book["status"] = "borrowed"
                book["borrower"] = borrower
                return f"Success: {book['title']} borrowed by {borrower}"
            else:
                return "Sorry, book not available."
    return "Book ID not found."

This code searches the library, checks availability, and updates the record. It returns a message to the user.

广告 / Sponsored

这段代码搜索馆藏、检查可借状态并更新记录。它向用户返回一条消息。

7. Testing and Debugging | 测试与调试

Testing is vital. We must try normal values (existing available book), boundary values (borrowing the last copy), and invalid inputs (wrong book ID). A test table helps organise this:

测试至关重要。我们必须尝试正常值(现有可借的书)、边界值(借出最后一本)和无效输入(错误的图书 ID)。测试表有助于组织测试:

Test Case (测试用例)Input (输入)Expected Output (预期输出)
Borrow available book"BK101", "Alice"Success message
Borrow already borrowed book"BK101", "Bob""not available"
Invalid ID"BK999""not found"

Debugging involves tracing the code when a test fails, perhaps by printing variable values at each step.

调试涉及在测试失败时跟踪代码,也许是在每个步骤打印变量值。

8. Evaluation and Reflection | 评估与反思

After implementation, reflect on what worked well and what could be improved. Does the system meet all the original requirements? Could the user interface be clearer? Are there any performance issues if the library has thousands of books? A good evaluation considers both strengths and weaknesses.

实现后,反思哪些地方做得好,哪些可以改进。系统是否满足所有原始需求?用户界面是否可以更清晰?如果图书馆有数千本书,是否存在性能问题?好的评估需要考虑优点和缺点。

For instance, using a linear search in a large list is slow; we could later learn about more efficient data structures.

例如,在大型列表中使用线性搜索较慢;我们以后可以学习更高效的数据结构。

9. Binary and Data Representation | 二进制与数据表示

Computers store everything in binary. A book ID like 'BK101' is represented as ASCII codes, but knowing how to convert the year of publication to binary reinforces data representation skills. For example, the number 2025 in binary is:

计算机以二进制存储一切。像 'BK101' 这样的图书 ID 以 ASCII 码表示,但知道如何将出版年份转换为二进制可以加强数据表示技能。例如,数字 2025 的二进制是:

÷ 2 = 31 R1 → 31 ÷ 2 = 15 R1 → 15 ÷ 2 = 7 R1 → 7 ÷ 2 = 3 R1 → 3 ÷ 2 = 1 R1 → 1 ÷ 2 = 0 R1

Reading the remainders backwards gives 11111101001₂.

从下往上读取余数得到 11111101001₂。

Understanding binary also helps when setting file permissions or compressing library data.

理解二进制在设置文件权限或压缩图书馆数据时也有帮助。

10. Cybersecurity Considerations | 网络安全考虑

Our library system handles borrower names and maybe passwords. We must protect this data. Use strong password policies, never store passwords in plain text (apply hashing), and validate all inputs to prevent SQL injection if a database is connected. Even in a simple Python program, input sanitisation prevents crashes.

我们的图书馆系统处理借阅人姓名,可能还有密码。我们必须保护这些数据。使用强密码策略,绝不以明文存储密码(应用哈希),并验证所有输入,以防止连接数据库时的 SQL 注入。即使在一个简单的 Python 程序中,输入清理也可以防止崩溃。

A basic check could be: if len(borrower_name) > 50: then reject the input.

基本检查可以是:如果借阅人姓名长度大于 50,则拒绝该输入。

11. Working Collaboratively | 协作工作

Real-world software is built by teams. In this case study, you can work in pairs: one person writes the borrowing function, another writes the return function. Use version control (even a shared folder with dated copies) and communicate clearly. Discuss interfaces – how will the two functions share data?

现实世界的软件由团队构建。在本案例研究中,你可以结对工作:一个人编写借阅函数,另一个人编写归还函数。使用版本控制(即使是带有日期的共享文件夹)并清晰沟通。讨论接口——两个函数将如何共享数据?

Agreeing on a common data structure (like the list of dictionaries) is essential for integration.

就通用数据结构(如字典列表)达成一致对于集成至关重要。

12. Extension: Adding a Graphical User Interface | 扩展:添加图形用户界面

Once the command-line version works, you can create a simple GUI using Python's Tkinter. Add labels, entry boxes, and buttons. The event-driven nature of GUIs introduces new concepts: callback functions and widgets.

一旦命令行版本工作正常,你可以使用 Python 的 Tkinter 创建一个简单的 GUI。添加标签、输入框和按钮。GUI 的事件驱动特性引入了新概念:回调函数和控件。

For example, a button "Borrow" can call the borrow_book() function when clicked, using the values from the entry fields. This makes the system more user-friendly and mirrors real applications.

例如,一个“借书”按钮可以在单击时调用 borrow_book() 函数,使用来自输入字段的值。这使得系统更加用户友好,并反映了真实的应用程序。

This extension provides an excellent opportunity to stretch your programming abilities.

这个扩展为拉伸你的编程能力提供了绝佳机会。

Published by TutorHao | Computer Science Revision Series | aleveler.com

广告 / Sponsored
Linux高级程序设计(高等院校计算机技术十二五规划教材)/刘加海/季江民/浙江大学出版社
计算机 备考教辅 · 正版现货 · 与本文内容相关
查看详情 / View on Taobao参考价 ¥55.6

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

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