📚 Case Study Practical Exercise | 案例分析实战演练
In this article, we will work through a complete case study to develop a simple library borrowing system. You will see how to break down a problem, design a solution using flowcharts and pseudocode, and then write and test a program. This step‑by‑step approach mirrors the way real software is built and will help you master the key skills required for the CIE Year 8 Computer Science course.
在这篇文章中,我们将通过一个完整的案例分析来构建一个简单的图书馆借阅系统。你会看到如何分解问题、使用流程图和伪代码设计解决方案,然后编写并测试程序。这种逐步推进的方法反映了真实软件的开发方式,能帮助你掌握 CIE 八年级计算机课程所需的关键技能。
1. Understanding the Problem | 理解问题
We are asked to create a program for a school library. A student can borrow up to 2 books at a time. If they try to borrow a third book, the system should refuse and show a message. The program must ask for the student’s name and the number of books they already have, then decide whether to allow the new borrowing.
我们需要为学校图书馆创建一个程序。一名学生一次最多可以借阅 2 本书。如果他们试图借第三本书,系统应拒绝并显示一条消息。程序必须询问学生的姓名和他们当前已借书的数量,然后决定是否允许新的借阅。
The inputs are: student name (text) and current books (a whole number). The output is either a confirmation message “Borrowing allowed” or a rejection message “Maximum books reached”. This is a simple decision problem.
输入为:学生姓名(文本)和当前借书数量(整数)。输出为确认消息“允许借阅”或拒绝消息“已达到最大借书数量”。这是一个简单的决策问题。
2. Decomposition | 问题分解
We split the task into smaller parts. First, collect the inputs. Second, check if the current number of books is less than 2. Third, display the appropriate message. Each part can be coded and tested separately.
我们将任务拆分成更小的部分。首先,收集输入。其次,检查当前借书数量是否小于 2。第三,显示相应的消息。每个部分可以单独编写代码并测试。
Decomposition helps us see the structure: input → process → output. The processing step contains a condition (if‑else). No repetition is needed for this simple version.
分解帮助我们看清结构:输入→处理→输出。处理步骤包含一个条件(if‑else)。这个简单版本不需要循环。
3. Pattern Recognition | 模式识别
This problem is similar to many other decision‑based programs, such as checking age limits for a game or verifying a password length. The pattern is: read a value, compare it with a limit, and produce one of two possible outputs.
这个问题与许多其他基于决策的程序相似,例如检查游戏年龄限制或验证密码长度。其模式为:读取一个值,与限制进行比较,并产生两种可能输出中的一种。
Recognising the “limit check” pattern means we can reuse the same logic structure whenever we need to test whether a number is below or above a boundary.
识别出“限制检查”模式意味着每当我们需要测试一个数字是否低于或高于某个边界时,都可以重复使用相同的逻辑结构。
4. Abstraction | 抽象
We strip away unnecessary details. We do not need to know the actual book titles, the student’s grade, or the library’s inventory. The only essential information is the current number of books. We model the borrowing rule as: if current_books < 2 then allow, else deny.
我们剥离掉不必要的细节。我们不需要知道实际的书名、学生的年级或图书馆的库存。唯一必要的信息是当前借书数量。我们将借阅规则建模为:如果 current_books < 2 则允许,否则拒绝。
This abstraction makes the solution easy to implement and test. It also means the program can work for any library with a similar policy, simply by changing the number 2 to a different limit.
这种抽象使得解决方案易于实现和测试。这也意味着,对于拥有类似政策但借书上限不同的图书馆,只需将数字 2 改为其他限制,程序就能适用。
5. Algorithm Design | 算法设计
An algorithm is a step‑by‑step plan to solve the problem. We design it in plain English before converting it to code:
算法是解决问题的一步步计划。我们在转换为代码之前,先用简单的英语设计它:
-
Step 1: Ask for the student’s name and store it in a variable.
第1步:询问学生姓名并存储在变量中。
-
Step 2: Ask how many books the student already has and store it as a number.
第2步:询问学生已有多少本书,并以数字存储。
-
Step 3: If the number is less than 2, display a message saying borrowing is allowed.
第3步:如果该数字小于 2,则显示一条消息表示允许借阅。
-
Step 4: Otherwise, display a message saying the maximum has been reached.
第4步:否则,显示一条消息表示已达到上限。
This clear sequence ensures we don’t miss any logic.
这个清晰的顺序确保我们不会遗漏任何逻辑。
6. Flowchart | 流程图
A flowchart uses symbols to represent the algorithm visually. The main symbols we need are: an oval for Start/End, a parallelogram for Input/Output, a rectangle for Process, and a diamond for Decision.
流程图使用符号来直观地表示算法。我们需要的符号主要有:椭圆形表示开始/结束,平行四边形表示输入/输出,矩形表示处理,菱形表示决策。
The flow for our borrowing system begins at Start. It then reads the student’s name and current books. A decision checks: “Is current_books < 2?”. If yes, the flow goes to output “Borrowing allowed”. If no, it outputs “Maximum books reached”. Both paths then lead to End.
我们借阅系统的流程从“开始”开始。然后读取学生姓名和当前借书数量。一个决策判断:“当前借书数量 < 2 吗?”。如果是,流程走向输出“允许借阅”。如果否,则输出“已达到最大借书数量”。两条路径最终都汇合到“结束”。
When drawing by hand, remember to label each arrow clearly and keep the layout neat. The decision diamond must have exactly two exit arrows (Yes / No).
手绘时,记住要给每个箭头清晰地标注,并保持布局整洁。决策菱形必须有且仅有两个出口箭头(是 / 否)。
7. Pseudocode | 伪代码
Pseudocode is a half‑code, half‑English description of the algorithm. It uses indentation to show the structure. Here is the pseudocode for our case:
伪代码是算法的一种半代码、半英文的描述。它使用缩进来展示结构。以下是本例的伪代码:
BEGIN
INPUT student_name
INPUT current_books
IF current_books < 2 THEN
OUTPUT "Borrowing allowed"
ELSE
OUTPUT "Maximum books reached"
ENDIF
END
Notice the KEYWORDS in UPPERCASE (BEGIN, INPUT, IF, THEN, ELSE, OUTPUT, ENDIF, END). This style is common in CIE assessments and helps your logic stand out clearly.
注意大写关键字(BEGIN, INPUT, IF, THEN, ELSE, OUTPUT, ENDIF, END)。这种风格在 CIE 评估中很常见,能让你的逻辑清晰地凸显出来。
Pseudocode allows you to test your logic before dealing with exact programming language syntax. It is a universal tool for planning.
伪代码使你在处理具体编程语言语法之前就能测试逻辑。它是一种通用的规划工具。
8. Implementation in Python | Python 实现
Now we translate the pseudocode into a real programming language. Below is the Python code. Variable names must be meaningful.
现在我们将伪代码翻译成真正的编程语言。下面是 Python 代码。变量名必须具有意义。
# Library borrowing system
student_name = input("Enter the student's name: ")
current_books = int(input("How many books does " + student_name + " have? "))
if current_books < 2:
print("Borrowing allowed. You may borrow another book.")
else:
print("Maximum books reached. You cannot borrow more books.")
The program uses input() to get data and int() to convert the books count to a number. The if statement compares current_books with the limit 2. The print() function shows the result.
该程序使用 input() 获取数据,并用 int() 将借书数量转换为数字。if 语句将 current_books 与限制值 2 进行比较。print() 函数显示结果。
Important: The indentation of the print lines must be consistent. In Python, indentation defines the block of code belonging to the if and else.
重要提示:print 语句的缩进必须一致。在 Python 中,缩进定义了属于 if 和 else 的代码块。
9. Testing and Debugging | 测试与调试
Testing proves that the program works correctly for all possible situations. We should create a test plan with different input values.
测试能证明程序在所有可能的情况下都能正确运行。我们应该创建一个包含不同输入值的测试计划。
| Test Case (测试用例) | Current Books (当前借书数) | Expected Output (预期输出) | Actual Result (实际结果) |
|---|---|---|---|
| 1 | 0 | Borrowing allowed | Borrowing allowed |
| 2 | 1 | Borrowing allowed | Borrowing allowed |
| 3 | 2 | Maximum books reached | Maximum books reached |
| 4 | 3 | Maximum books reached | Maximum books reached |
Boundary testing is crucial: values 1 and 2 sit exactly at the edge of the condition. If the program accidentally used <= 2 instead of < 2, test case 3 would fail. Always check the boundaries.
边界测试至关重要:数值 1 和 2 正好位于条件的边缘。如果程序误用了 <= 2 而不是 < 2,测试用例 3 就会失败。始终要检查边界。
If a test fails, we debug by tracing through the code line by line, checking variable values and logic. Fixing the condition or data type solves most errors.
如果测试失败,我们通过逐行跟踪代码来调试,检查变量值和逻辑。修正条件或数据类型能解决大多数错误。
10. Evaluation | 评估
After successful testing, we reflect on the solution. Does it meet the original requirements? Yes, it correctly enforces the 2‑book limit for any student name and count. However, the program is very simple and could be improved.
测试成功后,我们要反思解决方案。它是否满足原始需求?是的,它正确地对任何学生姓名和借书数量执行了 2 本书的限制。然而,这个程序非常简单,还有改进空间。
Limitations: It only checks one borrowing at a time and forgets the data after running. In a real library, we would need to store records permanently and manage multiple students. We could extend the system with a database and a user menu.
局限性:它每次只检查一次借阅,运行结束后就丢失数据。在真正的图书馆中,我们需要永久存储记录并管理多名学生。我们可以用数据库和用户菜单来扩展系统。
Nevertheless, this case study demonstrates the full development cycle: understand, decompose, recognise patterns, abstract, design the algorithm, draw a flowchart, write pseudocode, implement, test, and evaluate. Mastering these steps prepares you for any programming challenge in CIE Computer Science.
尽管如此,这个案例分析展示了完整的开发周期:理解、分解、识别模式、抽象、设计算法、绘制流程图、编写伪代码、实现、测试和评估。掌握这些步骤能让你应对 CIE 计算机科学中的任何编程挑战。
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课程辅导,国外大学本科硕士研究生博士课程论文辅导