← 返回资讯屏轩教育 · 行业资讯

Case Study Practical Drill | 案例分析实战演练

2026-07-18 07:13 · 本文部分内容由AI辅助创作

📚 Case Study Practical Drill | 案例分析实战演练

Welcome to this Year 8 Cambridge Computer Science case study practical drill. In this session, we will apply computational thinking and programming basics to a realistic problem: designing a simple snack vending machine. You will learn how to break down a problem, create algorithms, use flowcharts and pseudocode, handle data, and evaluate a solution. Each section builds your skills in analysis, design, and testing, just like a real computer scientist.

欢迎参加本次 Year 8 剑桥计算机科学案例分析实战演练。我们将把计算思维和编程基础运用到一个真实场景中:设计一台简单的零食自动贩卖机。你将学会如何分解问题、创建算法、使用流程图和伪代码、处理数据以及评估解决方案。每个环节都在增强你的分析、设计和测试能力,就像真正的计算机科学家一样。

1. Understanding the Problem | 理解问题

Before coding, we must clearly define the problem. Our vending machine sells three items: a pack of crisps (50p), a bottle of juice (80p), and a chocolate bar (65p). A customer selects one item, inserts coins, and expects to receive the correct item and change if they overpay.

在编写代码之前,我们必须清晰地定义问题。我们的自动贩卖机出售三种商品:一包薯片(50便士)、一瓶果汁(80便士)和一块巧克力(65便士)。顾客选择一种商品,投入硬币,如果多付了钱就期待收到正确的商品和找零。

We ask questions: Which coins can the machine accept? What happens if the customer does not insert enough money? What output messages should the machine display? Clarifying these points prevents confusion later.

我们会提出问题:机器能接受哪些硬币?如果顾客投入的金额不够会怎样?机器应该显示什么输出信息?理清这些要点可以避免后续出现混乱。


2. Defining Requirements | 明确需求

Based on the problem, we list the functional requirements. The machine must: let the user press a button for item 1, 2, or 3; accept 10p, 20p, and 50p coins; calculate the total inserted; compare it to the item price; deliver the item and return change if the total is sufficient; and display 'Insufficient funds' if not enough money is inserted.

根据问题,我们列出功能性需求。机器必须:让用户按下商品1、2或3的按钮;接受10p、20p和50p硬币;计算投入的总金额;将其与商品价格比较;如果总金额足够,交付商品并退还找零;如果金额不足,显示“余额不足”。

We also note the non-functional requirements: the system should be easy to use, display clear messages, and handle coin inputs correctly without crashing.

我们还会注意到非功能性需求:系统应易于使用,显示清晰的信息,并能正确处理硬币输入而不崩溃。


3. Decomposing the Task | 任务分解

Computational thinking starts with decomposition. We break the vending machine system into smaller, manageable parts: input (user selection and coin insertion), processing (price lookup, total calculation, comparison), output (dispense item, return change, display messages), and storage (item prices and inventory counts).

计算思维从分解开始。我们将自动贩卖机系统拆分成更小、更易处理的部分:输入(用户选择和硬币投入)、处理(价格查找、总额计算、比较)、输出(交付商品、退还找零、显示信息)和存储(商品价格和库存数量)。

This modular view helps us focus on one piece at a time. For instance, we can design the coin counting logic separately from the change calculation algorithm.

这种模块化的视角帮我们一次专注于一个部分。例如,我们可以把硬币计数逻辑与找零计算算法分开设计。


4. Designing the Algorithm | 算法设计

on (1, 2, or 3). 3. Prompt user to insert coins. 4. Keep accepting valid coins until user presses 'done' n item. 7. If total >= price, dispense item and give change (total - price). Else, display 'Insufficient funds' and return coins.

算法是分步的解决方案。我们为机器设计一个高层算法:1. 显示商品菜单和价格。2. 等待商品选择(1、2或3)。3. 提示用户投入硬币。4. 持续接受有效硬币直到用户按“完成”。5. 累加投入的硬币。6. 获取所选商品的价格。7. 如果总额≥价格,交付商品并找零(总额-价格);否则显示“余额不足”并退还硬币。

Notice how the algorithm uses sequence, selection (if condition) and iteration (repeat coin input). These are the three building blocks of programming.

注意算法如何使用顺序、选择(if条件)和迭代(重复硬币输入)。这是编程的三大基本结构。


5. Flowchart Representation | 流程图表示

es, diamonds for decisions, and parallelograms for input/output. The flowchart starts with 'Start', then 'Display menu', 'Input item choice', 'Input coin' in a loop, 'Sum total', 'Is total >= price?', and paths for Yes (give item and change) and No (error message, return coins).

流程图提供了算法的可视化地图。我们使用标准符号:椭圆形表示开始/结束,矩形表示处理,菱形表示决策,平行四边形表示输入/输出。流程图从“开始”开始,然后“显示菜单”,“输入商品选择”,在一个循环中“输入硬币”,“累加总额”,“总额≥价格?”,并为是(交付商品和找零)和否(错误信息,退还硬币)设计路径。

Imagine the decision diamond: if the condition is true, follow the left branch; if false, follow the right. Drawing a clear flowchart makes it easier to spot logical errors before writing code.

想象决策菱形:如果条件为真,沿着左分支;如果为假,沿着右分支。绘制清晰的流程图有助于在编写代码之前发现逻辑错误。

[Insert flowchart diagram in your notebook]


6. Pseudocode Writing | 伪代码编写

Pseudocode describes the algorithm in plain-language statements that resemble code. Here is the pseudocode for our vending machine:

伪代码用类似代码的简明语言描述算法。以下是自动贩卖机的伪代码:

ITEM1_PRICE = 50
ITEM2_PRICE = 80
ITEM3_PRICE = 65
OUTPUT "Select item (1,2,3)"
INPUT choice
total = 0
REPEAT
OUTPUT "Insert coin (10,20,50) or type 0 to finish"
INPUT coin
IF coin is valid THEN total = total + coin
UNTIL coin = 0
IF choice = 1 THEN price = ITEM1_PRICE
ELSE IF choice = 2 THEN price = ITEM2_PRICE
ELSE price = ITEM3_PRICE
IF total >= price THEN
change = total - price
OUTPUT "Dispensing item. Your change: ", change
ELSE
OUTPUT "Insufficient funds. Returning coins."

This pseudocode uses constants, variables, loops, and conditional statements, just like a real program.

这个伪代码使用了常量、变量、循环和条件语句,就像真正的程序一样。


广告 / Sponsored

7. Variable and Data Types | 变量与数据类型

When we implement the solution, we need variables to store data. We identify: 'choice' (integer), 'coin' (integer), 'total' (integer), 'price' (integer), 'change' (integer). All hold whole numbers, so we use the integer data type.

当实现解决方案时,我们需要变量来存储数据。我们确定:“choice”(整数)、“coin”(整数)、“total”(整数)、“price”(整数)、“change”(整数)。它们都保存整数,因此使用整数数据类型。

We also might use a string variable for output messages like "Insufficient funds". Choosing the right data type saves memory and prevents errors.

我们还可能使用字符串变量来存放诸如“余额不足”的输出信息。选择正确的数据类型可以节省内存并防止错误。

We can summarise the core variables in a table:

我们可以用一个表格总结核心变量:

VariableData TypePurpose
choiceIntegerSelected item number
coinIntegerValue of inserted coin
totalIntegerSum of coins inserted
priceIntegerPrice of chosen item
changeIntegerAmount to return

8. Testing with Sample Data | 示例数据测试

Before trusting the algorithm, we test it with sample data. We create a test table that lists inputs, expected outputs, and actual outputs. This is part of verification.

在信任算法之前,我们用示例数据来测试它。我们创建一个测试表格,列出输入、预期输出和实际输出。这是验证的一部分。

Example test cases:

示例测试用例:

TestChoiceCoins insertedTotalExpected output
11 (Crisps)20p, 20p, 10p50pItem dispensed, change 0p
22 (Juice)50p, 50p100pItem dispensed, change 20p
33 (Chocolate)20p, 20p40pInsufficient funds, coins returned

Running these tests mentally or in a simple Python simulation confirms that the logic works correctly.

在头脑中或用一个简单的Python模拟运行这些测试,可以确认逻辑工作正常。


9. Binary and Logic Connection | 二进制与逻辑连接

Year 8 Cambridge Computer Science often integrates binary numbers. Suppose we give each item a 4-bit binary code to represent its selection. This mimics how a real machine might use switches or a keypad encoder.

Year 8 剑桥计算机科学常常融入二进制数。假设我们给每种商品分配一个4位二进制代码来表示它的选择。这模拟了真实机器如何使用开关或键盘编码器。

ItemBinary CodeDecimal
Crisps00011
Juice00102
Chocolate00113

We also encounter logic when checking coin validity. A coin is accepted only if its value is 10 OR 20 OR 50. This uses a logical OR combination. If we had a sensor for coin diameter and weight, we could link binary patterns to physical signals, but our simplified model uses numeric values.

在检查硬币有效性时,我们也会遇到逻辑。只有当硬币是10或20或50时才会被接受。这使用了逻辑或的组合。如果我们有硬币直径和重量的传感器,就可以把二进制模式与物理信号联系起来,但我们的简化模型使用数值。

20p is 10100₂ because 16+4=20. This reinforces the connection between theory and hardware.

二进制数转换练习:如果机器用二进制寄存器存储找零,20便士的找零就是10100₂,因为16+4=20。这强化了理论与硬件之间的联系。


10. Evaluation and Improvements | 评估与改进

Every design can be improved. We evaluate the vending machine solution: it works for three items but adding new items requires editing the code. A better approach would use a data structure like a list or array to store item names and prices, making it scalable.

任何设计都可以改进。我们评估贩卖机解决方案:它对三种商品有效,但添加新商品需要修改代码。更好的方法是使用列表或数组等数据结构来存储商品名称和价格,使其具有可扩展性。

We also notice that the machine does not check stock levels. Adding a stock variable for each item would prevent selling out-of-stock products. Furthermore, the user interface could be improved with a display screen and a card payment option.

我们还注意到机器没有检查库存水平。为每种商品增加一个库存变量可以防止出售缺货产品。此外,用户界面可以通过显示屏和刷卡支付选项来改进。

This reflection cycle -- analyse, design, test, evaluate -- is the essence of computational thinking. Practising with case studies builds your confidence for exams and real-world problem solving.

这种“分析、设计、测试、评估”的反思循环是计算思维的精髓。通过案例学习进行练习,可以增强你面对考试和真实世界问题解决的信心。


Published by TutorHao | Cambridge Computer Science Revision Series | aleveler.com

广告 / Sponsored
现货 Cambridge International AS & ALevel IT Coursebook剑桥国际IGC…
计算机 备考教辅 · 正版现货 · 与本文内容相关
查看详情 / View on Taobao参考价 ¥467.0

更多咨询请联系16621398022(同微信)

备考资讯每日更新,关注不错过
考纲变化 · 科目分析 · 学习方法
扫码关注公众号 tutorhao
在微信里长按二维码识别关注
或截图后用「扫一扫 → 相册」选择本图
公众号:tutorhao