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 are square boxes. Yet a repetition sign and selection sign can be added to show its characteristics.
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.
// In pseudocode: PROCEDURE AskPassword(): <...code...> IF User_entry = correct_password THEN CALL spit_out_cash() ELSE CALL call_the_police() ENDIF ENDPROCEDURE
Parameters pass values between components.
|a) Normal parameter||Pass normal parameters (e.g. A number)|
|b) Flag Parameter||Usually a Boolean value. Sends as a signal.|
|c) Pass-by-reference Parameter||Variable is updated inside the module. Usually a global variable.|
Parameters are passed side of the connection line, like this:
You will also be tested on converting between structure charts and code. It’s not hard.