Structure charts and module headers
A map of the modules
- A big program is split into modules: procedures and functions that each do one job. This is called decomposition.
- A structure chart shows the modules as boxes, which module calls which, and the data passed between them.
- Paper 2 asks you to read a chart, complete one, or write the module headers a chart describes. This lesson shows how each symbol becomes part of a header.

From arrows to a header
- An arrow down into a module is a parameter: the value goes in.
- An arrow up out of a module is a value coming back. If the module sends back one value, it is a FUNCTION, and the value is its
RETURNStype. - An arrow pointing both ways is a value that goes in, is changed, and comes back: a BYREF parameter of a PROCEDURE.
- A module with no arrow up is a PROCEDURE.

The program behind the chart
DECLARE Scores : ARRAY[1:4] OF INTEGER
DECLARE Position : INTEGER
FUNCTION GetScore() RETURNS INTEGER
Position ← Position + 1
RETURN Scores[Position]
ENDFUNCTION
FUNCTION CheckScore(Score : INTEGER) RETURNS BOOLEAN
RETURN Score >= 0 AND Score <= 100
ENDFUNCTION
PROCEDURE UpdateTotal(Score : INTEGER, BYREF Total : INTEGER)
Total ← Total + Score
ENDPROCEDURE
PROCEDURE ProcessScores()
DECLARE Score, Total, Count : INTEGER
Total ← 0
FOR Count ← 1 TO 4
Score ← GetScore()
IF CheckScore(Score) THEN
CALL UpdateTotal(Score, Total)
ELSE
OUTPUT "Rejected ", Score
ENDIF
NEXT Count
OUTPUT "Total ", Total
ENDPROCEDURE
Scores[1] ← 70
Scores[2] ← 105
Scores[3] ← 55
Scores[4] ← -3
Position ← 0
CALL ProcessScores()
- The curved arrow on the chart is the
FORloop: the three modules are called once per score. - The diamond on the line to
UpdateTotalis theIF: it is called only for a valid score. - The output is
Rejected 105,Rejected -3,Total 125.
Watch the BYREF rule
- In 9618 pseudocode,
BYREFapplies to every parameter after it in the header, untilBYVALappears. - So
PROCEDURE AddBonus(BYREF Score : INTEGER, Bonus : INTEGER)makesBonusBYREF too, andCALL AddBonus(MyScore, 7)fails: 7 is not a variable. - Put the BYVAL parameters first:
PROCEDURE AddBonus(Bonus : INTEGER, BYREF Score : INTEGER). - When no
BYREForBYVALis written, parameters are passed by value.
Reading a chart in the exam
- Find the top module: it is the one that calls the others.
- For each lower module, look at its arrows: down for parameters, up for a returned value, both ways for BYREF.
- A filled circle is a BOOLEAN flag; an open circle is ordinary data. Give each parameter the type the question uses.
- Look for a diamond (only one module is called) and a curved arrow (the modules are called in a loop).
Common mistakes
| Wrong | Right | Why |
|---|---|---|
| a FUNCTION for a module with no arrow up | a PROCEDURE | nothing comes back, so there is nothing to return |
| a value going both ways passed by value | BYREF |
the module changes it and the caller must see the change |
BYREF Total : INTEGER, Score : INTEGER |
Score : INTEGER, BYREF Total : INTEGER |
BYREF also covers every later parameter |
| a flag drawn with an open circle | a filled circle | flags (BOOLEANs) have filled circles |
| drawing iteration as a diamond | a curved arrow | the diamond means selection |
Now you try
- Each task describes a chart in words. Write the header first, then the body.
Independent transfer
The final task gives a module with three values going down and one coming up. Write its header and body, then solve it before opening support.
Difficulty 2/5 · 140 coins + a small bonus on first completion today
A chart shows IsInRange with three data couples going down (Value, Low, High, all INTEGER) and a flag InRange coming up. Write the module so it returns TRUE when Value is from Low to High, both included.
Click Run to see the output here.
Difficulty 3/5 · 200 coins + a small bonus on first completion today
A chart shows AddBonus with Bonus going down and Score going both ways. Write the procedure so it adds Bonus to Score, then call it so the program outputs 57.
Click Run to see the output here.
Difficulty 1/5 · 100 coins + a small bonus on first completion today
On a structure chart, a value that goes into a module and comes back changed is passed in which way? Give the pseudocode keyword.
Difficulty 3/5 · 200 coins + a small bonus on first completion today
A chart shows Largest with A, B and C (INTEGER) going down and one INTEGER coming up. Write the module. The main program reads three integers and outputs Largest of them.
Click Run to see the output here.