📚 AS WJEC Computer Science: Case Study Practical Walkthrough | AS WJEC 计算机科学:案例分析实战演练
In AS WJEC Computer Science, one of the most valuable ways to prepare for exams is to work through a detailed case study that mirrors real-world systems analysis and design. This article takes you step by step through a practical case study: building a library book-loan management system. We will explore how to interpret requirements, design data structures, choose algorithms, structure the user interface, test the solution, and evaluate the final product. By following this walkthrough, you will see how theory links directly to the kind of scenario-based questions that appear in Unit 1 and Unit 2 of the WJEC specification.
在 AS WJEC 计算机科学中,备考最有价值的方式之一就是完整演练一个贴近真实世界的系统分析与设计案例。本文将带你循序渐进地完成一个实战案例:构建图书馆借书管理系统。我们将一起探讨如何解读需求、设计数据结构、选择算法、搭建用户界面、测试方案并最终评估产品。通过这个演练,你会清楚地看到理论知识如何直接对应到 WJEC 大纲第一单元和第二单元中常见的场景类考题。
1. Understanding the Case Study Scenario | 理解案例背景
The first step is to carefully read the scenario. Imagine a small community library needs a computerised system to manage its book collection and loans. Currently, all records are kept on paper, which leads to missing books and difficulty tracking overdue items. The system must store book details, borrower information, and loan records. It should allow staff to check out books, return them, search for titles, and generate a list of overdue loans. As a candidate, you need to extract the functional requirements from this narrative.
第一步是仔细阅读场景描述。设想一家小型社区图书馆需要一套计算机化系统来管理藏书与借阅。目前所有记录都在纸上,经常出现书籍丢失、难以跟踪逾期的情况。系统必须存储图书详情、借阅者信息和借阅记录,并支持工作人员办理借书、还书、搜索书名以及生成逾期清单。作为考生,你需要从这段叙述中提取出功能需求。
Non-functional requirements are also implied, such as ease of use for staff with minimal training, and the ability to store at least 2000 book records without performance degradation. The system must run on a single desktop computer in the library, so there is no need for a network database.
非功能需求也需要从中推导,例如系统应易于操作,无需大量培训,并且能够存储至少2000条图书记录而不会导致性能下降。由于系统只在图书馆内的一台台式机上运行,因此不需要网络数据库。
Typical WJEC marking schemes reward identification of inputs, outputs, processes, and data storage. For this case study, inputs include book ISBN, borrower ID, and date of loan. Outputs are loan confirmation screens, overdue reports, and search results. Processes include validation of borrower limits and automatic calculation of due dates.
典型的 WJEC 评分标准会奖励对输入、输出、处理过程和数据存储的识别。在本案例中,输入包括图书 ISBN、借阅者 ID 和借阅日期;输出是借阅确认界面、逾期报告和搜索结果;处理过程包括读者借阅限额校验和应还日期的自动计算。
2. Requirements Elicitation and Documentation | 需求获取与文档化
After absorbing the scenario, you should list the core functional requirements in a clear table. This helps when you later justify design decisions. A sample table is shown below.
理解场景后,你应当将核心功能需求清晰地列在一个表格里,这有助于后续论证设计决策。下面是一张示例表格。
| Requirement ID | Description | Priority |
|---|---|---|
| FR1 | Add new book with ISBN, title, author, year | High |
| FR2 | Register borrower (name, contact, membership ID) | High |
| FR3 | Check out book (validate borrower, update loan record) | High |
| FR4 | Return book and calculate fine if overdue | High |
| FR5 | Search books by title keyword | Medium |
| FR6 | Generate overdue loans report | Medium |
In your exam answer, you should also note any assumptions that clarify requirements. For instance, assume a borrower can have at most three active loans, and the standard loan period is 14 days. Fines are calculated at £0.20 per day overdue. These constraints become part of your processing logic.
在考试回答中,你还应该记录下所有用以澄清需求的假设。例如,假设每位读者最多只能同时借阅三本书,标准借阅期为14天,逾期罚款按每天 £0.20 计算。这些约束将成为处理逻辑的一部分。
WJEC exams often ask you to produce a data flow diagram or a system flowchart at this stage. Although this article focuses on textual design, keep in mind that you must be able to represent processes graphically.
WJEC 考试常在这一阶段要求你绘制数据流图或系统流程图。尽管本文重点在于文字设计,但请记住你必须能够用图形方式来表示处理过程。
3. System Design and Architecture | 系统设计与架构
Based on the requirements, a modular approach is best. We will build a console-based application using Python, which is perfectly suitable for AS level. The architecture separates concerns: a data layer handles file‑based storage, a business logic layer contains the rules for loans and fines, and a presentation layer manages the text menus.
基于需求,采用模块化设计最为合适。我们将使用 Python 构建一个控制台应用程序,这完全符合 AS 阶段的要求。架构上做到关注点分离:数据层负责基于文件的存储,业务逻辑层包含借阅与罚款规则,表示层管理文字菜单。
Choosing a simple CSV file for persistent storage satisfies the non-functional requirement of no network database. A flat file is easy to implement and adequate for a collection of 2000 books. The file structure can be designed with clear headers, making it human-readable and easy to debug.
选择简单的 CSV 文件作为持久化存储,既满足了无需网络数据库的非功能需求,又易于实现,而且足以应对2000册图书的体量。文件结构可以设计清晰的标题行,使其可读性强且便于调试。
For the internal data representation, we can use dictionaries and lists. A book dictionary might have keys such as 'ISBN', 'Title', 'Author', and 'Available'. A loan record will link a borrower ID to an ISBN and due date. These data structures will be instantiated when the program starts by reading the CSV files.
在内部数据表示上,我们可以使用字典和列表。一本图书的字典可以包含键 'ISBN'、'Title'、'Author' 和 'Available';一条借阅记录则将读者 ID 与 ISBN 以及应还日期关联起来。这些数据结构将在程序启动时通过读取 CSV 文件来实例化。
4. Data Storage Design and File Handling | 数据存储设计与文件处理
Let's design the flat file schema. We need three files: books.csv, borrowers.csv, and loans.csv. The fields are as follows.
我们来设计平面文件模式。我们需要三个文件:books.csv、borrowers.csv 和 loans.csv。字段如下:
| File | Fields | Key |
|---|---|---|
| books.csv | ISBN, Title, Author, Year, Available | ISBN |
| borrowers.csv | BorrowerID, Name, Contact | BorrowerID |
| loans.csv | LoanID, ISBN, BorrowerID, DateOut, DateDue, DateReturned | LoanID |
Using CSV format means we can easily read and write records with Python's built-in csv module. During checkout, the system must update both the loans.csv file and the Available flag in books.csv. This requires careful transactional handling to avoid data inconsistency.
使用 CSV 格式意味着我们可以利用 Python 内置的 csv 模块轻松读写记录。在办理借书时,系统必须同时更新 loans.csv 和 books.csv 中的可用标志。这需要谨慎的事务处理,以避免数据不一致。
In your WJEC answer, discussing file organisation (serial vs. sequential vs. random) shows depth. Since our program will mostly read entire files into memory on startup and rewrite them on exit, a serial access approach is acceptable. However, for search functionality, loading all records into a dictionary indexed by ISBN provides fast direct access.
在你的 WJEC 回答中,讨论文件组织方式(串行、顺序或随机)能体现深度。由于我们的程序在启动时大多把整个文件读入内存,退出时再写回,因此串行访问方式是可接受的。但对于搜索功能,将所有记录加载到以 ISBN 为索引的字典中可以达到快速直接访问的效果。
5. Algorithm Design: Checkout and Fine Calculation | 算法设计:借书与罚款计算
A central algorithm is the checkout process. It must validate the borrower's active loan count, check book availability, record the current date, and compute the due date. Below is pseudocode representing the logic, which aligns with WJEC expectations for algorithm representation.
借书流程是一个核心算法。它必须验证读者的当前借阅数量、检查图书是否可借、记录当前日期并计算应还日期。下面是表示该逻辑的伪代码,符合 WJEC 对算法表示的期望。
PROCEDURE checkout(borrowerID, ISBN)
IF borrower's current loans >= 3 THEN
OUTPUT "Borrower has reached limit"
RETURN
ENDIF
IF book with ISBN is NOT available THEN
OUTPUT "Book not available"
RETURN
ENDIF
currentDate ← today's date
dueDate ← currentDate + 14 days
CREATE new loan record with currentDate and dueDate
SET book Available flag to False
SAVE updated data to files
OUTPUT "Book loaned successfully. Due: " + dueDate
ENDPROCEDURE
借书流程:如果读者当前借阅数达到3本则拒绝,如果图书不可用则拒绝,否则记录当前日期,计算应还日期为当前日期加14天,创建新借阅记录,将图书可用标志设为 False,保存数据并输出成功信息。
Fine calculation occurs during the return process. The algorithm subtracts the due date from the actual return date. If the difference is positive, multiply by the daily fine rate.
罚款计算在还书流程中发生。算法用实际归还日期减去应还日期;若差值为正,则乘以每日罚款率。
fineAmount = (dateReturned − dateDue) × 0.20, if dateReturned > dateDue
In code, we must handle date arithmetic properly. Python's datetime module allows subtraction of date objects, returning a timedelta. The days property gives the integer number of days. This is a robust solution that avoids manual calendar complexities.
在代码中,我们必须正确处理日期运算。Python 的 datetime 模块允许日期对象相减,返回 timedelta 对象;其 days 属性给出整数天数。这是一种健壮的解决方案,避免了手动日历计算的复杂性。
6. Search and Sorting Algorithms | 搜索与排序算法
The library staff needs to find books by title keyword. A linear search through the list of book dictionaries is straightforward and acceptable for up to 2000 records. While binary search is faster, it requires the list to be sorted, and maintaining sorted order during insertion adds complexity. In an exam, you must justify the trade-off.
图书馆工作人员需要通过书名关键词查找图书。对图书字典列表进行线性搜索简单直接,对于多达2000条记录而言是可接受的。虽然二分搜索更快,但要求列表有序,而在插入时维持有序性会增加复杂性。在考试中,你必须就这一权衡做出论证。
However, if we want to generate a list of overdue books sorted by borrower name, we can apply the bubble sort algorithm. It is easy to understand and implement, and for small datasets it performs adequately. You might be asked to write bubble sort in pseudocode or Python.
然而,如果我们要生成一份按读者姓名排序的逾期图书清单,则可以采用冒泡排序算法。它易于理解和实现,对于小型数据集来说性能足够。你可能会被要求用伪代码或 Python 写出冒泡排序。
Remember that WJEC values efficiency awareness. Even if you use a simple algorithm, mention its time complexity. For linear search, it is O(n) in the worst case; for bubble sort, O(n²). Then suggest that with larger data sets a more efficient algorithm, such as quicksort, would be preferred, but for the scope of this AS project, simplicity is prioritised.
请记住,WJEC 重视效率意识。即使你选择了简单的算法,也要提及其时间复杂度。线性搜索的最坏情况是 O(n);冒泡排序是 O(n²)。然后说明,面对更大数据集时,更高效的算法(如快速排序)会是更好的选择,但就本 AS 项目范围而言,优先考虑简洁性。
7. User Interface Design and HCI Principles | 用户界面设计与人机交互原则
A console menu must be clear and intuitive. We will design a text-based menu driven by numbered options. Each option corresponds to a functional requirement. The menu should loop after completing an action, and validation should prevent crashes from incorrect input.
控制台菜单必须清晰直观。我们将设计一个由数字选项驱动的文字菜单,每个选项对应一项功能需求。菜单应在完成操作后循环显示,输入验证应防止由错误输入导致的崩溃。
LIBRARY SYSTEM 1. Add new book 2. Register borrower 3. Check out book 4. Return book 5. Search book by title 6. Overdue report 7. Exit Choose option:
Applying HCI principles, we use consistency in layout, provide meaningful feedback, and minimise memory load by displaying all choices. For an AS-level discussion, you should link these choices to cognitive psychology principles such as recognition rather than recall.
运用人机交互原则,我们在布局上保持一致性,提供有意义的反馈,并通过显示所有选项来减少用户的记忆负担。在做 AS 层面的讨论时,你应将设计选择联系到认知心理学原理,比如辨识优于回忆。
Error messages must be specific. Instead of 'Invalid input', the system should say 'Invalid option, please enter a number between 1 and 7'. When searching, if no matches are found, the message should read 'No books found containing that keyword'. This reduces user frustration and is a simple way to demonstrate professionalism.
错误消息必须具体。不应只说“无效输入”,而应显示“无效选项,请输入1到7之间的数字”。在搜索时,如果未找到匹配项,应给出“未找到包含该关键词的图书”。这样做能减少用户的挫败感,也是展示专业性的简单方法。
8. Testing Strategy and Test Data | 测试策略与测试数据
Thorough testing is essential for any software project. We will adopt a strategy covering normal, boundary, and erroneous data. A test table documents each test case with its expected outcome and result.
彻底的测试对于任何软件项目都至关重要。我们将采用覆盖正常数据、边界数据和错误数据的策略。通过测试表格记录每个测试用例的预期结果和实际结果。
| Test ID | Description | Input Data | Expected Outcome |
|---|---|---|---|
| T1 | Checkout with valid borrower | borrowerID=B001, ISBN=978-3-16-148410-0 | Success message with due date |
| T2 | Checkout when borrower has 3 loans | Borrower with 3 existing loans | Limit reached message |
| T3 | Search with non-existent title | 'XYZ123' | No books found message |
| T4 | Return book exactly on due date | Return date = due date | No fine, book marked returned |
WJEC expects you to understand the difference between testing and debugging. Testing reveals the presence of errors, while debugging is the process of locating and correcting them. In our case study, we would first perform unit testing on the fine calculation function, then integration testing to be sure the menu correctly calls the right functions.
WJEC 期望你理解测试与调试的区别:测试是为了揭示错误的存在,调试则是定位并修正错误的过程。在我们的案例研究中,我们首先对罚款计算函数进行单元测试,然后进行集成测试,确保菜单正确调用相应功能。
Boundary testing involves the loan limit. We test exactly three loans and then attempt a fourth. Also, test the transition of dates around midnight, though for simplicity we use whole dates. This is a typical AS-level practical element.
边界测试涉及借阅上限。我们测试恰好三本书在借,然后尝试借第四本。此外也应测试日期边界,尽管为简化我们只使用完整日期。这是 AS 实践部分的典型内容。
9. Implementation: Key Code Snippets in Python | 实施:Python 关键代码片段
Below is a simplified version of the checkout function in Python, demonstrating file reading, validation, and date handling. This code follows the pseudocode earlier and would be a major component of the project.
下面是 Python 中简化版的借书函数,展示了文件读取、验证和日期处理。这段代码遵循了前面的伪代码逻辑,是整个项目的主要组成部分。
import csv, datetime def checkout(borrower_id, isbn): # Load current loans and book data loans = [] with open('loans.csv', 'r') as f: reader = csv.DictReader(f) loans = [row for row in reader] active = [l for l in loans if l['BorrowerID'] == borrower_id and l['DateReturned'] == ''] if len(active) >= 3: print("Borrower has reached loan limit.") return # Check book availability books = [] with open('books.csv', 'r') as f: books = list(csv.DictReader(f)) book = next((b for b in books if b['ISBN'] == isbn), None) if not book or book['Available'] == 'False': print("Book not available.") return # Record loan today = datetime.date.today() due = today + datetime.timedelta(days=14) new_loan = {'LoanID': str(len(loans)+1), 'ISBN': isbn, 'BorrowerID': borrower_id, 'DateOut': str(today), 'DateDue': str(due), 'DateReturned': ''} loans.append(new_loan) # Update book availability for b in books: if b['ISBN'] == isbn: b['Available'] = 'False' # Save all with open('loans.csv','w',newline='') as f: writer = csv.DictWriter(f, fieldnames=loans[0].keys()) writer.writeheader(); writer.writerows(loans) with open('books.csv','w',newline='') as f: writer = csv.DictWriter(f, fieldnames=books[0].keys()) writer.writeheader(); writer.writerows(books) print(f"Book loaned. Due date: {due}")
该函数首先读取借阅记录并计算当前读者的活跃借阅数,若超过限额则提示;接着检查图书可用性;然后生成新的借阅记录,更新图书状态,最后将所有数据写回 CSV 文件。这种文件操作方式在 AS 考试中很常见。
For the overdue report, a function iterates through loans.csv, selects those with no return date and a due date before today, then sorts by borrower name using a simple bubble sort. The sorted list is then printed in a formatted table. This demonstrates multiple programming techniques together.
对于逾期报告,一个函数遍历 loans.csv,筛选出未归还且应还日期早于今天的记录,然后用冒泡排序按读者姓名排序,最后将排序后的列表按表格格式打印。这同时展示了多种编程技术。
10. Evaluation and Possible Enhancements | 评估与可能的改进
After implementation, the solution must be evaluated against the original requirements. The system successfully meets all FR1 to FR6. However, we should critique its limitations: the flat file approach is not scalable to multiple concurrent users; there is no password protection for staff; the search is case-sensitive and requires exact substring matching. Such reflective thinking is highly valued in WJEC extended answers.
实施完成后,必须对照原始需求对方案进行评估。该系统成功满足了 FR1 至 FR6 的所有要求。但我们也应批判其局限性:平面文件方式无法扩展到多用户并发;没有工作人员密码保护;搜索区分大小写且需要精确子串匹配。这种反思性思维在 WJEC 扩展题中极受重视。
Future enhancements could include migrating to an SQLite database, which still runs on a single machine but offers better data integrity and querying. Adding a graphical user interface with Tkinter would improve usability, though this is beyond AS scope. We could also implement a reservation queue for popular books. These suggestions show an awareness of real-world software evolution.
未来的改进方向可包括迁移到 SQLite 数据库,这仍可在单机上运行,但能提供更好的数据完整性和查询能力;添加 Tkinter 图形用户界面能提升可用性,尽管这超出了 AS 课程范围;还可以为热门图书实现预约队列。这些建议展示了对真实世界软件演进的认知。
In an exam, if you are asked to write an evaluation, you should always link back to the user requirements and clearly state what works well and what could be better. Remember to use technical vocabulary such as scalability, maintainability, and usability.
在考试中,如果你被要求写一份评估,务必始终回到用户需求上,清晰说明哪些方面做得好、哪些可以改进。记得使用专业术语,如可扩展性、可维护性和易用性。
Published by TutorHao | AS WJEC Computer Science Revision Series | aleveler.com
更多咨询请联系16621398022(同微信)

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