A structure chart is the map of a modular program. It shows how a problem is decomposed into modules, which module calls which, and exactly what data passes between them. Learn to read one, draw one and turn one straight into pseudocode.
A structure chart is a top-down design diagram. Each rectangle is a module (a procedure or function); a line from a module to one below it means the upper module calls the lower one. Short arrows beside the lines show the parameters passed: an arrow with a hollow circle is data; an arrow with a filled circle is a flag (a Boolean). A diamond shows selection (only one of the modules below is called) and a curved arrow shows iteration (the modules are called repeatedly). It shows what each module does and what it needs, not how it does it.
Read Fig. 1 from the top down and from left to right. ProcessMarks is the main module. It calls GetMark and UpdateTotal repeatedly (the red curved arrow), then calls OutputAverage once. GetMark calls ValidateMark repeatedly until the mark is valid.
Mark passes up from GetMark to ProcessMarks; Total passes down to OutputAverage.IsValid passes up from ValidateMark.A structure chart does not show the detailed steps inside a module, and it is not a flowchart. If a question asks for a structure chart, draw boxes, lines and parameter arrows, not decision boxes and loops of code.
Start with one box for the whole problem. Decompose it into the main sub-tasks, then decompose any sub-task that is still too complex. Finally, decide what data each module needs (passed down) and what it produces (passed up).
Every parameter arrow needs a label and a direction. An unlabelled arrow, or one with no circle to show data or flag, will not earn the mark.
Four quick checks. Each correct answer earns XP and records this skill on your profile.
On a structure chart, what does an arrow with a filled (solid) circle show?
On a structure chart, what does a curved arrow drawn across the lines below a module show?
In Fig. 1, which module calls ValidateMark?
A module receives a value, changes it and passes it back up. How should the parameter be passed in pseudocode?
Each box becomes a module header, and the arrows tell you its parameters. Try the procedures and functions in the lab, then compare with the pseudocode for Fig. 1 below.
| Arrows on the chart | Pseudocode |
|---|---|
| Only data going down | PROCEDURE with BYVAL parameters |
| Exactly one value coming up | FUNCTION ... RETURNS that value's type |
| A value going down and coming back up, or several values coming up | PROCEDURE with BYREF parameters |
| Curved arrow across calls | a loop (FOR, WHILE or REPEAT) around the calls |
| Diamond | IF or CASE choosing which module to call |
PROCEDURE ProcessMarks()
DECLARE Count, Mark, Total : INTEGER
Total ← 0
FOR Count ← 1 TO 30
Mark ← GetMark()
CALL UpdateTotal(Mark, Total)
NEXT Count
CALL OutputAverage(Total)
ENDPROCEDURE
FUNCTION GetMark() RETURNS INTEGER
DECLARE Mark : INTEGER
REPEAT
INPUT Mark
UNTIL ValidateMark(Mark) = TRUE
RETURN Mark
ENDFUNCTION
FUNCTION ValidateMark(Mark : INTEGER) RETURNS BOOLEAN
RETURN Mark >= 0 AND Mark <= 100
ENDFUNCTION
PROCEDURE UpdateTotal(BYVAL Mark : INTEGER, BYREF Total : INTEGER)
Total ← Total + Mark
ENDPROCEDURE
PROCEDURE OutputAverage(Total : INTEGER)
OUTPUT "Average mark: ", Total / 30
ENDPROCEDURE
FUNCTION CalcArea(Length : REAL, Width : REAL) RETURNS REAL: one value comes up, so it is a functionA function is called inside an expression, never with CALL: write Mark ← GetMark(), not CALL GetMark(). Procedures are called with CALL.
Unlocks once the four checks above are done. Worth more XP, written to AS Paper 1 and Paper 2 standard.
What is the purpose of a structure chart?
On a structure chart, CheckPIN receives EnteredPIN and passes back PINCorrect with a filled circle. Which header matches?
Which symbol on a structure chart shows that only one of several modules is called?
Values A and B pass down to module Swap and both pass back up, exchanged. Which pseudocode header is correct?
This skill is now recorded on your profile. Keep the chain going.