📚 Case Study: School Library Borrowing System | 案例分析:学校图书馆借阅系统
In this revision session, we will work through a complete case study that ties together problem-solving and programming skills required for CIE IGCSE Computer Science. By analysing a simplified school library borrowing system, you will see how computational thinking — decomposition, pattern recognition, abstraction, and algorithm design — can be applied to a real-world scenario. Follow each step carefully; at the end you will be equipped to tackle similar questions in the exam.
在这次复习中,我们将通过一个完整的案例分析,串联起 CIE IGCSE 计算机科学所需的问题解决与编程技能。通过分析一个简化的学校图书馆借阅系统,你将看到计算思维——分解、模式识别、抽象和算法设计——如何应用于真实场景。请仔细跟进每一步;结束时你将有能力应对考试中的类似问题。
1. Problem Definition and Requirements Analysis | 问题定义与需求分析
The school librarian currently manages loans using paper cards. They want a digital system that can record which book is borrowed by which student, calculate due dates, handle returns, and automatically compute fines for late returns. The system must also prevent a book from being borrowed if it is already on loan, and allow the librarian to check the current status of any book.
学校图书管理员目前使用纸质卡片管理借阅。他们希望有一个数字系统,能够记录哪本书被哪个学生借出、计算到期日、处理还书,并自动计算逾期罚款。系统还必须防止一本已被借出的书再次被借出,并允许管理员查询任何书籍的当前状态。
Non-functional requirements include that the system should respond to a query in under two seconds, store data in a simple file so that no database server is needed, and provide clear error messages when, for example, an incorrect student ID is entered.
非功能性需求包括:系统应在两秒内响应查询,使用简单文件存储数据以省去数据库服务器,并在输入例如错误的学生ID时提供清晰的错误提示。
2. Decomposition and Abstraction | 分解与抽象
We can break the whole system into four main modules: Student Registration, Book Management, Loan Processing, and Fine Calculation. Each module can be developed and tested independently. For instance, the Loan Processing module must handle borrowing, returning, and status checking.
我们可以将整个系统分解为四个主要模块:学生注册、书籍管理、借阅处理与罚款计算。每个模块可以独立开发与测试。例如,借阅处理模块需要处理借书、还书和状态查询。
Abstraction helps us focus on essential information. For a student we only need a student ID and name; details such as address or phone number are ignored. For a book we need a book ID, title, and a flag indicating if it is currently borrowed. The exact cover image or publisher is not relevant in this context.
抽象帮助我们聚焦于必要信息。对于学生,我们只需要学生ID和姓名;地址或电话号码等细节被忽略。对于一本书,我们需要书号、书名以及一个表示当前是否借出的标志。书的封面图片或出版商在此场景下并不相关。
3. Input, Output, and Storage Requirements | 输入、输出与存储需求
The system will receive input such as book IDs, student IDs, and commands (e.g. 'BORROW', 'RETURN', 'CHECK'). Outputs include on-screen messages confirming a transaction, displaying book status, or showing the fine amount. All outputs should be plain text, as the school's computers do not have graphical capability.
系统接收的输入包括书号、学生ID和指令(例如 'BORROW'、'RETURN'、'CHECK')。输出包括在屏幕上显示交易确认、书籍状态或罚款金额的消息。所有输出应为纯文本,因为学校的计算机没有图形功能。
Data must persist even when the computer is turned off. We will use two simple text files: books.txt storing book ID, title, status (0 for available, 1 for borrowed), and borrower student ID if borrowed; students.txt storing student ID and name. Using comma-separated values (CSV) makes parsing straightforward in Python.
数据必须在计算机关闭后仍然保留。我们将使用两个简单的文本文件:books.txt 存储书号、书名、状态(0 表示可借,1 表示已借出)以及借阅者学生ID(若已借出);students.txt 存储学生ID和姓名。使用逗号分隔值(CSV)格式可以方便地用 Python 解析。
4. Algorithm Design: Borrowing a Book (Pseudocode) | 算法设计:借书流程(伪代码)
The borrowing algorithm must validate the student and book, check availability, and update records. Below is a structured pseudocode representation of the core logic. Notice the sequence, selection, and iteration constructs required by the syllabus.
借书算法必须验证学生和书籍的有效性、检查可借状态并更新记录。下面是核心逻辑的结构化伪代码表示。请注意考纲所要求的顺序、选择和循环结构。
BEGIN
INPUT studentID, bookID
validStudent ← checkStudentExists(studentID)
IF validStudent = False THEN
OUTPUT "Error: Student not found"
STOP
ENDIF
bookStatus ← getBookStatus(bookID)
IF bookStatus = "BORROWED" THEN
OUTPUT "Book already on loan"
ELSE
SET book status to BORROWED
dueDate ← today + 14 days
store borrower studentID
OUTPUT "Loan successful. Due date: ", dueDate
ENDIF
END
This pseudocode uses INPUT, OUTPUT, assignment (←), and conditional branches. In an actual program, the functions getBookStatus and checkStudentExists would read the text files.
该伪代码使用了 INPUT、OUTPUT、赋值(←)和条件分支。在实际程序中,函数 getBookStatus 和 checkStudentExists 会读取文本文件。
5. Algorithm Design: Returning a Book (Flowchart Description) | 算法设计:还书流程(流程图描述)
Although we cannot draw a flowchart here, the logical steps are equivalent to diagram shapes. The process begins by accepting the book ID. A decision symbol checks if the book exists and is marked as borrowed. If yes, the return is processed: the book status is set to available, the calculated fine (if any) is displayed, and the borrower field is cleared. If the book is not found or already available, an appropriate error message is output.
虽然此处无法绘制流程图,但逻辑步骤与图形元素对应。流程从接收书号开始。一个判断菱形检查书是否存在且标记为已借出。如果满足,处理还书:将书籍状态设为可借,显示计算出的罚款(如有),并清除借阅者字段。如果书未找到或已处于可借状态,则输出相应的错误消息。
Key flowchart symbols that would appear: a terminal (start/end) oval, a parallelogram for input/output, a rectangle for processing (update status), and a diamond for decisions. Labelling arrows with "Yes" and "No" ensures clarity.
会出现的流程图符号包括:起止框(椭圆)、输入输出框(平行四边形)、处理框(矩形,用于更新状态)和判断框(菱形)。给箭头标上"是"和"否"可确保清晰。
6. Data Structure Choices: Arrays and Files | 数据结构选择:数组与文件
When the program reads books.txt into memory, it can store the records in a two-dimensional array (or a list of lists in Python). Each row corresponds to one book. Index 0 holds the book ID, index 1 the title, index 2 the status (0/1), and index 3 the borrower student ID. This arrangement allows quick lookup by index and easy updating before writing back to the file.
当程序将 books.txt 读入内存时,它可以把记录存储在一个二维数组(或 Python 中的列表的列表)中。每一行对应一本书。索引 0 存放书号,索引 1 存放书名,索引 2 存放状态(0/1),索引 3 存放借阅者学生ID。这种安排允许通过索引快速查找,并易于在写回文件前进行更新。
Using a 1D array for a single book and a 2D array for the collection demonstrates the concept of data structures. The syllabus expects you to be able to declare and manipulate arrays: for example, books = [["001", "Computing Basics", 0, ""], ["002", "Algorithms 101", 1, "S1234"]]. Looping through the 2D array lets you search for a specific book ID.
使用一维数组表示单本书,二维数组表示藏书集合,体现了数据结构的概念。考纲要求你能够声明和操作数组,例如:books = [["001", "Computing Basics", 0, ""], ["002", "Algorithms 101", 1, "S1234"]]。通过遍历该二维数组,可以搜索特定的书号。
7. Handling Edge Cases and Errors | 边界情况与错误处理
Robust software handles incorrect inputs gracefully. For this system, edge cases include: a student ID that does not exist, a book ID not in the catalogue, trying to borrow a book that is already borrowed, returning a book that is not on loan, and entering a non-numeric string when a number is expected. Each case must produce a clear message rather than crashing the program.
健壮的软件能够妥善处理错误输入。对于本系统,边界情况包括:不存在的学生ID、不在目录中的书号、尝试借阅已借出的书、归还一本未经借阅的书,以及输入非数字字符串却期望数字。每种情况必须产生清晰的提示,而不是使程序崩溃。
We can add input validation routines. For instance, after reading the studentID, the program iterates through the student array. If no match is found, it outputs "Student ID not recognised" and loops back to ask for the input again. Similarly, date formats should be validated before calculation.
我们可以添加输入验证例程。例如,在读取学生ID后,程序遍历学生数组。如果未找到匹配项,则输出"学生ID未识别",并循环回去再次请求输入。类似地,日期格式应在计算前进行验证。
8. Testing Strategy: Normal, Boundary, and Erroneous Data | 测试策略:正常、边界与异常数据
A solid test plan increases the reliability of any program. According to CIE guidelines, you must be able to select appropriate test data. For the borrow function, a normal test would use a valid student ID and an available book ID. The expected outcome is a successful loan with a due date exactly 14 days from today.
周全的测试计划能够提升程序的可靠性。根据 CIE 指南,你必须能够选择适当的测试数据。对于借书功能,正常测试会使用一个有效的学生ID和一本可借的书号。预期结果是借阅成功,到期日恰好为今天的 14 天后。
Boundary tests focus on the limits of conditions. Since the loan period is 14 days, returning a book exactly on the due date should incur no fine; returning one day late should trigger the minimum fine. Another boundary test is when the student IDs or book IDs are at the maximum allowed length (e.g. 5 characters). Erroneous tests include injecting negative numbers, symbols, or leaving fields blank.
边界测试关注条件的极限。由于借阅期限为 14 天,在到期日当天还书应无罚款;逾期一天应触发最低罚款。另一个边界测试是学生ID或书号达到允许的最大长度(例如 5 个字符)。异常测试包括输入负数、符号或留空字段。
9. Test Data Table and Expected Results | 测试数据表格与预期结果
The table below illustrates a structured test plan for the borrowing module. It covers normal, boundary, and erroneous cases. In an exam, you might be asked to complete such a table.
下表展示了借书模块的结构化测试计划。它覆盖了正常、边界和异常情况。考试中可能会要求你补全类似的表格。
| Test ID | studentID | bookID | Type | Expected Outcome |
|---|---|---|---|---|
| T1 | S101 | B001 | Normal | Loan successful; due date today+14 |
| T2 | S102 | B001 | Boundary (book already borrowed) | Error: Book already on loan |
| T3 | S999 | B001 | Erroneous | Error: Student not found |
| T4 | S101 | B999 | Erroneous | Error: Book ID invalid |
| T5 | '' (empty) | B001 | Erroneous | Error: Student ID cannot be empty |
Notice how each test targets a distinct logical path through the algorithm. This coverage ensures that all decision branches are exercised at least once, a concept known as statement coverage in validation.
注意每个测试都针对算法中不同的逻辑路径。这种覆盖确保所有决策分支至少执行一次,这一概念在验证中称为语句覆盖。
10. Key Implementation Considerations | 代码实现要点
When coding the solution in a high-level language like Python, you will use file-handling commands (open, readlines, write), string manipulation (split, strip), and control structures. Always close files after reading or writing to avoid data corruption. Use meaningful variable names such as book_status and due_date to improve maintainability.
当用 Python 等高级语言编写解决方案时,你会使用文件操作命令(open、readlines、write)、字符串处理(split、strip)和控制结构。务必在读写后关闭文件,以避免数据损坏。使用有意义的变量名,如 book_status 和 due_date,以提高可维护性。
Fine calculation uses the formula: fine ← number_of_days_late × daily_rate. For example, if the daily rate is £0.10 and a book is overdue by 3 days, the fine is 3 × 0.10 = £0.30. This requires handling dates; Python's datetime module provides a datetime.date.today() to compute date differences.
罚款计算使用公式:罚款 ← 逾期天数 × 日罚金。例如,若日罚金为 £0.10,一本书逾期 3 天,则罚款为 3 × 0.10 = £0.30。这需要处理日期;Python 的 datetime 模块提供了 datetime.date.today() 来计算日期差。
11. Summary and Exam Tips | 总结与考试提示
This case study has reinforced the full development lifecycle: from requirements and decomposition through algorithm design, data structure choice, test planning, and code implementation. When tackling CIE IGCSE Computer Science questions, always show your working — whether it is pseudocode, a partial flowchart, or a test table. Examiners credit logical steps even if the final syntax is imperfect.
本案例分析强化了完整的开发生命周期:从需求和分解开始,到算法设计、数据结构选择、测试计划及代码实现。在应对 CIE IGCSE 计算机科学考题时,务必展示你的思考过程——无论是伪代码、部分流程图还是测试表格。即使最终语法不完美,评分员也会认可逻辑步骤。
Finally, practice writing pseudocode for different scenarios (e.g. returning a book with fine calculation) and become fluent in identifying suitable test data. Keep your answers precise and linked to the problem given in the question paper. Good luck with your revision!
最后,练习为不同场景(例如带罚款计算的还书)编写伪代码,并熟练掌握识别合适测试数据的能力。保持答案精确并与试卷所给问题紧密相关。祝复习顺利!
Published by TutorHao | Computer Science Revision Series | aleveler.com
更多咨询请联系16621398022(同微信)

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