← Course Hub← 课程主页 ← All Units← 返回单元列表
H I G H  S C H O O L  C O M P U T E R  S C I E N C E
Solutions答案解析

Software Development Process软件开发流程

Worked Solutions · AP CSP-Feeder · US / ON / BC / AB Styles完整答案解析 · AP CSP 衔接 · 美 / 安 / 卑 / 阿省风格



PART I  ·  SHORT RESPONSE第一部分  ·  短答题AP CSP-style MCQ + ON/BC short answer · 25 marksAP CSP 风格选择题 + 安/卑省考短答 · 共 25 分

Section A · Short ResponseA 部分 · 短答题

Q1 EASY 🇺🇸 US AP CSP-style MCQAP CSP 风格选择题 §1 SDLC PhasesSDLC 阶段 · CSTA 3B-AP-17 [3 marks][3 分]

A software team is creating flowcharts, pseudocode, and UML diagrams to plan their program structure before writing any code. Which SDLC phase are they in?一个软件团队在编写任何代码之前,正在创建流程图、伪代码和 UML 图来规划程序结构。他们处于 SDLC 的哪个阶段?

Answer: (B) Design答案:(B)设计 A1

The Design phase is where the team converts requirements into concrete blueprints using tools such as flowcharts, pseudocode, UML class diagrams, and wireframes. No code is written yet. CSTA 3B-AP-17 states "processes could include agile, spiral, or waterfall" and names design as a distinct phase preceding implementation.设计阶段是团队将需求转化为具体蓝图的阶段,使用流程图、伪代码、UML 类图和线框图等工具。此时还未编写任何代码。CSTA 3B-AP-17 指出"过程可包括敏捷、螺旋或瀑布",并将设计列为实现前的独立阶段。

(A) Requirements gathers user needs in plain language, not design artifacts.需求阶段用通俗语言收集用户需求,而非设计制品。
(C) Testing verifies working code against a test plan; it comes after implementation.测试阶段根据测试计划验证可运行的代码;它在实现之后。
(D) Maintenance fixes bugs or adds features to software already deployed to users.维护阶段修复错误或为已部署给用户的软件添加功能。
Insight:关键洞察: The question specifies "before writing any code" -- that phrase locks the answer to Design (or Requirements/Analysis). Since the activities named (flowcharts, pseudocode, UML) are all design artifacts listed in ICS3U B2.4 and AP CSP CRD-2.B, Design is the only correct answer. On the exam, the phrase "before coding" combined with "design artifact" always maps to the Design phase.题目指明"在编写任何代码之前"--这句话锁定了答案为设计(或需求/分析)。由于提到的活动(流程图、伪代码、UML)都是 ICS3U B2.4 和 AP CSP CRD-2.B 中列出的设计制品,设计是唯一正确答案。在考试中,"编码前"加上"设计制品"的短语总是对应设计阶段。
Q2 EASY 🇨🇦 ON ON Provincial-style安大略省考风格 §2 Functional vs Non-functional Requirements功能性与非功能性需求 · ICS3U B4.1 [4 marks][4 分]

Classify each requirement for a school portal app as Functional (F) or Non-functional (NF).将学校门户应用的每个需求分类为功能性(F)或非功能性(NF)。

Answer (a): 1=F, 2=NF, 3=F, 4=NF答案(a):1=F,2=NF,3=F,4=NF M1 A1

1. F -- "allow students to view grades" describes what the system must do (a user action).1. F -- "允许学生查看成绩"描述系统必须做什么(用户操作)。

2. NF -- "load in under 3 seconds" describes how the system must perform (a performance constraint).2. NF -- "3 秒内加载"描述系统如何执行(性能约束)。

3. F -- "allow teachers to post due dates" describes what the system must do.3. F -- "允许教师发布截止日期"描述系统必须做什么。

4. NF -- "store passwords in encrypted form" describes a security quality constraint, not a user-visible action.4. NF -- "以加密形式存储密码"描述安全质量约束,而非用户可见的操作。

Answer (b):答案(b): M1 A1

A functional requirement describes what the system must do (a specific user-visible action or output); a non-functional requirement describes how the system must perform (a quality constraint such as speed, security, or accessibility). AP CSP CRD-2.A and Ontario ICS3U B4.1 both require capturing both types before design begins.功能性需求描述系统必须做什么(特定的用户可见操作或输出);非功能性需求描述系统如何执行(速度、安全性或无障碍性等质量约束)。AP CSP CRD-2.A 和安大略 ICS3U B4.1 都要求在设计开始前捕获两种类型。

Insight:关键洞察: The quick classification test: if you can describe the requirement as a user story ("As a user, I can..."), it is functional. If the requirement states a constraint on speed, security, reliability, or maintainability, it is non-functional. Encryption (req 4) is non-functional because it is a security quality that applies to how the system stores data, not what it lets users do.快速分类测试:如果你能将需求描述为用户故事("作为用户,我可以……"),它就是功能性的。如果需求规定速度、安全性、可靠性或可维护性的约束,它就是非功能性的。加密(需求 4)是非功能性的,因为它是一个安全质量,适用于系统如何存储数据,而非允许用户做什么。
Q3 MEDIUM 🇨🇦 BC BC Provincial-style卑诗省考风格 §3 Design Artifacts设计制品 · ICS3U B2.4 [5 marks][5 分]

Questions about the validate_login pseudocode and UML class diagrams.关于 validate_login 伪代码和 UML 类图的问题。

Answer (a):答案(a): A1 A1

Input: username and password (two string parameters passed to the function). Output: the strings "Access granted" or "Access denied" (printed to the user) and a Boolean return value (True or False).输入:usernamepassword(传递给函数的两个字符串参数)。输出:字符串 "Access granted""Access denied"(打印给用户)以及布尔返回值(TrueFalse)。

Answer (b) -- three UML sections:答案(b)-- UML 三节: A1 A1

Top section: class name (e.g., LoginSystem). Middle section: attributes -- the data the object stores (e.g., - username: str, - password: str). Bottom section: methods -- the operations the object can perform (e.g., + login(): bool, + logout(): void).顶部:类名(例如 LoginSystem)。中部:属性--对象存储的数据(例如 - username: str- password: str)。底部:方法--对象可执行的操作(例如 + login(): bool+ logout(): void)。

Answer (c):答案(c): A1

The UML class diagram is best suited for showing attributes and methods, because its three-section box format is specifically designed to organize class name, data fields (attributes), and operations (methods) in one visual structure.UML 类图最适合显示属性和方法,因为其三节盒子格式专门设计用于在一个视觉结构中组织类名、数据字段(属性)和操作(方法)。

Insight:关键洞察: Know when to use each design tool: pseudocode and flowcharts for algorithm logic (sequences, decisions, loops); UML class diagrams for object structure (what data a class holds and what it can do). Exam questions will describe a scenario and ask you to choose the tool -- the key discriminator is algorithm logic vs object structure.了解何时使用每种设计工具:伪代码和流程图用于算法逻辑(顺序、判断、循环);UML 类图用于对象结构(类保存什么数据以及可以做什么)。考题会描述场景并要求你选择工具--关键区分因素是算法逻辑与对象结构。
Q4 MEDIUM 🇨🇦 AB AB/Universal Applied阿省/通用应用题 §4 Coding Standards编码规范 · CSE1120 · BC CP11 [6 marks][6 分]

Identify three coding standard violations in the temperature code and rewrite it.识别温度代码中的三个编码规范违规并重写。

Answer (a) -- Three violations:答案(a)-- 三个违规: M1 M1 M1
  1. Poor naming: variable x does not describe what it stores. Standard: meaningful names (BC CP11; CSE1120). Should be something like temperature_celsius.命名不佳:变量 x 没有描述其存储的内容。规范:有意义的命名(BC CP11;CSE1120)。应命名为 temperature_celsius 之类。
  2. Magic number: 37 is hard-coded with no explanation. Standard: no magic numbers -- replace with a named constant. Should be FEVER_THRESHOLD = 37 defined at the top.魔法数字:37 被硬编码且没有说明。规范:无魔法数字--用命名常量替换。应在顶部定义 FEVER_THRESHOLD = 37
  3. Useless comment: # high just repeats the word "fever" printed below -- it says what the code does, not why. Standard: comments should explain the why. A better comment: # 37C is the clinical normal upper limit.无用注释:# high 只是重复了下面打印的"fever"--它说明代码做什么,而非为什么。规范:注释应解释原因。更好的注释:# 37C 是临床正常体温上限

(Also acceptable: inconsistent indentation -- 2 spaces instead of 4.)(也可接受:缩进不一致--2 个空格而非 4 个。)

Answer (b) -- Refactored code:答案(b)-- 重构后的代码: A1 A1 A1
FEVER_THRESHOLD = 37  # 37 degrees C is the clinical normal upper limit
                       # 37 摄氏度是临床正常体温上限

temperature_celsius = float(input("Enter temperature in Celsius: "))

if temperature_celsius > FEVER_THRESHOLD:
    print("fever")
else:
    print("normal")
Insight:关键洞察: When a code review question asks for "violations", map each one to a named standard: meaningful names, no magic numbers, useful comments (explain why not what), consistent 4-space indentation. The refactored version logic is identical -- only the readability changed. This is the definition of refactoring: restructuring code without changing behavior.当代码审查题要求找"违规"时,将每个违规映射到命名规范:有意义的命名、无魔法数字、有用的注释(解释为什么而非是什么)、一致的 4 个空格缩进。重构后的代码逻辑相同--只有可读性改变了。这就是重构的定义:在不改变行为的情况下重构代码。
Q5 MEDIUM 🇺🇸 US 🇨🇦 ON AP CSP-style MCQAP CSP 风格选择题 §5 Error Types错误类型 · BC CP11 · ICS3U B4.4 [7 marks][7 分]

Classify three error scenarios as Syntax, Logic, or Runtime.将三种错误场景分类为语法、逻辑或运行时错误。

Answer (a): Runtime error (IndexError)答案(a):运行时错误(IndexError) A1 A1

The code is syntactically valid Python -- the interpreter can parse it with no errors. The problem only manifests when the program executes the line print(scores[5]) at runtime: the list scores has indices 0, 1, 2 (three elements), so index 5 does not exist. Python raises an IndexError at that exact moment of execution, not during parsing. This is why runtime errors cannot be caught by a parser or compiler -- the index is only known at runtime.该代码是语法上有效的 Python--解释器可以无错误地解析它。问题只在程序运行时执行 print(scores[5]) 行时才显现:列表 scores 的索引为 0、1、2(三个元素),所以索引 5 不存在。Python 在执行的那一刻引发 IndexError,而非解析时。这就是为什么运行时错误无法被解析器或编译器捕获--索引只有在运行时才可知。

Answer (b): Syntax error答案(b):语法错误 A1 A1

The function definition def add(a, b) is missing the required colon (:) at the end. Python's parser will immediately raise a SyntaxError when it reads this line, before any code runs. The fix: def add(a, b):.函数定义 def add(a, b) 末尾缺少必需的冒号(:)。Python 的解析器在读取这一行时会立即引发 SyntaxError,在任何代码运行之前。修复:def add(a, b):

Answer (c): Logic error答案(c):逻辑错误 A1 A1 A1

The program runs without crashing (no syntax error, no exception) but produces the wrong answer -- that is the definition of a logic error. The condition if score > 90 uses a strict greater-than, so a score of exactly 90 falls through to the next branch and outputs "B" instead of "A". The algorithm is flawed, not the syntax or execution environment. The fix is to use if score >= 90 (greater-than-or-equal). This is a classic off-by-one boundary condition error, which BC CP11 and ICS3U B4.4 specifically name as a logic error.程序运行不崩溃(无语法错误,无异常),但产生错误答案--这就是逻辑错误的定义。条件 if score > 90 使用严格大于,所以恰好 90 分落入下一个分支并输出"B"而非"A"。算法有缺陷,而非语法或执行环境。修复是使用 if score >= 90(大于或等于)。这是一个经典的差一边界条件错误,BC CP11 和 ICS3U B4.4 将其明确命名为逻辑错误。

Insight:关键洞察: The three error types have a clean decision rule. Syntax: parser fails, nothing runs. Runtime: parser succeeds, but execution crashes on a specific line. Logic: program runs to completion, but the output is wrong. For boundary conditions specifically, always test the exact threshold value -- that is how you catch off-by-one logic errors that would otherwise pass all "typical" test cases.三种错误类型有清晰的判断规则。语法:解析器失败,没有任何东西运行。运行时:解析器成功,但执行在特定行崩溃。逻辑:程序运行完成,但输出错误。对于边界条件,始终测试确切的阈值--这是捕获差一逻辑错误的方法,否则这些错误会通过所有"典型"测试用例。
PART II  ·  EXTENDED RESPONSE第二部分  ·  简答题AP CSP-feeder FRQ + Honors · 30 marksAP CSP 衔接简答题 + 荣誉级 · 共 30 分

Section B · Extended ResponseB 部分 · 简答题

Q6 EASY 🇺🇸 US AP CSP-feeder FRQAP CSP 衔接简答题 §1 Waterfall vs Agile瀑布模型与敏捷 · CSTA 3B-AP-17 [5 marks][5 分]

Team Alpha: library management system, fixed requirements. Team Beta: social study-group app, new features every two weeks.阿尔法团队:图书馆管理系统,需求固定。贝塔团队:社交学习小组应用,每两周有新功能需求。

Answer (a):答案(a): A1 A1

Waterfall is more appropriate for Team Alpha. The requirements are fixed and well-understood, so the team can plan all seven SDLC phases in advance without expecting changes. Waterfall's sequential phase structure produces a predictable schedule and budget, which is ideal when requirements are stable.瀑布模型更适合阿尔法团队。需求固定且已明确,所以团队可以提前规划所有七个 SDLC 阶段而不预期变化。瀑布的顺序阶段结构产生可预测的进度和预算,这在需求稳定时是理想的。

Answer (b):答案(b): A1 A1

Agile is more appropriate for Team Beta. One specific advantage: agile uses short two-week sprints, so the team can incorporate new user feature requests between sprints without scrapping months of prior work. In Team Beta's case, the menu of features changes every two weeks -- agile is built for exactly this kind of iterative, user-driven development.敏捷更适合贝塔团队。一个具体优点:敏捷使用两周短冲刺,所以团队可以在冲刺之间整合新的用户功能请求,而不需要废弃数月的先前工作。在贝塔团队的情况下,功能菜单每两周变化--敏捷正是为这种迭代、用户驱动的开发而构建的。

Answer (c):答案(c): A1

A key disadvantage of waterfall compared to agile: changes to requirements are expensive and difficult after a phase is complete, because waterfall assumes each phase is finished before the next begins. In agile, requirements can evolve each sprint.与敏捷相比,瀑布的一个主要缺点:阶段完成后,需求变更代价高昂且困难,因为瀑布假设每个阶段在下一个阶段开始前完成。在敏捷中,需求可以每次冲刺都演进。

Insight:关键洞察: On any "waterfall vs agile" question, apply two filters: (1) are requirements stable or changing? Stable = waterfall; changing = agile. (2) Can the team deliver working software in short cycles? If yes and users want frequent updates, agile is the answer. CSTA 3B-AP-17 expects you to name both models and state a tradeoff -- memorize: waterfall is predictable but inflexible; agile is flexible but requires constant communication and re-planning.对于任何"瀑布与敏捷"题,应用两个过滤器:(1) 需求是稳定还是变化的?稳定 = 瀑布;变化 = 敏捷。(2) 团队能在短周期内交付可运行的软件吗?如果是,且用户想要频繁更新,敏捷是答案。CSTA 3B-AP-17 期望你命名两种模型并说明权衡--记住:瀑布可预测但不灵活;敏捷灵活但需要持续沟通和重新规划。
Q7 MEDIUM 🇨🇦 ON ON Provincial-style安大略省考风格 §5 Test Plan测试计划 · ICS3U B4.4 [8 marks][8 分]

Test plan for describe_temp(celsius): Freezing/Cold/Comfortable/Hot thresholds at 0, 15, 30.describe_temp(celsius) 的测试计划:阈值分别在 0、15、30 处产生 Freezing/Cold/Comfortable/Hot。

Answer (a) -- Completed test plan:答案(a)-- 已完成的测试计划: M1 A1 A1 A1
Scenario场景Input输入Expected output预期输出Type类型
Normal -- comfortable day正常 -- 舒适的一天22ComfortableComfortableNormal正常
Normal -- freezing day正常 -- 冰冻的一天-10FreezingFreezingNormal正常
Exact boundary -- Freezing/Cold threshold精确边界 -- Freezing/Cold 阈值0FreezingFreezingBoundary边界
Very large value (no upper limit)非常大的值(无上限)1000HotHotEdge边缘

(Accept any valid boundary case at a threshold: 0, 15, or 30. Accept any reasonable edge case: very large number, very negative number, non-integer float.)(接受任何在阈值处的有效边界情况:0、15 或 30。接受任何合理的边缘情况:非常大的数字、非常负的数字、非整数浮点数。)

Answer (b) -- Four required test plan elements (ICS3U B4.4):答案(b)-- 四个必要的测试计划要素(ICS3U B4.4): A1 A1
  1. Test scenario (a description of what is being tested)测试场景(被测内容的描述)
  2. Input data (the specific values used)输入数据(使用的具体值)
  3. Expected output (what the program should produce if correct)预期输出(正确时程序应产生的内容)
  4. Actual outcome + Pass/Fail (what the program actually produced, and whether it matches)实际结果 + 通过/失败(程序实际产生的内容,以及是否匹配)
Answer (c):答案(c): A1 A1

Error type: Logic error. The program runs without crashing but produces the wrong answer, so it is not a syntax or runtime error. The boundary condition the programmer got wrong is the condition for "Freezing": the code uses IF celsius < 0 (strict less-than), which means an input of exactly 0 falls into the "Cold" branch (0 < 15). The fix is to change the condition to IF celsius <= 0 or to restructure the thresholds so that 0 maps to "Freezing". This is a classic off-by-one boundary logic error.错误类型:逻辑错误。程序运行不崩溃但产生错误答案,所以不是语法或运行时错误。程序员出错的边界条件是"Freezing"的条件:代码使用 IF celsius < 0(严格小于),这意味着恰好 0 的输入落入"Cold"分支(0 < 15)。修复是将条件改为 IF celsius <= 0 或重构阈值使 0 映射到"Freezing"。这是一个经典的差一边界逻辑错误。

Insight:关键洞察: Always include boundary test cases at exact threshold values (here: 0, 15, 30). An off-by-one logic error will pass every "middle of range" normal test case but fail exactly at the boundary -- which is precisely the case with input 0 here. ICS3U B4.4 explicitly requires boundary cases in the test plan for this reason.始终在精确阈值处包含边界测试用例(此处:0、15、30)。差一逻辑错误会通过所有"范围中间"的正常测试用例,但恰好在边界处失败--这正是输入 0 的情况。ICS3U B4.4 正是因此明确要求测试计划中包含边界情况。
Q8 HARD 🇨🇦 BC 🇺🇸 US AP CSP-feeder FRQAP CSP 衔接简答题 §6 Documentation and Maintenance文档与维护 · CSTA 3B-AP-22 · BC CP12 [8 marks][8 分]

Write a docstring for convert_grade, name three maintenance types with examples, and classify a docstring's documentation type.为 convert_grade 编写文档字符串,命名三种维护类型并举例,以及分类文档字符串的文档类型。

Answer (a) -- Docstring:答案(a)-- 文档字符串: M1 M1 A1 A1
def convert_grade(score):
    """
    Convert a numeric score (0-100) to a letter grade.
    将百分制分数(0-100)转换为字母等级。

    Parameters / 参数:
        score (float): numeric score, must be in [0, 100]

    Returns / 返回:
        str: letter grade "A", "B", "C", "D", or "F"

    Raises / 异常:
        ValueError: if score is outside [0, 100]
    """
Answer (b) -- Three maintenance types with examples:答案(b)-- 三种维护类型及例子: A1 A1 A1
  • Corrective maintenance -- fix a bug that users reported. Example: users report that a score of 70 returns "D" instead of "C"; the programmer discovers the threshold check uses > instead of >= for the C threshold and fixes it.纠正性维护 -- 修复用户报告的错误。例子:用户报告 70 分返回"D"而非"C";程序员发现 C 阈值检查使用 > 而非 >= 并修复。
  • Adaptive maintenance -- update the function to work in a new environment. Example: the school migrates from Python 3.8 to Python 3.12; the programmer confirms the function still works and updates the module header's version note.适应性维护 -- 更新函数以在新环境中工作。例子:学校从 Python 3.8 迁移到 Python 3.12;程序员确认函数仍然正常工作并更新模块头的版本说明。
  • Perfective maintenance -- add a new feature or improve performance. Example: the teacher requests support for a "+/-" modifier (A+/A/A-); the programmer adds this feature and updates the docstring.完善性维护 -- 添加新功能或提高性能。例子:教师要求支持"+/-"修饰符(A+/A/A-);程序员添加此功能并更新文档字符串。
Answer (c):答案(c): A1

A Python docstring is technical documentation. Its intended audience is developers who maintain or use the function in their own code -- they read the docstring to understand what the function does, what parameters it expects, and what exceptions it can raise, without needing to read the implementation. (It is not user documentation, which is for end users in plain language, nor inline comment, which appears inside the function body.)Python 文档字符串是技术文档。其目标受众是维护或在自己代码中使用该函数的开发人员--他们阅读文档字符串以了解函数的功能、期望的参数以及可能引发的异常,而无需阅读实现。(它不是面向最终用户的用户文档,也不是出现在函数体内的内联注释。)

Insight:关键洞察: The three maintenance types map to three questions: did something break? (corrective) Did the environment change? (adaptive) Does the user want something new/better? (perfective). In professional software, maintenance accounts for the majority of total software cost over the product's lifetime -- CSTA 3B-AP-22 requires you to "discuss intended and unintended implications" of modifications, which is exactly what a good docstring and a comprehensive test plan enable.三种维护类型对应三个问题:某些东西坏了吗?(纠正性)环境改变了吗?(适应性)用户想要新的/更好的东西吗?(完善性)在专业软件中,维护占产品整个生命周期总软件成本的大部分--CSTA 3B-AP-22 要求你"讨论修改的预期和非预期影响",这正是好的文档字符串和全面测试计划所能实现的。
Q9 HARD Honors荣誉级 🇺🇸 US AP CSP-feeder FRQAP CSP 衔接简答题 §4 + §6 Code Standards + Refactoring编码规范 + 重构 · CSTA 3B-AP-23 [9 marks][9 分]

Function f(l) sums positive numbers in a list. Identify four problems, rewrite it properly, and name two code review quality checks.函数 f(l) 对列表中的正数求和。识别四个问题,正确重写它,并命名两个代码审查质量检查。

Answer (a) -- Four problems:答案(a)-- 四个问题: M1 M1 M1 A1
  1. Poor function name: f says nothing about what the function does. Standard: meaningful names. Should be something like sum_positive.函数命名不佳:f 没有说明函数的功能。规范:有意义的命名。应命名为 sum_positive 之类。
  2. Poor parameter name: l is ambiguous (looks like the digit 1 in some fonts) and does not describe the data. Standard: meaningful names. Should be numbers or values.参数命名不佳:l 有歧义(在某些字体中看起来像数字 1)且不描述数据。规范:有意义的命名。应命名为 numbersvalues
  3. Poor variable names: t and i (where i is not an index counter but an element value) are unclear. Standard: meaningful names. t should be total; i should be num or value.变量命名不佳:ti(其中 i 不是索引计数器而是元素值)不清晰。规范:有意义的命名。t 应命名为 totali 应命名为 numvalue
  4. Useless comment and missing docstring: # add just describes what the return statement does (obvious from the code). Standard: comments explain the why, not the what. More importantly, no docstring is present -- for a function shared with others, a docstring is required to document the parameter type, return type, and purpose.无用注释和缺少文档字符串:# add 只是描述 return 语句做什么(从代码中已明显可见)。规范:注释解释为什么而非是什么。更重要的是,没有文档字符串--对于与他人共享的函数,需要文档字符串来记录参数类型、返回类型和目的。
Answer (b) -- Refactored function:答案(b)-- 重构后的函数: M1 M1 A1 A1
POSITIVE_THRESHOLD = 0  # values must be strictly above this to be included
                         # 值必须严格大于此阈值才能包含在内

def sum_positive(numbers):
    """
    Return the sum of all positive numbers in a list.
    返回列表中所有正数的总和。

    Parameters / 参数:
        numbers (list): a list of numeric values

    Returns / 返回:
        float or int: the sum of all values greater than zero
    """
    total = 0
    for num in numbers:
        if num > POSITIVE_THRESHOLD:
            total = total + num
    return total
Answer (c) -- Two qualities a code reviewer checks:答案(c)-- 代码审查员检查的两个质量: A1

Any two of: (1) variable/function naming clarity, (2) comment quality (explaining why, not what), (3) presence and accuracy of documentation (docstring), (4) edge case handling, (5) absence of dead code, (6) consistent indentation and style.以下任意两个:(1) 变量/函数命名清晰度,(2) 注释质量(解释为什么而非是什么),(3) 文档的存在和准确性(文档字符串),(4) 边缘情况处理,(5) 没有死代码,(6) 一致的缩进和风格。

Insight:关键洞察: Using a named constant (POSITIVE_THRESHOLD = 0) here might seem excessive for a value of 0, but it demonstrates the principle: if someone later wants to change the threshold (e.g., "count only values above 5"), they change one line at the top, not every if-statement inside the loop. This is the key benefit of named constants -- single point of change. CSTA 3B-AP-23 specifically says "evaluate key qualities through a code review" -- the reviewer is asking "would another developer understand this in six months?" That is the standard your refactoring should meet.在这里使用命名常量(POSITIVE_THRESHOLD = 0)对于值 0 可能看起来过于繁琐,但它展示了原则:如果以后有人想要更改阈值(例如,"只计算大于 5 的值"),他们只需更改顶部的一行,而不是循环内的每个 if 语句。这是命名常量的关键好处--单一更改点。CSTA 3B-AP-23 特别指出"通过代码审查评估关键质量"--审查员在问"六个月后另一个开发人员能理解这个吗?"这是你的重构应该满足的标准。
PART III  ·  MODELING / APPLIED第三部分  ·  建模与应用Universal / multi-region applied · 25 marks通用/多地区应用题 · 共 25 分

Section C · Modeling and ApplicationsC 部分 · 建模与应用

Q10 MEDIUM 🇺🇸 US 🇨🇦 ON AP CSP-feeder FRQAP CSP 衔接简答题 §2 + §3 Requirements + Design需求 + 设计 · CRD-2.A · ICS3U B2.4 [8 marks][8 分]

Locker assignment system: student inputs name, gets a locker number, locker marked taken. No lockers available = error message.储物柜分配系统:学生输入姓名,获得储物柜编号,储物柜标记为已占用。无可用储物柜 = 错误信息。

Answer (a) -- Requirements:答案(a)-- 需求: A1 A1 A1
FR-1: The system shall accept a student name as input and output an available
      locker number, then mark that locker as taken.
      -- 系统应接受学生姓名作为输入,输出一个可用储物柜编号,然后将该储物柜标记为已占用。

FR-2: If no lockers are available, the system shall output the message
      "No lockers available" instead of a locker number.
      -- 若无可用储物柜,系统应输出"无可用储物柜"而非储物柜编号。

NFR-1: The system shall assign a locker in under 1 second for any input.
       -- 系统应在 1 秒内为任意输入分配储物柜。
Answer (b) -- Pseudocode for assign_locker:答案(b)-- assign_locker 的伪代码: M1 A1 A1
FUNCTION assign_locker(name)
    IF LENGTH(lockers) == 0 THEN
        OUTPUT "No lockers available"
        RETURN -1
    END IF
    locker_num = lockers[0]
    REMOVE lockers[0] FROM lockers
    OUTPUT name + " assigned locker " + locker_num
    RETURN locker_num
END FUNCTION
Answer (c) -- UML class diagram:答案(c)-- UML 类图: A1 A1
+---------------------------+
|       LockerSystem        |   <-- class name
+---------------------------+
| - available_lockers: list |   <-- attributes
| - assignments: dict       |
+---------------------------+
| + assign_locker(name:str) |   <-- methods
| + release_locker(num:int) |
+---------------------------+
Insight:关键洞察: Good requirements are numbered and testable -- FR-1 above can be tested by checking that the output locker number decreases the available list by 1. FR-2 can be tested with an empty list. NFR-1 can be timed. The pseudocode handles the edge case (empty list) before the main logic -- this is called defensive programming, and it is explicitly rewarded in the design phase of the SDLC. The UML diagram is the bridge from requirements to implementation: it shows what the class needs to store (attributes) and what it needs to do (methods).好的需求有编号且可测试--上面的 FR-1 可以通过检查输出储物柜编号使可用列表减少 1 来测试。FR-2 可以用空列表测试。NFR-1 可以计时。伪代码在主逻辑之前处理边缘情况(空列表)--这被称为防御性编程,在 SDLC 的设计阶段明确受到奖励。UML 图是从需求到实现的桥梁:它显示类需要存储什么(属性)以及需要做什么(方法)。
Q11 MEDIUM 🇨🇦 ON 🇨🇦 BC ON Provincial-style安大略省考风格 §5 + §7 Testing + Version Control测试 + 版本控制 · ICS4U B1.7 · BC CP11 [8 marks][8 分]

Password strength checker: check_strength(pwd) returns "Strong" if len(pwd) >= 8 and pwd contains at least one digit, else "Weak".密码强度检查器:check_strength(pwd) 若 len(pwd) >= 8 且 pwd 包含至少一个数字则返回"Strong",否则返回"Weak"。

Answer (a) -- Test plan:答案(a)-- 测试计划: M1 A1 A1 A1
Scenario场景Input (pwd)输入Expected output预期输出Type类型
10 chars, has digit10 个字符,含数字abcdefgh12StrongStrongNormal (strong)正常(强)
5 chars, no digit5 个字符,无数字helloWeakWeakNormal (weak)正常(弱)
Exactly 8 chars, 1 digit恰好 8 个字符,1 个数字abcdefg1StrongStrongBoundary边界
Empty string空字符串""WeakWeakEdge边缘
Answer (b) -- Three Git commands:答案(b)-- 三个 Git 命令: A1 A1 A1
git add password_checker.py
git commit -m "Fix off-by-one: change > 8 to >= 8 for length check (fixes Strong boundary)"
git push origin main
Answer (c):答案(c): A1

Branches allow Anika and Ben to work on separate copies of the codebase simultaneously. Without branches, if both push to the same file at the same time, one person's changes will overwrite the other's. Branches isolate each developer's work until it is reviewed and ready to merge.分支允许阿妮卡和本同时在代码库的独立副本上工作。没有分支,如果两人同时推送到同一文件,一个人的更改会覆盖另一个人的。分支隔离每个开发人员的工作,直到它被审查并准备好合并。

Insight:关键洞察: The boundary test case (exactly 8 chars, 1 digit) is the most important test here -- it is exactly the test that would have caught the bug Anika found. A password of "abcdefg1" (8 characters, 1 digit) should be "Strong" but the buggy implementation likely used len(pwd) > 8 (strict greater-than) instead of len(pwd) >= 8. This is why the commit message says "Fix off-by-one" -- an off-by-one in the boundary condition is a logic error, and the boundary test case is what reveals it. ICS4U B1.7 and BC CP11 both require version control -- Git's commit history provides an audit trail of who fixed what and why.边界测试用例(恰好 8 个字符,1 个数字)是这里最重要的测试--它正是能够捕获阿妮卡发现的错误的测试。密码"abcdefg1"(8 个字符,1 个数字)应该是"Strong",但有问题的实现可能使用 len(pwd) > 8(严格大于)而非 len(pwd) >= 8。这就是为什么提交消息说"Fix off-by-one"--边界条件中的差一是逻辑错误,边界测试用例揭示了它。ICS4U B1.7 和 BC CP11 都要求版本控制--Git 的提交历史提供了谁修复了什么以及为什么的审计跟踪。
Q12 HARD 🇺🇸 US 🇨🇦 ON 🇨🇦 BC AP CSP-feeder FRQAP CSP 衔接简答题 §1 + §3 + §5 + §7 Full SDLC Scenario完整 SDLC 场景 · CSTA 3B-AP-17 · ICS3U B4.1 [9 marks][9 分]

Cafeteria menu voting app: students vote from 5 options; app announces winner at end of day. Agile, two-week sprints, Git collaboration.食堂菜单投票应用:学生从 5 个选项中投票;应用在一天结束时宣布获胜者。敏捷,两周冲刺,Git 协作。

Answer (a) -- SDLC phase mapping (5 phases, 1 activity each):答案(a)-- SDLC 阶段映射(5 个阶段,每个 1 个活动): M1 A1 A1 A1 A1
  1. Requirements: Interview cafeteria staff and students to determine what the app must do -- e.g., "FR-1: Students must be able to vote for exactly one lunch option per school day."需求:采访食堂工作人员和学生,确定应用必须做什么--例如,"FR-1:学生每个学校日只能为一个午餐选项投票一次。"
  2. Analysis: Identify inputs (student ID, selected option), outputs (vote confirmation, winner announcement), data (vote counts per option, max one vote per student), and edge cases (tie between two options, student voting twice).分析:识别输入(学生 ID、选择的选项)、输出(投票确认、获胜者公告)、数据(每个选项的投票计数,每个学生最多一票)和边缘情况(两个选项并列、学生投票两次)。
  3. Design: Write pseudocode for the vote() and announce_winner() functions; draw a flowchart showing the voting decision flow (valid student, not already voted, update count); sketch a UML class diagram for a VotingSystem class with attributes vote_counts and voted_students.设计:为 vote() 和 announce_winner() 函数编写伪代码;绘制显示投票决策流程的流程图(有效学生、尚未投票、更新计数);为 VotingSystem 类草绘 UML 类图,含属性 vote_counts 和 voted_students。
  4. Implementation: Write Python code for vote() and announce_winner() following coding standards (meaningful names, no magic numbers, inline comments explaining the tie-breaking logic).实现:遵循编码规范(有意义的命名、无魔法数字、解释平局逻辑的内联注释)编写 vote() 和 announce_winner() 的 Python 代码。
  5. Testing: Execute a test plan with normal cases (one clear winner), boundary cases (exactly tied vote counts), and error cases (student tries to vote twice). Record actual vs expected output and mark pass/fail.测试:执行包含正常情况(一个明显获胜者)、边界情况(投票数完全相同)和错误情况(学生尝试投票两次)的测试计划。记录实际与预期输出并标记通过/失败。
Answer (b):答案(b): A1 A1 A1

Error type: Runtime error (specifically an IndexError). The program crashes when it tries to access a specific index to determine the winner, but that index does not exist or is ambiguous in a tie situation -- this only happens at execution time, not at parse time, making it a runtime error.错误类型:运行时错误(具体是 IndexError)。程序尝试访问特定索引来确定获胜者时崩溃,但在平局情况下该索引不存在或有歧义--这只在执行时发生,而非解析时,使其成为运行时错误。

SDLC phase where it should have been caught: Testing. A test case where two food items receive identical votes (e.g., Pizza = 5, Salad = 5) would have triggered the crash and revealed the missing tie-handling logic before deployment.本应捕获该故障的 SDLC 阶段:测试。一个两个食品获得相同票数(例如,披萨 = 5,沙拉 = 5)的测试用例会触发崩溃,并在部署前揭示缺失的平局处理逻辑。

Specific test case: Scenario = "Tie between two options"; Input = Pizza votes: 5, Salad votes: 5, all others: 0; Expected output = either the app announces both as co-winners or prompts for a runoff; Actual output (buggy) = IndexError crash. Type = Boundary / Error.具体测试用例:场景 = "两个选项平局";输入 = 披萨投票:5,沙拉投票:5,其他:0;预期输出 = 应用宣布两者并列或提示决胜;实际输出(有缺陷)= IndexError 崩溃。类型 = 边界/错误。

Answer (c):答案(c): A1

Agile is a better fit because the cafeteria menu changes each term, meaning the list of vote options will change frequently; agile's two-week sprint cycle allows the team to update the option list at the start of each term without redesigning the entire system from scratch the way waterfall would require.敏捷更适合,因为食堂菜单每学期变化,这意味着投票选项列表会频繁更改;敏捷的两周冲刺周期允许团队在每学期开始时更新选项列表,而不需要像瀑布那样从头重新设计整个系统。

Insight:关键洞察: Q12 integrates all seven sections of the study guide into one scenario. When you see a full-SDLC question on an exam, a reliable strategy is: (1) name the activity for each phase using the scenario's domain words (here: "cafeteria", "vote", "options"), (2) identify the error type by ruling out syntax (parser error) and logic (wrong answer without crash), then confirming runtime (crash during execution), (3) always state the SDLC phase as Testing for bugs that should have been caught before deployment, (4) connect agile's advantage directly to the change trigger mentioned in the question (here: "menu changes each term" = requirement changes = agile advantage).Q12 将学习指南的所有七个部分整合到一个场景中。当你在考试中看到完整 SDLC 题时,一个可靠的策略是:(1) 使用场景的领域词(这里:"食堂"、"投票"、"选项")命名每个阶段的活动,(2) 通过排除语法(解析器错误)和逻辑(无崩溃的错误答案),然后确认运行时(执行期间崩溃)来识别错误类型,(3) 对于本应在部署前捕获的错误,始终将 SDLC 阶段说明为测试,(4) 将敏捷的优势直接与题目中提到的变化触发器联系起来(这里:"菜单每学期变化" = 需求变化 = 敏捷优势)。