AS Level · Topic 12.2
A-Level Computer Science 9618 / Topic 12 / AS

Draw the modules.

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.

The key idea

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.

ProcessMarks GetMarkUpdateTotalOutputAverage ValidateMark MarkMark, TotalTotal TotalMarkIsValid data parameter (data couple) flag (a Boolean value) iteration: called repeatedly
Fig. 1: a structure chart for a program that reads and validates 30 marks, totals them and outputs the average
Section 01

Reading a structure chart.

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.

CalculateFee MemberFeeVisitorFee diamond: selection IsMember = TRUEIsMember = FALSE
Fig. 2: CalculateFee calls MemberFee or VisitorFee, never both
Examiner trap

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.

Section 02

Building a chart.

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).

Worked example Decompose a problem
A program reads a customer's meter readings, calculates the bill and prints it. CalculateBill needs the Previous and Current readings and produces the Cost. Describe the structure chart.
  1. Top box: ProduceBill (the whole problem).
  2. Three boxes below, in the order they run, left to right: GetReadings, CalculateBill, PrintBill.
  3. GetReadings passes Previous and Current up to ProduceBill (data couples).
  4. Previous and Current pass down to CalculateBill; Cost passes up.
  5. Cost passes down to PrintBill. No iteration or selection is needed.
Answer: ProduceBill above GetReadings, CalculateBill and PrintBill, with data couples Previous, Current (up from GetReadings, down to CalculateBill) and Cost (up from CalculateBill, down to PrintBill)
Your turn
In Fig. 1, why does the arrow labelled Total pass both down to and up from UpdateTotal?
Examiner trap

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.

Stage 1 · Learn

Check what the sim just showed you

Four quick checks. Each correct answer earns XP and records this skill on your profile.

Quick check+10 XP

On a structure chart, what does an arrow with a filled (solid) circle show?

Quick check+10 XP

On a structure chart, what does a curved arrow drawn across the lines below a module show?

Quick check+10 XP

In Fig. 1, which module calls ValidateMark?

Quick check+10 XP

A module receives a value, changes it and passes it back up. How should the parameter be passed in pseudocode?

Section 03

Into 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 chartPseudocode
Only data going downPROCEDURE with BYVAL parameters
Exactly one value coming upFUNCTION ... RETURNS that value's type
A value going down and coming back up, or several values coming upPROCEDURE with BYREF parameters
Curved arrow across callsa loop (FOR, WHILE or REPEAT) around the calls
DiamondIF 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
Your turn
On a chart, Length and Width pass down to a module CalcArea and Area passes up. Write the module header.
Examiner trap

A function is called inside an expression, never with CALL: write Mark ← GetMark(), not CALL GetMark(). Procedures are called with CALL.

Stage 2 · Exam

Exam-style questions

Unlocks once the four checks above are done. Worth more XP, written to AS Paper 1 and Paper 2 standard.

Finish the four checks above to unlock the exam questions
Exam style+20 XP

What is the purpose of a structure chart?

Exam style+20 XP

On a structure chart, CheckPIN receives EnteredPIN and passes back PINCorrect with a filled circle. Which header matches?

Exam style+20 XP

Which symbol on a structure chart shows that only one of several modules is called?

Exam style+20 XP

Values A and B pass down to module Swap and both pass back up, exchanged. Which pseudocode header is correct?

Skill unlocked

Structure charts, mastered.

This skill is now recorded on your profile. Keep the chain going.

-Rank -Level -Score -Topics
Go deeper · practice
Six original Cambridge-style questions
Reading and drawing structure charts, data couples, flags, selection and iteration, and deriving pseudocode from a chart.