Chapter 12: Stepwise refinement and structure charts

Nov 18, 2019

Overview of the chapter:

Current A1 course only mentioned 12.3 section. Notes on section 12.1 and 12.2 will be added after the completion of coursework.

  • 12.1 Step-wise refinement
  • 12.2 Modules
  • 12.3 Structure charts

12.3 Structure charts

Structure charts are graphical representation of the modular structure of solutions.

A structure chart has the following functions:

  • Shows hierarchy of different modules
  • Shows interface (parameter passed) between modules
  • Shows selection
    • When a module is called only under certain conditions
  • Shows repetition
    • When a module is called more than once

Components of a structure chart

Modules

Usually subroutines.

Modules are square boxes. Yet a repetition sign and selection sign can be added to show its characteristics.

A standard modulus. This represents a function called AskPassword().

Repetition is an arrow pointing to itself. Repeating condition should be marked clearly beside.

.
//In Pseudocode:
PROCEDURE AskPassword ()
    WHILE user_entry <> correct_password DO
        <code...>
    ENDWHILE
ENDPROCEDURE

Selection is a diamond. Depending on conditions it calls different modules.

Not that modules are connected through lines, **not arrows**.
// In pseudocode:
PROCEDURE AskPassword():
    <...code...>

    IF User_entry = correct_password THEN
        CALL spit_out_cash()
    ELSE
        CALL call_the_police()
    ENDIF
ENDPROCEDURE

Parameters

Parameters pass values between components.

UseDescriptionShape
a) Normal parameterPass normal parameters (e.g. A number)
b) Flag ParameterUsually a Boolean value. Sends as a signal.
c) Pass-by-reference ParameterVariable is updated inside the module. Usually a global variable.

Parameters are passed side of the connection line, like this:

From computer science textbook

You will also be tested on converting between structure charts and code. It’s not hard.

Great! You've successfully subscribed.
Great! Next, complete checkout for full access.
Welcome back! You've successfully signed in.
Success! Your account is fully activated, you now have access to all content.