📚 Year 9 WJEC Computer Science: Case Study Practical Workshop | Year 9 WJEC 计算机:案例分析实战演练
In this case study, you will step into the role of a systems analyst to develop a digital solution for a school library. By working through a real‑world scenario, you will apply computational thinking, practise writing algorithms in pseudocode, and connect abstract ideas to concrete hardware and software decisions. Each section pairs an English explanation with the equivalent Chinese translation so you can strengthen your technical vocabulary in both languages.
在这个案例分析中,你将扮演系统分析师的角色,为学校图书馆开发一个数字解决方案。通过处理真实世界的场景,你将应用计算思维,练习用伪代码编写算法,并将抽象概念与具体的硬件和软件决策联系起来。每个小节都配有英文解释和对应的中文翻译,帮助你加强双语技术词汇。
1. Understanding the Scenario: What the Library Needs | 理解场景:图书馆需要什么
Our school library currently uses paper cards to track borrowing. The librarian wants a computerised system that can register students, allow them to borrow and return books, search for titles, and show which books are available. This is our project scope – we must design and plan the system before writing a single line of code.
我们学校的图书馆目前使用纸质卡片记录借阅情况。图书管理员想要一个计算机系统,可以注册学生、允许他们借书和还书、搜索书名,并显示哪些书可供借阅。这就是我们的项目范围——我们必须先设计和规划系统,然后再编写哪怕一行代码。
We record all requirements in a simple list so nothing is forgotten:
我们将所有需求记录在一个简单的列表中,以免遗漏:
- Enrol students with name and ID
- 学生注册,包含姓名和学号
- Add books with title, author and barcode
- 添加图书,包含书名、作者和条形码
- Borrow a book – change its status to ‘on loan’ and record who took it
- 借书——将状态改为“已借出”并记录借阅人
- Return a book – change status back to ‘available’
- 还书——将状态改回“可借”
- Search by title or author
- 搜索按书名或作者
- Report overdue books automatically
- 自动报告逾期图书
2. Decomposition: Breaking Down the Problem | 分解:拆解问题
Decomposition is about splitting a large problem into smaller, manageable parts. For our library, we can break the system into modules: User Management, Book Inventory, Borrowing Transactions, and Reporting. Each module can then be designed separately.
分解是把一个大问题拆分成更小、更易于管理的部分。对于我们的图书馆系统,我们可以把它分成几个模块:用户管理、图书库存、借阅交易和报告。然后可以分别设计每个模块。
Think of it like building with Lego bricks – if we try to build the whole castle at once, we get lost. By sorting bricks by colour and shape first (modules), the task becomes clearer.
可以想象成搭建乐高积木——如果我们试图一次性搭完整座城堡,就会迷失方向。先把积木按颜色和形状分类(模块),任务就会变得更清晰。
Here is a simple breakdown diagram in words:
以下是一个用文字表示的简单分解图:
| Library System |
| 1. Student Registration |
| 2. Book Database |
| 3. Borrow/Return Logic |
| 4. Search Engine |
| 5. Overdue Alert |
3. Pattern Recognition: Spotting Similarities | 模式识别:发现相似之处
Once the problem is decomposed, we look for patterns. Borrowing and returning a book both involve changing a book’s status and updating a transaction log. Registration of students and adding books both store data in a list. Recognising these patterns helps us write reusable code instead of repeating ourselves.
问题被分解后,我们就要寻找模式。借书和还书都涉及更改图书的状态和更新交易记录。注册学生和添加书籍都是将数据存储到列表中。识别出这些模式有助于我们编写可复用的代码,而不是重复编写。
For example, we can design one function called update_status that works for both borrowing and returning by passing a parameter that indicates the new status. This saves time and reduces errors.
例如,我们可以设计一个名为 update_status 的函数,通过传入一个表示新状态的参数,使其既能处理借出,也能处理归还。这节省了时间并减少了错误。
Another pattern: searching by title and searching by author use the same logic – look through a list and compare a keyword – only the field we compare changes. So one search function can serve both.
另一个模式:按书名搜索和按作者搜索使用相同的逻辑——遍历列表并比较关键词——只有我们比较的字段不同。因此一个搜索功能可以同时服务两者。
4. Abstraction: Filtering Out the Noise | 抽象:滤除无关细节
Abstraction means focusing on what is important and ignoring details that do not matter for the current stage. When we model a student, we only need their name, ID number and perhaps their form class. We do not need to store their favourite colour or shoe size – that is irrelevant noise.
抽象意味着专注于重要的部分,忽略当前阶段不需要的细节。当我们给一个学生建模时,我们只需要他们的姓名、学号或许还有班级。我们不需要存储他们最喜欢的颜色或鞋码——这些都是无关的噪音。
In the book data, we care about title, author, barcode, and status. We ignore the colour of the cover or the number of pages for now. This keeps our model simple and efficient. Abstraction is a crucial skill because real‑world data is messy, and we must extract only the essential attributes.
在图书数据中,我们关心书名、作者、条形码和状态。目前我们忽略了封面颜色或页数。这让我们的模型保持简单和高效。抽象是一项关键技能,因为现实世界的数据杂乱无章,我们必须只提取基本属性。
We can represent a book as a dictionary (or record) like this:
我们可以像这样将一本书表示为一个字典(或记录):
| attribute | example value |
| title | “The Hobbit” |
| author | “J.R.R. Tolkien” |
| barcode | “9876543210” |
| status | available |
5. Algorithm Design: Flowcharts and Pseudocode | 算法设计:流程图与伪代码
Before coding, we plan the logic with algorithms. The most common tools are flowcharts and pseudocode. Let’s design the borrow‑book process. A flowchart uses symbols: ovals for start/end, parallelograms for input/output, rectangles for processes, and diamonds for decisions. Below is a textual description that you can draw.
在编码之前,我们用算法来规划逻辑。最常用的工具是流程图和伪代码。我们来设计借书流程。流程图使用各种符号:椭圆表示开始/结束,平行四边形表示输入/输出,矩形表示处理,菱形表示判断。下面是一段文字描述,你可以把它画出来。
- Start → Input student ID and book barcode
- 开始 → 输入学生ID和图书条形码
- Check: Is student registered? If no → show error, go to end.
- 检查:学生是否已注册?若否 → 显示错误,转至结束。
- Check: Is book in catalogue? If no → show error, go to end.
- 检查:图书是否在目录中?若否 → 显示错误,转至结束。
- Check: Is book status ‘available’? If no → show error, go to end.
- 检查:图书状态是否为“可借”?若否 → 显示错误,转至结束。
- Set book status to ‘on loan’, record student ID and due date.
- 将图书状态设为“已借出”,记录学生ID和到期日期。
- Output success message → End
- 输出成功信息 → 结束
Now we write the same logic in pseudocode, which looks like a mix of English and programming keywords. This is not real code but it is easy to convert later.
现在我们用伪代码编写相同的逻辑,它看起来像是英语和编程关键字的混合体。这不是真正的代码,但以后很容易转换。
Pseudocode: Borrow a book
BEGIN
INPUT studentID, barcode
IF studentID NOT IN studentList THEN
OUTPUT "Student not found"
ELSE IF barcode NOT IN bookList THEN
OUTPUT "Book not found"
ELSE IF book.status != "available" THEN
OUTPUT "Book already out"
ELSE
book.status ← "on loan"
book.borrowerID ← studentID
book.dueDate ← today + 14 days
OUTPUT "Borrow successful"
END IF
END
6. Data Representation: Variables and Data Types | 数据表示:变量与数据类型
Every piece of information in a program is stored in a variable, and each variable has a data type. In our library system we will use these types:
程序中的每一条信息都存储在一个变量中,每个变量都有一个数据类型。在我们的图书馆系统中,我们将使用以下类型:
- String – for name, title, barcode (even if barcode looks like a number, we do not calculate with it, so treat it as a string)
- 字符串 – 用于姓名、书名、条形码(即使条形码看起来像数字,我们不进行计算,所以当作字符串处理)
- Integer – for student ID, number of days borrowed
- 整型 – 用于学生ID、借阅天数
- Boolean – for status flags, e.g. isOverdue (True/False)
- 布尔型 – 用于状态标志,例如 isOverdue (True/False)
- Date – for due dates, though we may store it as a string in a fixed format for simplicity
- 日期型 – 用于到期日,不过为简单起见,我们可以用固定格式的字符串存储
Choosing the correct data type is important because it determines what operations can be performed. Adding two integers gives a sum; adding two strings joins them together.
选择正确的数据类型很重要,因为它决定了可以执行哪些操作。两个整数相加得到一个和;两个字符串相加会将它们连接起来。
We also use a data structure called an array (or list) to hold many books. In pseudocode we might declare a 2D array or a list of records:
我们还使用一种称为数组(或列表)的数据结构来存放多本书。在伪代码中,我们可以声明一个二维数组或一个记录列表:
bookRecords ← [ ] // an empty list
Each element in this list can be a structure containing title, author, barcode, status. In Python this would be a list of dictionaries.
列表中的每个元素可以是一个结构体,包含书名、作者、条形码和状态。在Python中,这会是一个字典列表。
7. Control Structures: Sequence, Selection, Iteration | 控制结构:顺序、选择和迭代
All programs are built from three basic control structures. Sequence is the default – instructions run one after another. Selection allows the program to take different paths (IF‑THEN‑ELSE). Iteration repeats a block of code (FOR, WHILE loops). Let’s see them in action.
所有程序都由三种基本控制结构构建而成。顺序是默认的——指令一条接一条地执行。选择允许程序走不同的路径(IF‑THEN‑ELSE)。迭代重复执行一段代码(FOR、WHILE循环)。我们来看看它们是如何工作的。
In the borrow algorithm, we used selection to check conditions. For iteration, imagine we need to print all overdue books. We would loop through the book list and test each one:
在借书算法中,我们用选择来检查条件。对于迭代,假设我们需要打印所有逾期图书。我们会遍历图书列表并对每一本进行测试:
FOR each book IN bookList DO
IF book.dueDate < today AND book.status = "on loan" THEN
OUTPUT book.title, student.borrowerName
END IF
ENDFOR
This combination of iteration and selection is extremely common. The WHILE loop is used when we don’t know in advance how many times to repeat – for example, asking for a valid student ID until one is entered correctly.
这种迭代与选择的结合非常常见。当预先不知道需要重复多少次时,就使用WHILE循环——例如,反复要求输入有效学号直到输入正确为止。
WHILE valid = False DO
INPUT studentID
IF studentID IN studentList THEN
valid ← True
ELSE
OUTPUT “ID not recognised, try again”
END IF
ENDWHILE
8. Input and Output Devices in Context | 上下文中的输入与输出设备
A real library system needs hardware to interact with users. Input devices capture data; output devices present information. Let’s choose what the librarian would use.
真实的图书馆系统需要硬件来与用户交互。输入设备捕获数据;输出设备呈现信息。我们来选一下图书管理员会用到的设备。
- Barcode scanner (input): reads the barcode from a student card or book instantly, reducing typing errors.
- 条码扫描器(输入):瞬间读取学生卡或书本上的条形码,减少录入错误。
- Keyboard and mouse (input): for manual searches and data entry when needed.
- 键盘和鼠标(输入):用于需要时的手动搜索和数据录入。
- Touchscreen monitor (input/output): allows staff to tap options quickly; also displays the interface.
- 触摸屏显示器(输入/输出):让工作人员可以快速点击选项,同时显示界面。
- Printer (output): to print overdue notices or receipts for students.
- 打印机(输出):打印逾期通知或给学生打印收据。
- Speaker (output): optional for audio alerts when a book is overdue.
- 扬声器(输出):可选,用于图书逾期时的声音提醒。
When we design the user interface, we consider how these peripherals connect to the computer. In a network, the system may use a server to store the database and thin clients (basic terminals) for the librarian desk.
当我们设计用户界面时,我们要考虑这些外设如何连接到计算机上。在网络中,系统可能使用服务器存储数据库,并为管理员办公桌配置瘦客户端(基础终端)。
9. Storage and Data Structures: Keeping Data Alive | 存储与数据结构:让数据持久
Variables disappear when the program stops. To keep student and book records permanently, we must use secondary storage – usually a hard disk or SSD in the server. The data will be saved in a file or a database.
当程序停止时,变量就消失了。为了永久保存学生和图书记录,我们必须使用二级存储——通常是服务器中的硬盘或固态硬盘。数据将保存在文件或数据库中。
We can model the library with two flat files: students.csv and books.csv. Each line is a record, with commas separating fields. A database would be better for a real system, but CSV is easy to understand and manipulate in Year 9.
我们可以用两个平面文件来模拟图书馆:students.csv 和 books.csv。每一行是一条记录,用逗号分隔字段。对于真实系统来说数据库会更好,但在九年级阶段,CSV 易于理解和操作。
In pseudocode we will read the file into a list at the start and write it back when changes are made. This simulates persistent storage:
在伪代码中,我们会在开始时将文件读入列表,并在更改后将其写回。这模拟了持久存储:
OPEN “books.csv” FOR READ
read all lines into bookList
CLOSE FILE
… make changes …
OPEN “books.csv” FOR WRITE
FOR each book IN bookList DO
write book.title, book.author, book.barcode, book.status
ENDFOR
CLOSE FILE
10. Testing and Debugging: Does It Work? | 测试与调试:能正常工作吗?
No system is complete without testing. We must plan test cases that cover normal operation, boundary values, and erroneous data. For the borrow function, test with:
未经测试的系统是不完整的。我们必须规划测试用例,覆盖正常操作、边界值和错误数据。对于借书功能,可以用以下情况测试:
- Normal case: Valid student, available book → success
- 正常情况:有效学生,可借阅的书 → 成功
- Error case: Student not registered → message displayed
- 错误情况:学生未注册 → 显示信息
- Error case: Book already on loan → message displayed
- 错误情况:图书已借出 → 显示信息
- Boundary: Borrowing on the due date itself – is the book considered overdue?
- 边界:在到期日当天借书——书会被视为逾期吗?
- Extreme: Very long barcode strings, special characters in names
- 极端:非常长的条形码字符串,姓名中包含特殊字符
Debugging is the art of finding and fixing faults. Common bugs in our system could be forgetting to update the file after a transaction, using the wrong data type (e.g. comparing a string due date with a date object), or an infinite loop in the WHILE validation. We use trace tables to follow variable values step by step.
调试是发现并修复故障的艺术。我们系统中常见的错误可能有:交易后忘记更新文件、使用了错误的数据类型(例如将字符串到期日与日期对象比较)、或WHILE验证中出现无限循环。我们使用追踪表来逐步跟踪变量的值。
A trace table for the borrow logic might look like:
借书逻辑的追踪表可能是这样的:
| step | studentID entered | studentFound? | output |
| 1 | “S101” | True | — |
| 2 | “S999” | False | “Student not found” |
11. Networks and Security: Keeping Data Safe | 网络与安全:保护数据安全
If multiple library computers share the book database, they form a Local Area Network (LAN). This raises security concerns. Only the librarian should be able to add or modify books; students might only view the catalogue. We implement user authentication with a username and password.
如果多台图书馆电脑共享图书数据库,它们就构成了一个局域网(LAN)。这就产生了安全隐患。只有图书管理员应该能够添加或修改图书;学生可能只能查看目录。我们通过用户名和密码实现用户身份验证。
A simple login screen checks credentials against a stored list. Passwords should never be displayed on screen (masked input). We also consider data backup – the book list is copied regularly to a separate drive, so if the server fails, records are not lost.
一个简单的登录界面会根据存储列表检查凭证。密码绝不应显示在屏幕上(密文输入)。我们还考虑数据备份——定期将图书列表复制到单独的驱动器上,这样即使服务器故障,记录也不会丢失。
Another security concept is validation. When data is entered, the program rejects anything obviously wrong. For example, a student ID must be in the format “S” followed by three digits. The barcode must be numeric and 13 digits long. This prevents garbage data from entering the system.
另一个安全概念是验证。输入数据时,程序会拒绝任何明显错误的内容。例如,学生ID必须是“S”后跟三位数字的格式。条形码必须为数字且长度为13位。这可以防止垃圾数据进入系统。
We can express the ID validation rule as:
我们可以将ID验证规则表达为:
IF LEN(studentID) ≠ 4 OR LEFT(studentID,1) <> “S” THEN
OUTPUT “Invalid ID format”
END IF
12. Evaluation and Real‑World Connections | 评估与现实世界联系
After implementing the system, we reflect on what went well and what could improve. Did our abstraction capture all necessary details? Did the user interface feel intuitive? Real libraries use sophisticated Integrated Library Systems (ILS) that incorporate RFID, automatic email alerts, and web catalogues. Our case study is a simplified but accurate model of those systems.
实施系统后,我们反思哪些方面做得好,哪些可以改进。我们的抽象是否捕获了所有必要的细节?用户界面是否感觉直观?真实的图书馆使用复杂的集成图书馆系统(ILS),它们结合了RFID、自动电子邮件提醒和网络目录。我们的案例研究是这些系统的一个简化但准确的模型。
This workshop has given you hands‑on experience in the full lifecycle: analysis, design, algorithm creation, testing and evaluation. These steps are the same whether you build a library system, a game, or a mobile app. The key is to start with computational thinking, then use the tools of abstraction, decomposition and pattern recognition to guide your coding.
本次实战演练让你亲身体验了完整的生命周期:分析、设计、算法创建、测试和评估。无论你构建的是图书馆系统、游戏还是移动应用,这些步骤都是一样的。关键是从计算思维开始,然后运用抽象、分解和模式识别这些工具来指导你的编码。
Published by TutorHao | Computer Science Revision Series | aleveler.com
更多咨询请联系16621398022(同微信)
屏轩国际教育cambridge primary/secondary checkpoint, cat4, ukiset,ukcat,igcse,alevel,PAT,STEP,MAT, ibdp,ap,ssat,sat,sat2课程辅导,国外大学本科硕士研究生博士课程论文辅导