📚 AS AQA Computer Science: Case Study Practical Walkthrough | 案例分析实战演练
In AQA AS Computer Science, case study questions test your ability to analyse a given scenario, design a solution, write pseudocode, and evaluate your approach. This walkthrough uses a realistic ‘Student Grade Analyser’ scenario to demonstrate each stage of a methodical problem-solving process. You will learn how to break down a problem, choose appropriate data structures, create algorithms, trace logic, and plan tests – all essential skills for the AS exam and the non‑exam assessment.
在AQA AS计算机科学中,案例分析题考察你分析给定场景、设计解决方案、编写伪代码以及评估方案的能力。本演练将利用一个真实的“学生成绩分析器”场景,逐步展示系统化问题求解过程的每个阶段。你将学会如何分解问题、选择合适的数据结构、编写算法、跟踪逻辑以及规划测试——这些全都是AS考试与非考试评估中至关重要的技能。
1. Understanding the Scenario | 理解应用场景
Our scenario: a school teacher needs a program that allows them to enter a student’s name and three test scores (each out of 100). The program must calculate the average score, assign a grade, and keep track of the highest and lowest scores across all students. Entry continues until the teacher types ‘STOP’ as the name, at which point a summary report is displayed. There is no graphical interface – the program runs in a console.
我们的场景是:一位学校教师需要一个程序,用来输入学生姓名及三个测试成绩(每个满分100)。程序必须计算平均分、评定等级,并跟踪所有学生中的最高分与最低分。输入过程持续进行,直到教师输入“STOP”作为姓名,此时将显示汇总报告。该程序没有图形界面,在控制台中运行。
2. Requirements Analysis | 需求分析
Functional requirements define what the system should do. For this scenario they include: repeatedly reading a student name and three integer scores; calculating an average as a real number; determining a grade based on boundaries; storing the best and worst scores seen so far; and producing a final summary with counts and grade distributions. Non‑functional requirements are less critical here but might mention that the program should handle invalid inputs gracefully.
功能性需求定义了系统应该做什么。针对本场景,这些需求包括:循环读取学生姓名和三个整数成绩;计算平均值(实数);根据分数线确定等级;存储当前看到的最高分与最低分;生成最终汇总,包括人数和等级分布。非功能性需求在此不太关键,但可以提到程序应优雅地处理无效输入。
- Functional: input names/scores, compute averages, assign grades, track extremes, output summary.
- 功能:输入姓名/成绩,计算平均值,分配等级,跟踪极值,输出汇总。
It is useful to clarify the grading boundaries: A if average ≥ 80; B if ≥ 70; C if ≥ 60; D if ≥ 50; F otherwise. These will be used in selection logic.
澄清等级界限很有用:平均分 ≥ 80 为 A;≥ 70 为 B;≥ 60 为 C;≥ 50 为 D;否则为 F。这些将用于选择逻辑。
3. Identifying Inputs, Processes, and Outputs | 确定输入、处理和输出
An IPO chart helps to visualise the data flow. The table below pairs each element with its English description (left) and Chinese equivalent (right).
IPO(输入-处理-输出)图表有助于可视化数据流。下表将每个要素的英文描述(左)与中文对应(右)配对列出。
| IPO Element (English) | 中文要素 |
|---|---|
| Input: Student name (string), three test scores (integers, 0–100) | 输入:学生姓名(字符串),三个测试成绩(整数,0–100) |
| Process: Calculate average, determine grade, update highest/lowest, count students | 处理:计算平均值,确定等级,更新最高/最低分,统计学生人数 |
| Output: Summary report (number of students, highest score, lowest score, grade counts) | 输出:汇总报告(学生总数,最高分,最低分,各等级人数) |
The teacher also interacts via keyboard entry, and the loop terminates when the sentinel value ‘STOP’ is entered for the name. This control mechanism must appear in the algorithm.
教师通过键盘输入进行交互,当输入姓名处的哨兵值“STOP”时循环终止。这一控制机制必须出现在算法中。
4. Choosing Data Structures and Variables | 选择数据结构与变量
We need to store the highest and lowest overall scores, a running total of students, and counters for each grade category. Because we do not need to keep all individual student data for later reports, arrays are unnecessary. Simple scalar variables and a few accumulators suffice. The table below lists the key identifiers.
我们需要存储全局最高分和最低分、学生累计总数以及每个等级类别的计数器。由于不需要保留所有个别学生数据以供后续报告,因此不需要使用数组。简单的标量变量以及几个累加器就够了。下表列出了关键标识符。
| Variable (English) | 变量(中文) |
|---|---|
| studentName : String | 学生姓名 :字符串 |
| score1, score2, score3 : Integer | 成绩1、成绩2、成绩3 :整数 |
| average : Real | 平均分 :实数 |
| highest, lowest : Integer | 最高分、最低分 :整数 |
| countA, countB, countC, countD, countF : Integer (all initialised to 0) | countA、countB、countC、countD、countF :整数(均初始化为0) |
| totalStudents : Integer | 学生总数 :整数 |
Using meaningful identifiers and initialising accumulators correctly is emphasised in the AQA mark scheme. Constants are not strictly needed, but grade boundaries could be defined as constants for readability.
使用有意义的标识符并正确初始化累加器,在AQA评分标准中受到强调。严格来说不一定需要常量,但为增强可读性,可以将等级分数线定义为常量。
5. Designing the Solution with Pseudocode | 使用伪代码设计方案
The solution logic can be expressed using AQA-style pseudocode. The structure is a pre-condition loop that reads the name, checks for the sentinel, and then processes the three scores. The grade is determined through nested IF statements, and the summary is shown after the loop exits.
解决方案逻辑可以用AQA风格的伪代码表示。其结构是一个前置条件循环,读取姓名,检查哨兵值,然后处理三个成绩。等级通过嵌套的IF语句确定,循环结束后显示汇总信息。
highest ← 0
lowest ← 100
totalStudents ← 0
countA ← 0; countB ← 0; countC ← 0; countD ← 0; countF ← 0
OUTPUT "Enter student name (STOP to finish): "
INPUT studentName
WHILE studentName ≠ "STOP"
OUTPUT "Enter three test scores: "
INPUT score1, score2, score3
average ← (score1 + score2 + score3) / 3.0
totalStudents ← totalStudents + 1
IF average > highest THEN
highest ← average
ENDIF
IF average < lowest THEN
lowest ← average
ENDIF
IF average ≥ 80 THEN
countA ← countA + 1
ELSE IF average ≥ 70 THEN
countB ← countB + 1
ELSE IF average ≥ 60 THEN
countC ← countC + 1
ELSE IF average ≥ 50 THEN
countD ← countD + 1
ELSE
countF ← countF + 1
ENDIF
OUTPUT "Enter student name (STOP to finish): "
INPUT studentName
ENDWHILE
OUTPUT "Total students: ", totalStudents
OUTPUT "Highest average: ", highest
OUTPUT "Lowest average: ", lowest
OUTPUT "Grade A: ", countA
OUTPUT "Grade B: ", countB
OUTPUT "Grade C: ", countC
OUTPUT "Grade D: ", countD
OUTPUT "Grade F: ", countF
This pseudocode follows the AQA conventions: ← for assignment, = for comparison, and clear indentation. The highest and lowest are initialised to sensible boundary values. Note that average is calculated using floating-point division.
这段伪代码遵循了AQA惯例:用 ← 表示赋值,用 = 表示比较,并采用了清晰的缩进。最高分和最低分被初始化为合理的边界值。注意平均分是用浮点除法计算的。
6. Visualising Logic with Flowcharts | 用流程图可视化逻辑
Flowcharts can help visualise selection and iteration. The main loop is a decision diamond checking whether studentName equals "STOP". Inside, the process box for calculating average is followed by decision diamonds for grade boundaries. Although we cannot draw actual graphics here, you should be able to sketch a flowchart where the main flow returns to the input prompt after updating counters and extremes.
流程图有助于可视化选择与迭代结构。主循环是一个判断菱形,检查 studentName 是否等于“STOP”。循环内部,计算平均分的处理框之后是用于等级界限的判断菱形。虽然此处无法绘制实际图形,但你应该能够画出这样一张流程图:主流程在更新计数器和极值后返回输入提示。
Key symbols to use: rounded rectangles for start/end, parallelograms for INPUT/OUTPUT, rectangles for processing, and diamonds for decisions. The terminating condition is placed at the beginning of the loop, making it a WHILE loop.
需要使用的关键符号:圆角矩形表示开始/结束,平行四边形表示输入/输出,矩形表示处理,菱形表示判断。终止条件置于循环开始处,因此这是一个 WHILE 循环。
7. Tracing the Algorithm | 算法跟踪
A trace table is an invaluable tool for verifying algorithm correctness. Let’s trace the first two iterations with sample data: Alice (scores 85, 90, 78), then Bob (65, 55, 70), finally STOP.
跟踪表是验证算法正确性的宝贵工具。我们用示例数据跟踪前两次迭代:Alice(成绩85、90、78),然后 Bob(65、55、70),最后 STOP。
| Iteration | studentName | score1,2,3 | average | highest | lowest | Grade | countA…countF |
|---|---|---|---|---|---|---|---|
| Start | - | - | - | 0 | 100 | - | all 0 |
| 1 | Alice | 85, 90, 78 | 84.33 | 84.33 | 84.33 | A | A=1, others 0 |
| 2 | Bob | 65, 55, 70 | 63.33 | 84.33 | 63.33 | C | A=1, C=1 |
After Bob’s entry, assume we input STOP next. The loop ends and the summary is displayed. The trace table confirms that highest remains 84.33, lowest becomes 63.33, and grade counters reflect the assigned grades. Always verify extreme updates when the first student enters data; we correctly set both highest and lowest to Alice’s average.
Bob的数据输入后,假设我们接着输入 STOP。循环结束并显示汇总。跟踪表证实最高分保持84.33,最低分变为63.33,等级计数器反映了分配的等级。务必验证当第一名学生输入数据时极值的更新情况;我们正确地将 highest 和 lowest 都设为 Alice 的平均分。
8. Developing a Test Plan | 制定测试计划
A structured test plan ensures the program behaves correctly across normal, boundary, and erroneous data. The table below presents a selection of tests, covering the main paths.
结构化的测试计划可确保程序在正常数据、边界数据和错误数据下均表现正确。下表展示了一组测试用例,覆盖了主要路径。
| Test ID | Description | Input Data | Expected Outcome |
|---|---|---|---|
| 1 | Normal single student | Name: Alice, scores 80,80,80 | Avg 80, grade A, highest=80, lowest=80, countA=1 |
| 2 | Multiple students, grade boundaries | Alice 79,80,81 (avg 80) ; Bob 69,70,71 (avg 70) ; STOP | Grades A and B, highest=80, lowest=70, countA=1, countB=1 |
| 3 | Boundary: exactly grade thresholds | Scores producing avg 50, 60, 70, 80 | Respective grades D, C, B, A assigned correctly |
| 4 | Invalid score (out of range) | Enter 105 for a score | Error message, re-prompt (if validation added) |
| 5 | Immediate STOP (zero students) | STOP as first name | Total students=0, highest still 0, lowest 100 – may need handling |
Notice that Test 5 reveals a flaw: if no students are entered, the summary would show misleading extremes. This kind of evaluation is exactly what examiners look for. We should add a check to output a message like 'No data entered' instead.
请注意,测试5揭示了一个缺陷:如果没有输入任何学生,汇总将显示误导性的极值。这种评估正是考官所看重的。我们应该添加一个检查,输出诸如“尚未输入数据”的消息。
9. Handling Invalid Inputs and Errors | 处理无效输入和错误
Robust programs validate user input. For the scores, we should ensure each is between 0 and 100 inclusive. A simple input-sanitisation loop can be added. Additionally, after the main loop we can check whether totalStudents = 0 to avoid displaying meaningless statistics.
健壮的程序会验证用户输入。对于成绩,我们应确保每个值在0到100之间(含)。可以增加一个简单的输入清理循环。此外,在主循环之后,我们可以检查 totalStudents 是否等于0,从而避免显示无意义的统计数据。
REPEAT
OUTPUT "Enter score (0-100): "
INPUT score
IF score < 0 OR score > 100 THEN
OUTPUT "Invalid score, please re-enter."
ENDIF
UNTIL score ≥ 0 AND score ≤ 100
This fragment demonstrates defensive programming. A similar check could be applied to each of the three scores. We also need to handle non-numeric input, but at AS level that is typically beyond the pseudocode scope. Using the sentinel-controlled outer loop already prevents most structural errors.
这段代码片段展示了防御性编程。可以对三个成绩分别应用类似的检查。我们还需要处理非数字输入,但在AS阶段通常超出伪代码范围。使用哨兵控制的外循环已经防止了大多数结构性错误。
10. Evaluation and Improvements | 评估与改进
After constructing a solution, you should critically evaluate its strengths and weaknesses. The current design is simple, modular, and meets all stated requirements. However, it does not store individual student records for later queries, and it cannot handle ties in the highest/lowest sensibly if we want to display which student achieved them. The use of a pre‑condition loop also means the summary might not execute if the user inputs STOP immediately; adding a post‑condition loop could be considered, but the sentinel pattern is widely accepted.
在构建解决方案之后,你应该批判性地评估其优缺点。当前设计简单、模块化,并满足了所有既定需求。然而,它没有存储个别学生记录以供后续查询;如果我们想显示谁获得了最高/最低分,它也无法合理处理并列情况。使用前置条件循环还意味着,如果用户立即输入 STOP,汇总可能不会执行;可以考虑增加后置条件循环,但哨兵模式已被广泛接受。
Possible enhancements include: storing scores in an array for a re‑calculation feature; adding a menu system; writing the summary to a file; or calculating the median. For the AS exam, you should be able to discuss the impact of these changes on time and space complexity.
可能的改进包括:将成绩存储到数组中以便重新计算;增加菜单系统;将汇总写入文件;或者计算中位数。对于AS考试,你应该能够讨论这些更改对时间和空间复杂度的影响。
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课程辅导,国外大学本科硕士研究生博士课程论文辅导Cancel reply