A Adam Learning
Back to notes
9618-AS-11-03Chapter 11Section 11.3short-answer

11.3 Structured Programming 结构化编程简答

Review the exact wording students need for this knowledge point, then open a filtered question list when ready to practise.

Find questions for 9618-AS-11-03

Procedure and function

  • Procedure:named module that performs a task;called as a statement and does not return a value in the same way as a function。
  • Function:named module that returns one value;its return value can be used in an expression or assignment。

Use a module when a task is repeated/reused, has a clear specific purpose, or makes a complex algorithm manageable。

Benefits of subroutines

  • Reduce complexity and simplify the main algorithm。
  • Can be called repeatedly from several places。
  • Designed and tested once, then reused。
  • Tested/debugged independently。
  • Changes are made once in the module, improving maintenance。

Parameters and arguments

  • Parameter:identifier declared in the module header to receive data。
  • Argument:actual value/expression supplied when the module is called。
  • BYVAL:a copy is passed;changing the parameter does not change the caller's variable。
  • BYREF:the original variable is referenced;changes can affect the caller's variable。

Interface terminology

Module interface specifies:

  • Module name and whether procedure/function。
  • Number, order, names and data types of parameters。
  • Passing method, such as BYVAL/BYREF。
  • Function return data type/value。

Example short answer:

CheckNum takes two INTEGER parameters and returns a BOOLEAN value.

When to use a function

Use a function when a module calculates/looks up/tests something and the result is required in an expression。A procedure is suitable for a sequence of actions such as displaying a report or updating several items where no single expression result is required。

Efficient modular code

If a function is called repeatedly inside a loop with unchanged arguments, it returns the same value each time。Call it once before the loop, store the result in a local variable, then reuse that variable。

Other good practice:meaningful identifiers、indentation/white space、comments、local variables and clear parameters。

Exam checklist

  • Procedure/function 是否按 return value 区分?
  • Parameter 与 argument 是否混淆?
  • BYVAL/BYREF 的 effect 是否准确?
  • Interface 是否包含 parameter types 和 return type?
  • Modular benefits 是否写到 reuse、testing、maintenance?
  • Efficiency 是否说明 repeated call 为什么多余及如何缓存 result?

Procedure/function headers、calls、returns 和 parameter pseudocode 留到代码专项。

Practice This Knowledge Point

Open the question bank with this knowledge code already filled in. The filtered list will show matching questions for this note.

Open filtered practice
Source questions used