Skip to content

3.13 Developing Procedures 开发过程

Programmers break down problems into smaller and more manageable pieces. By creating procedures and leveraging parameters, programmers generalize processes that can be reused. Procedures allow programmers to draw upon existing code that has already been tested, allowing them to write programs more quickly and with more confidence.

  • 程序员将问题分解为更小和更易管理的部分。通过创建过程和利用参数,程序员泛化可以重用的过程。过程允许程序员利用已经测试过的现有代码,使他们能够更快、更有信心地编写程序。

核心要点 Core Points

  1. One common type of abstraction is procedural abstraction, which provides a name for a process and allows a procedure to be used only knowing what it does, not how it does it.

    • 一种常见的抽象类型是过程抽象,它为过程提供名称,并允许仅知道过程做什么而不必知道如何做来使用过程。
  2. Procedural abstraction allows a solution to a large problem to be based on the solutions of smaller subproblems. This is accomplished by creating procedures to solve each of the subproblems.

    • 过程抽象允许大问题的解决方案基于较小子问题的解决方案。这是通过创建过程来解决每个子问题来实现的。
  3. The subdivision of a computer program into separate subprograms is called modularity.

    • 将计算机程序细分为独立子程序称为模块化。
  4. A procedural abstraction may extract shared features to generalize functionality instead of duplicating code. This allows for program code reuse, which helps manage complexity.

    • 过程抽象可以提取共享特征来泛化功能,而不是复制代码。这允许程序代码重用,有助于管理复杂性。
  5. Using parameters allows procedures to be generalized, enabling the procedures to be reused with a range of input values or arguments.

    • 使用参数允许过程泛化,使过程能够与一系列输入值或参数一起重用。
  6. Using procedural abstraction helps improve code readability.

    • 使用过程抽象有助于提高代码可读性。
  7. Using procedural abstraction in a program allows programmers to change the internals of the procedure (to make it faster, more efficient, use less storage, etc.) without needing to notify users of the change as long as what the procedure does is preserved.

    • 在程序中使用过程抽象允许程序员更改过程的内部(使其更快、更高效、使用更少存储等),只要保留过程的功能,就不需要通知用户更改。
  8. The exam reference sheet provides the following syntax for defining procedures:

    • 考试参考表提供以下定义过程的语法:
    • Text:
      • 文本:
      PROCEDURE procName (parameter1, parameter2, ...)
      {
        <block of statements>
      }
    • Block: A visual representation of the procedure structure
      • 块: 过程结构的视觉表示
    • Which is used to define a procedure that takes zero or more arguments. The procedure contains block of statements.
      • 用于定义接受零个或多个参数的过程。过程包含语句块。
  9. The exam reference sheet provides the following syntax for defining procedures with return values:

    • 考试参考表提供以下定义带返回值过程的语法:
    • Text:
      • 文本:
      PROCEDURE procName (parameter1, parameter2, ...)
      {
        <block of statements>
        RETURN (expression)
      }
    • Block: A visual representation of the procedure structure including a return
      • 块: 包括返回的过程结构的视觉表示

学生活动 Student Activities

  1. Explain how the use of procedural abstraction manages complexity in a program.

    • 解释过程抽象的使用如何管理程序中的复杂性。
  2. Develop procedural abstractions to manage complexity in a program by writing procedures.

    • 通过编写过程开发过程抽象来管理程序中的复杂性。

基于 VitePress 构建的 AP CSP 学习平台