📚 Year 11 AQA Computer Science: Case Study Practice | 11年级AQA计算机:案例分析实战演练
Case study questions are a key feature of the AQA GCSE Computer Science exam, testing your ability to apply computational thinking in realistic scenarios. This guided practice will walk you through a school library management system, from analysing requirements to writing pseudocode and testing solutions, so you can tackle any case study with confidence.
案例分析题是 AQA GCSE 计算机考试的核心特色,考查你在真实场景中运用计算思维的能力。本次引导式实战将带你一步步构建一个学校图书馆管理系统,从需求分析、编写伪代码到测试方案,让你自信应对任何案例。
1. Understanding the Scenario | 理解场景
A local secondary school wants a digital system to replace its paper-based library records. The system must store details of all books, keep track of which students have borrowed them, and allow staff to process borrow and return transactions quickly. It should also support searching for a book by its ISBN or title.
一所本地中学希望用数字系统取代纸质图书馆记录。系统需存储所有图书信息、跟踪哪些学生借了书,并让工作人员能快速办理借阅和归还手续。还应支持按 ISBN 或书名搜索图书。
The key actors are the librarian and the students. There are approximately 2,000 books and 500 students in the school. The system must be simple enough to run on a single desktop computer without an internet connection.
主要角色是图书管理员和学生。学校约有 2000 册图书和 500 名学生。系统要足够简单,能在单台无互联网连接的台式机上运行。
2. Identifying Inputs, Outputs and Processes | 识别输入、输出与处理过程
Inputs include book details (ISBN, title, author, status), student details (ID, name, books borrowed count) and transaction requests (borrow or return). The librarian types a command followed by relevant data.
输入包括图书信息(ISBN、书名、作者、状态)、学生信息(学号、姓名、已借数量)以及事务请求(借书或还书)。管理员输入一个命令及其相关数据。
Outputs are confirmation messages, lists of books currently on loan, overdue notices, and search results. The system must also write updated data back to files so records persist between sessions.
输出包括确认消息、当前借出图书列表、逾期通知和搜索结果。系统还需将更新数据写回文件,以便在会话之间保持记录。
Core processes: add a new book, delete a book, register a student, borrow a book, return a book, search by ISBN or title, and display all borrowed books for a student.
核心处理过程:添加新书、删除图书、注册学生、借书、还书、按 ISBN 或书名搜索,以及显示某学生的所有借阅记录。
3. Data Structures and Variables | 数据结构与变量
We define a record type Book with fields: isbn: STRING, title: STRING, author: STRING, available: BOOLEAN. A second record type Student holds: studentID: STRING, name: STRING, numBooks: INTEGER.
我们定义一个记录类型 Book,字段为:isbn: STRING、title: STRING、author: STRING、available: BOOLEAN。另一个记录类型 Student 包含:studentID: STRING、name: STRING、numBooks: INTEGER。
Books are stored in an array books[1:2000] of type Book. Students are stored in an array students[1:500]. A 2D array loans[1:500, 1:5] tracks which ISBNs each student currently has, assuming a maximum of 5 books per student.
图书存储在类型为 Book 的数组 books[1:2000] 中。学生存储在数组 students[1:500] 中。一个二维数组 loans[1:500, 1:5] 记录每个学生当前借阅的 ISBN,假设每生最多借 5 本。
Global variables hold the current number of books (bookCount) and students (studentCount). File handling routines load and save these arrays at startup and shutdown.
全局变量保存当前图书数量(bookCount)和学生数量(studentCount)。文件处理例程在启动和关闭时加载与保存这些数组。
4. Designing the Borrowing Algorithm | 设计借书算法
The algorithm must: check the student exists, verify they have not reached the 5-book limit, confirm the book is available, mark the book as unavailable, add the ISBN to the student’s loans row, and increment numBooks.
算法必须:检查学生是否存在,验证该生未达到 5 本上限,确认图书可借,将图书标记为不可借,把 ISBN 加入该生 loans 行,并使 numBooks 加 1。
PROCEDURE borrowBook(studentID, isbn)
studentIndex ← findStudent(studentID)
IF studentIndex = -1 THEN
OUTPUT "Student not found"
RETURN
ENDIF
IF students[studentIndex].numBooks ≥ 5 THEN
OUTPUT "Borrow limit reached"
RETURN
ENDIF
bookIndex ← findBook(isbn)
IF bookIndex = -1 OR NOT books[bookIndex].available THEN
OUTPUT "Book unavailable"
RETURN
ENDIF
books[bookIndex].available ← FALSE
students[studentIndex].numBooks ← students[studentIndex].numBooks + 1
position ← students[studentIndex].numBooks
loans[studentIndex, position] ← isbn
OUTPUT "Book borrowed successfully"
ENDPROCEDURE
注意,辅助函数 findStudent 和 findBook 通过线性搜索返回索引,若未找到则返回 -1。借书成功后,loans 数组中填入 ISBN。
5. Pseudocode for Returning a Book | 还书伪代码
Returning a book reverses the borrowing steps: locate the student, find the ISBN in their loans array, remove it by shifting subsequent entries left, mark the book as available, and decrement numBooks.
还书操作逆转借书步骤:定位学生,在其 loans 数组中找到该 ISBN,通过左移后续条目删除它,将图书标记为可借,并使 numBooks 减 1。
PROCEDURE returnBook(studentID, isbn)
studentIndex ← findStudent(studentID)
IF studentIndex = -1 THEN
OUTPUT "Student not found"
RETURN
ENDIF
found ← FALSE
FOR i ← 1 TO students[studentIndex].numBooks
IF loans[studentIndex, i] = isbn THEN
FOR j ← i TO students[studentIndex].numBooks - 1
loans[studentIndex, j] ← loans[studentIndex, j+1]
NEXT j
students[studentIndex].numBooks ← students[studentIndex].numBooks - 1
found ← TRUE
EXIT FOR
ENDIF
NEXT i
IF NOT found THEN
OUTPUT "Book not in student's loan record"
RETURN
ENDIF
bookIndex ← findBook(isbn)
books[bookIndex].available ← TRUE
OUTPUT "Book returned successfully"
ENDPROCEDURE
这种做法明确了在还书时可能出现的错误:学生未借该 ISBN 或记录不匹配。通过将后续元素左移,我们保持了数组的连续性与 numBooks 的一致性。
6. Searching for Books Efficiently | 高效搜索图书
A linear search over 2,000 books is acceptable for a school library, but we can improve performance for title searches if the array is sorted alphabetically by title. A binary search then reduces worst-case comparisons from O(n) to O(log₂ n).
对 2000 册书进行线性搜索在学校图书馆场景中尚可接受,但若按书名字母顺序排序,便可使用二分搜索,将最坏情况下的比较次数从 O(n) 降至 O(log₂ n)。
We keep the books array sorted by insertion. When a new book is added, it is placed in the correct alphabetical position, pushing later elements right. This type of sorted insertion maintains order at the cost of shifting elements.
我们通过插入时保持图书数组有序。添加新书时,将其放在正确的字母位置上,并将后续元素右移。这种有序插入方式虽需移动元素,但维持了顺序。
For ISBN search, a simple linear search is sufficient because ISBNs are unique and the array is small. However, a hash table could give O(1) average lookup time if the collection grew substantially.
对于 ISBN 搜索,简单的线性搜索已足够,因为 ISBN 唯一且数组较小。但如果馆藏大幅增长,可使用哈希表实现 O(1) 的平均查找时间。
7. Validating User Input | 用户输入验证
Defensive design prevents the system from crashing or behaving unexpectedly. Every user input must be validated. An ISBN must be exactly 13 digits; student ID must follow the pattern "S" followed by 4 digits. Book titles and author names must not be empty.
防御性设计防止系统崩溃或异常行为。每个用户输入都必须经过验证。ISBN 必须恰好为 13 位数字;学号需遵循 'S' 后跟 4 位数字的格式。书名和作者姓名不能为空。
We use input validation routines, e.g. FUNCTION isValidISBN(isbn) RETURNS BOOLEAN, that check length and use a loop to confirm only digits. If validation fails, the program should output an error and re-prompt the user.
我们使用输入验证子程序,例如 FUNCTION isValidISBN(isbn) RETURNS BOOLEAN,检查长度并用循环确认只有数字。若验证失败,程序应输出错误并提示用户重新输入。
For menu choices like 'B' for borrow, 'R' for return, the program should ignore case and reject any unexpected character. This prevents logic errors further down.
对于菜单选项,如借书 'B'、还书 'R',程序应忽略大小写并拒绝非预期字符。这可以防止后续逻辑错误。
8. Handling Errors and Exceptions | 错误与异常处理
File operations can fail if files are missing or corrupted. The system should check whether the data files exist on startup and, if not, initialise empty arrays and create them. When saving, it should handle disk full errors gracefully.
文件操作可能因文件丢失或损坏而失败。系统应在启动时检查数据文件是否存在;若不存在,则初始化空数组并创建它们。保存时应妥善处理磁盘满错误。
Using TRY…EXCEPT (or equivalent in the chosen language) for file I/O improves robustness. If an exception occurs, the program can inform the user and avoid data loss by keeping a backup in memory until the issue is resolved.
在文件 I/O 中使用 TRY…EXCEPT(或所选语言的等效机制)可提升健壮性。若发生异常,程序可通知用户并保留内存备份,直至问题解决,避免数据丢失。
Additionally, the system should prevent borrowing a book already on loan, and should not allow returning a book that is marked available. Checks built into the procedures act as internal safeguards.
此外,系统应阻止借出已借出的图书,也不应允许归还标记为可借的图书。嵌入过程的检查作为内部安全防护。
9. Testing the System: Normal, Boundary, Erroneous | 测试系统:正常、边界、异常
Thorough testing is essential. We design test cases covering normal operation, boundary values, and invalid inputs.
全面测试至关重要。我们设计测试用例,覆盖正常操作、边界值和非法输入。
| Test Case | Input | Expected Output |
|---|---|---|
| Normal borrow | Valid student, available ISBN | Success message, book marked unavailable |
| Borrow limit | Student with 5 loans tries to borrow | 'Borrow limit reached' |
| Unavailable book | ISBN already on loan | 'Book unavailable' |
| Invalid ISBN format | 'abc123' | 'Invalid ISBN format' |
| Missing file | Delete books.dat before loading | System creates new empty file, no crash |
边界测试包括借第一本和最后一本(第 5 本),还书后 numBooks 变为 0,以及搜索空数组。异常测试包括输入特殊字符、超长字符串和学生 ID 不存在等。
10. Flowchart Representation | 流程图表示
e borrow logic. The main steps: Start → Input studentID and ISBN → Validate student exists? (No → Error, End) → Yes → Check number of books < 5? (No → Error, End) → Yes → Book available? ror, End) → Yes → Mark book unavailable, update loans and numBooks → Output success → End.
流程图有助于将借书逻辑可视化。主要步骤:开始 → 输入 studentID 和 ISBN → 学生存在?(否 → 错误,结束) → 是 → 借书数量 < 5?(否 → 错误,结束) → 是 → 图书可借?(否 → 错误,结束) → 是 → 标记图书不可借,更新 loans 和 numBooks → 输出成功 → 结束。
Each decision uses a diamond symbol, while processes use rectangles. The same structure can be drawn for the return procedure, but with an additional loop to find the ISBN in the loans array.
每个判断使用菱形符号,处理过程使用矩形。同样的结构也可用于还书过程,但多了一个在 loans 数组中查找 ISBN 的循环结构。
11. Evaluating the Solution | 评估解决方案
This system fulfils the school’s basic needs: it stores data persistently, handles borrow/return workflows, and provides search functionality. Using arrays keeps the design simple and memory‑efficient for 2,000 books.
该系统满足学校的基本需求:持久存储数据、处理借还流程,并提供搜索功能。使用数组使设计简洁,且对于 2000 册图书而言内存效率良好。
However, arrays have fixed sizes; if the library expands beyond 2,000 books, the program would need recompilation or dynamic resizing. A queue for reservation requests is missing, and there is no due-date tracking or fine calculation, which could be added later.
然而,数组大小固定,如果图书馆馆藏超过 2000 册,程序需要重新编译或动态调整大小。缺少预约请求队列,也没有到期日跟踪或罚金计算,这些可在后续添加。
Additionally, the interface is text-based, which may be less user-friendly than a graphical interface. Security is minimal – any user can access librarian functions. Adding a password check would improve data integrity.
此外,界面为纯文本,可能不如图形界面友好。安全性较低——任何用户均可访问管理员功能。添加密码校验可提高数据完整性。
12. Extending the System | 系统扩展
To make the system more robust, you could incorporate a date module to record loan dates and calculate fines for overdue books. This would require a dueDate field in the loan record and a function to compare dates.
为使系统更健壮,可加入日期模块以记录借阅日期并计算逾期罚金。这需要在借阅记录中增加 dueDate 字段以及比较日期的函数。
A reserve queue implemented as a linear queue data structure would allow students to join a waiting list for popular titles. Once a book is returned, the next waiting student gets a notification.
用线性队列数据结构实现预约队列,可使学生加入热门图书的等候列表。一旦图书归还,下一位等待的学生即可收到通知。
Moving from a flat file to a SQLite database would simplify many operations and support concurrency if multiple librarians need access. It would also make it easier to generate reports, such as most‑borrowed authors or overdue lists.
从平面文件迁移到 SQLite 数据库将简化许多操作,并在多位管理员需要访问时支持并发。它还使生成报告更为容易,如借阅最多的作者或逾期清单。
Published by TutorHao | Computer Science Revision Series | aleveler.com
更多咨询请联系16621398022(同微信)

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