Skip to content
Cambridge AS & A Level9618

Program Design

Computer Science 9618 Chapter Notes

Last updated November 2026

ShareWhatsAppPost

Program Design notes as a printable PDF.

Read online free. Download a watermarked copy with a free account.

Read the notes

The full Program Design notes as text: skim, search, and jump between subtopics.

~15 min read

1. Purpose of a structure chart

A structure chart decomposes a problem into sub-tasks. Each sub-task is a module: a procedure or a function.

The chart shows the module relationships: the hierarchy of which module calls which. It also shows the parameters that are passed between the modules, and whether each module is a function or a procedure.

A chart can be turned into pseudocode. Each box becomes a module header, and the labels on the arrows become its parameters.

Worked example 12 marks

A structure chart will be produced as part of the development process.

Describe the purpose of a structure chart.

  1. 1

    to show the module relationships / hierarchy / selection / repetition, that is, how a problem is broken down [1]

  2. 2

    to show the parameters that are passed between the sub-tasks / modules, or whether a module is a function or a procedure [1]

2. Selection: the diamond

A module sometimes calls one of several modules below it. Which one is called is decided when the program runs. A diamond on the lines to those modules shows this selection.

The word ‘either’ in a description is the clue. A module that calls either X or Y is drawn with a diamond. A module that calls both is not.

Examiner insight

“Common mistakes included the omission of the selection diamond (MP2) and occasional confusion over whether the circle on a parameter arrow should be shaded or unshaded.” “Most candidates correctly identified the use of selection so gained one mark for this question. A few candidates correctly named all four modules involved.”

Worked example 13 marks

Two new modules are added to a structure chart: Module-X() and Module-Y().

• Module-X() has no parameters.

• Module-Y() will take a string and a real number as parameters and return a Boolean value.

• Module-D() will call either Module-X() or Module-Y().

Draw only the part of the structure chart that represents the relationship between Module-X(), Module-Y() and Module-D().

  1. 1

    ``` Module-D() <> selection

    |-- Module-X() |-- Module-Y() in: STRING, REAL out: BOOLEAN (shaded) ```

  2. 2

    all rectangles correctly labelled and interconnected [1]

  3. 3

    all and only parameters: none for Module-X(); a string and a real into Module-Y() and a Boolean out [1]

  4. 4

    selection diamond on the lines from Module-D() [1]

3. Iteration: the curved arrow

A curved arrow that begins and ends at a module shows iteration. The module repeatedly calls the modules below it.

A full answer names the modules in the correct sequence in which they are called. ‘It is a loop’ is not enough.

Examiner insight

“Candidates answers often correctly stated that this symbol indicated iteration, but then failed to follow this with the detail of the sequence in which the three modules would be called.” “Many of the answers seen were too vague such as “A loop will have Module A call the other Modules”.”

Worked example 12 marks

In a structure chart, Module-A() has a curved arrow that begins and ends at Module-A(). Below it, from left to right, are Sub-Y1(), Sub-Y2() and Sub-9().

Explain the meaning of the curved arrow symbol which begins and ends at Module-A().

  1. 1

    iteration / looping: the calls are repeated [1]

  2. 2

    names all four modules in the correct sequence: Module-A() repeatedly calls Sub-Y1(), then Sub-Y2(), then Sub-9() [1]

4. Parameters, functions and procedures

Labelled arrows between boxes carry the parameters passed to a module and the values returned from it. A module that returns a value is a function. A module that returns nothing is a procedure.

The arrow notation has three forms: a clear circle, a shaded circle and a double arrow. A Boolean parameter is drawn with a shaded circle.

To derive pseudocode, write one header per box. A parameter that the module assigns a new value to, for the caller to use, is passed with `BYREF`.

``` FUNCTION Name(Param : TYPE) RETURNS TYPE PROCEDURE Name(BYREF Param : TYPE) ```

Examiner insight

“A common mistake was to present the subroutine as a function.” “The inclusion of BYREF to define the parameter was rarely seen.”

Worked example 12 marks

The definition for module LoanReturn() is amended. It is called with parameters LoanID, BookID and Fine. The module code checks whether the book has been returned on time and then assigns a new value to Fine.

LoanID and BookID are of type STRING. Fine is of type REAL.

Write the pseudocode header for the amended module LoanReturn().

  1. 1

    no value is returned, so it is a procedure: `PROCEDURE LoanReturn (LoanID, BookID : STRING,` [1]

  2. 2

    Fine is given a new value, so it is passed by reference: `BYREF Fine : REAL)` [1]

5. Constructing a chart from a description

Work through the description in passes. Draw a box for every module and join them in the correct hierarchy. Add a diamond only where the words give a choice (‘either’, ‘one of’), and an iteration arrow only where they say ‘repeatedly’. Put each on the module that makes the choice or repeats.

Then label every parameter and return value. A mark scheme gives marks for all and only the parameters: do not add any the description does not give.

Examiner insight

“Common mistakes were omitting parameter labels particularly on the lower level and not shading in the Boolean parameter arrow to Module-Y.”

Worked example 14 marks

A structure chart is used to document part of a program, made up of five modules. Program notes:

• module Setup calls either module Restart, or module Confirm

• module Confirm takes a string as a parameter and returns an integer

• module Modify has no parameters and returns a Boolean

• module Update takes a string as a parameter

• module Restart repeatedly calls module Update followed by module Modify

• module Restart takes a string as a parameter that is passed by reference.

Draw a structure chart to represent the relationship between the five modules, including all parameters and return values.

  1. 1

    ``` Setup <> either

    |-- Confirm in: STRING out: INTEGER |-- Restart BYREF STRING (iteration) |-- Update in: STRING |-- Modify out: BOOLEAN (shaded) ```

  2. 2

    all boxes correctly labelled and connected in the correct hierarchy [1]

  3. 3

    BYREF parameter to Restart; parameter to Confirm and its return value [1]

  4. 4

    selection diamond on Setup and the iteration arrow on Restart [1]

  5. 5

    parameter to Update and return value from Modify [1]

6. State-transition diagrams

A state-transition diagram is used to document an algorithm. It shows the states a system can be in and the events that move it from one state to another.

Each transition is a line with an arrow from the current state to the next state, labelled with the event. The arrow must have the correct line direction.

The arrow into the first state is labelled Start. A diagram can also have a final or halting state.

Examiner insight

“Common incorrect answers seen for row three were ‘Input’ or some scenario-specific expressions such as ‘Water level’.”

Worked example 14 marks

An automated digital camera system is used to take a sequence of pictures of animals in a garden. During the design of the system, a state-transition diagram is produced.

The table details the states in the automated digital camera system along with the events which cause the states to change. The system starts in standby mode. The sequence of pictures is taken when in active mode.

Complete the state-transition diagram for the automated digital camera system. The Start arrow into standby mode is already drawn.

Current stateEventNext state
standby modeturn ondetect mode
detect modeturn offstandby mode
detect modemovement detectedactive mode
active mode20 seconds elapsedsequence complete
active modeturn offstandby mode
sequence completetime saveddetect mode
  1. 1

    the three new states drawn and labelled: detect mode, active mode, sequence complete [1]

  2. 2

    any two events drawn with labels, joining the correct states with the correct line direction [1]

  3. 3

    any four events drawn in the same way [1]

  4. 4

    all and only six events: turn on, turn off (twice), movement detected, 20 seconds elapsed and time saved, each from its current state to its next state [1]

7. Inputs, outputs and loops

A transition can carry an input and an output. Both go in one label, input first: `A1 | X1`. A transition with no output has only the input.

A transition can return to the state it left. This is a loop, and it is labelled like any other transition.

To draw a diagram from a table, give each row one arrow. It runs from the current state to the next state and carries the correct event labels.

Examiner insight

“Where marks were lost this was usually due to: • failing to add the initial transition arrow • omitting either the input or the output from the transition label • placing the label far away from the transition arrow so that it was not clear what it referred to.”

Worked example 15 marks

One part of the program contains an algorithm which is represented by a state-transition diagram.

The table shows the inputs, outputs and states for the algorithm.

Complete the state-transition diagram to represent the information given in the table. The Start arrow into S1 and the arrow from S1 to S3 labelled A2 | X2 are already drawn.

Current stateInputOutputNext state
S1A2X2S3
S1A1X1S2
S2A4X4S5
S3A1S3
S3A3X3S2
S3A2X4S4
S4A1X1S4
S4A3S2
S4A4X4S5
  1. 1

    S1 to S2 labelled A1 | X1 [1]

  2. 2

    states S3, S4 and S5 drawn and labelled [1]

  3. 3

    S2 to S5 labelled A4 | X4 [1]

  4. 4

    from S3: a loop labelled A1, S3 to S2 labelled A3 | X3, S3 to S4 labelled A2 | X4 [1]

  5. 5

    from S4: a loop labelled A1 | X1, S4 to S2 labelled A3, S4 to S5 labelled A4 | X4 [1]

Recap

  • A structure chart shows module relationships, the parameters passed, and whether each module is a function or a procedure.
  • Diamond = selection: the module calls either one module or the other, decided at run time.
  • Curved arrow = iteration: name the modules it repeatedly calls, in sequence.
  • Function returns a value. Procedure does not. BYREF when the caller must see the change.
  • Draw all and only the parameters given. Shade the Boolean circle.
  • A state-transition diagram documents an algorithm: states, labelled arrows, a Start arrow.
  • Label a transition with its input and output, `A1 | X1`. Do not forget loops.

End-of-chapter exercise

Test yourself on the whole chapter. Work through these before moving on.

  1. A structure chart has a curved arrow that begins and ends at the module `Main()`. Below `Main()` are `Input()`, `Process()` and `Output()`, from left to right. Explain what the curved arrow means.2 marks
    Answer
    1. The curved arrow means iteration [1].
    2. `Main()` repeatedly calls `Input()`, then `Process()`, then `Output()` [1].

    Trap: ‘A loop’ on its own is too vague: name the modules and their sequence.

  2. In a structure chart, the module `Cashier()` is joined by a diamond to `Cash()` and `Card()`. Explain what the diamond means.2 marks
    Answer
    1. The diamond shows selection [1].
    2. `Cashier()` calls either `Cash()` or `Card()`, decided when the program runs [1].

    Trap: Reading the diamond as a repeat, or as a call to both modules.

  3. A module `Perimeter` is called with two REAL values, `Width` and `Height`. It returns their perimeter as a REAL. Write the pseudocode header for the module.3 marks
    Answer
    1. ``` FUNCTION Perimeter(Width : REAL, Height : REAL) RETURNS REAL ```
    2. It returns a value, so it is a function [1]. Both parameters have a name and a type [1]. The return type follows RETURNS [1].

    Trap: Writing PROCEDURE, or leaving out RETURNS, for a module that returns a value.

  4. A module `Swap` is called with two INTEGER parameters, `A` and `B`. It exchanges their values in the calling module and returns nothing. Write the pseudocode header for the module.3 marks
    Answer
    1. ``` PROCEDURE Swap(BYREF A : INTEGER, BYREF B : INTEGER) ```
    2. It returns nothing, so it is a procedure [1]. Both changes must reach the caller: `A` is `BYREF` [1] and `B` is `BYREF` [1].

    Trap: Leaving out BYREF: the changes stay inside the module and the caller sees no swap.

  5. A turnstile starts in the state Locked. A coin makes it Unlocked. A push makes it Locked again. A push when Locked, and a coin when Unlocked, change nothing. List every arrow of its state-transition diagram, with its label, including the arrow into the first state.4 marks
    Answer
    1. Locked to Unlocked, labelled coin [1]. Unlocked to Locked, labelled push [1].
    2. Two loops: Locked on push, and Unlocked on coin [1].
    3. The arrow into Locked is labelled Start [1].

    Trap: Leaving out the two loops because the state does not change.

  6. The table gives the transitions of an algorithm. It starts in S1. The inputs A, B, B, A, B are applied in that order. State the outputs, in order, and the final state. | Current state | Input | Output | Next state | | --- | --- | --- | --- | | S1 | A | X | S2 | | S2 | B | – | S2 | | S2 | A | Y | S3 | | S3 | B | Z | S1 |3 marks
    Answer
    1. A: X, to S2. B: no output, stay in S2. B: no output, stay in S2. A: Y, to S3. B: Z, to S1.
    2. Outputs in order: X, Y, Z [2]. Final state: S1 [1].

    Trap: Counting five outputs: the two loops on B in S2 have no output.

  7. The module `Report()` calls `Fetch()` and then `Show()`. `Fetch()` is called with a STRING, `Name`, and returns an INTEGER, `Total`. `Show()` is called with `Total`. Describe the structure chart, with all parameters and return values.4 marks
    Answer
    1. ``` Report() |-- Fetch() in: Name (STRING) out: Total (INTEGER) |-- Show() in: Total (INTEGER) ```
    2. `Report()` above `Fetch()` and `Show()` [1]. `Name` into `Fetch()` [1]. `Total` out of `Fetch()` [1]. `Total` into `Show()` [1].

    Trap: Adding a diamond or an iteration arrow: the description says neither ‘either’ nor ‘repeatedly’.

  8. The module `Till()` repeatedly calls `Scan()` and then `Total()`. `Scan()` returns a REAL value, `Price`. `Total()` is called with `Price` and calls either `Discount()` or `FullPrice()`, decided when the program runs. `Discount()` and `FullPrice()` are each called with `Price` and each returns a REAL. Describe the structure chart.6 marks
    Answer
    1. ``` Till() (iteration) |-- Scan() out: Price (REAL) |-- Total() in: Price (REAL) <> selection |-- Discount() in: Price out: REAL |-- FullPrice() in: Price out: REAL ```
    2. All five modules labelled, in the correct hierarchy [1]. `Price` returned by `Scan()` [1] and passed to `Total()` [1].
    3. `Price` into, and a REAL out of, `Discount()` and `FullPrice()` [1]. Iteration arrow on `Till()` only [1]. Selection diamond on `Total()` only [1].

    Trap: Putting the diamond or the iteration arrow on the wrong module.

  9. A door alarm starts Disarmed. A valid code makes it Armed and outputs beep. When Armed, opening the door makes it Alarming and outputs siren on, and a valid code makes it Disarmed with no output. When Alarming, a valid code makes it Disarmed and outputs siren off. When Disarmed, opening the door changes nothing. (a) List the labelled arrows of the state-transition diagram. (b) The alarm is Disarmed. The inputs door opened, valid code, door opened, valid code occur in that order. State the outputs, in order, and the final state.7 marks
    Answer
    1. (a) Start into Disarmed [1]. Disarmed to Armed: valid code | beep [1]. Armed to Alarming: door opened | siren on [1].
    2. Armed to Disarmed: valid code. Alarming to Disarmed: valid code | siren off [1]. A loop on Disarmed: door opened, no output [1].
    3. (b) Door opened: loop, no output. Valid code: beep, Armed. Door opened: siren on, Alarming. Valid code: siren off, Disarmed.
    4. Outputs in order: beep, siren on, siren off [1]. Final state: Disarmed [1].

    Trap: Leaving out the door-opened loop on Disarmed, or giving it an output: it changes nothing, so the trace has three outputs, not four.

  10. `Main()` repeatedly calls `GetNumber()` and then `Check()`. `GetNumber()` is called with an INTEGER, `Value`, assigns a new value to it and returns nothing. `Check()` is called with `Value` and returns a BOOLEAN. The repetition stops when `Check()` returns TRUE. Write the headers for `GetNumber()` and `Check()`, and the pseudocode for `Main()`.6 marks
    Answer
    1. ``` PROCEDURE GetNumber(BYREF Value : INTEGER) FUNCTION Check(Value : INTEGER) RETURNS BOOLEAN PROCEDURE Main() DECLARE Value : INTEGER REPEAT CALL GetNumber(Value) UNTIL Check(Value) = TRUE ENDPROCEDURE ```
    2. `GetNumber()` returns nothing, so it is a procedure [1]. `Main()` needs the new value, so it is `BYREF` [1]. `Check()` is a function `RETURNS BOOLEAN` [1].
    3. `CALL GetNumber(Value)` inside the loop [1]. `Check()` used in an expression after it, not with `CALL` [1]. The loop repeats until `Check()` returns TRUE [1].

    Trap: Writing `GetNumber()` as a function, or leaving out `BYREF`: examiners report both, and without `BYREF` the new value never reaches `Main()`.

Say this, not that

Wording that loses the mark, against the wording the mark scheme credits.

Loses the markGets the mark
“A loop will have Module A call the other Modules”Module-A repeatedly calls the three modules, in sequence
‘Input’ or ‘Water level’ on the first arrowthe arrow into the first state is labelled Start
FUNCTION LoanReturn(...) for a module that returns nothingPROCEDURE with BYREF Fine : REAL
Boolean parameter drawn with a clear circleBoolean parameter drawn with a shaded circle

Frequently asked questions

What is the purpose of a structure chart?
A structure chart decomposes a problem into sub-tasks, and each sub-task is a module. It shows the module relationships, the hierarchy of which module calls which, and the parameters passed between the modules. It also shows whether each module is a function or a procedure.
What does the selection diamond mean on a structure chart?
A diamond on the lines to modules shows selection: the module calls one of the modules below it, and the choice is decided when the program runs. The word 'either' in a description is the clue. A module that calls both modules is not drawn with a diamond.
What does a curved arrow that starts and ends at the same module mean on a structure chart?
A curved arrow that begins and ends at a module shows iteration. The module repeatedly calls the modules below it. A full answer names those modules in the correct sequence in which they are called.
How do you write a pseudocode header for a module in a structure chart?
A module that returns a value is a function, written with RETURNS. A module that returns nothing is a procedure. A parameter that the module assigns a new value to, for the caller to use, is passed with BYREF, so the caller sees the change.
How is a state-transition diagram drawn?
A state-transition diagram documents an algorithm. It shows the states a system can be in and the events that move it from one state to another. Each transition is a labelled arrow, and the arrow into the first state is labelled Start.
What is a common mistake when describing iteration in a structure chart?
A vague answer such as a loop will have Module A call the other Modules is too vague. A full answer shows that Module A repeatedly calls the modules in the correct sequence, and names each one.

Free notes are just the start.

Unlock every Workbook and Chapter at a Glance, and generate your own worksheets and predicted papers.

Explore plans

Related chapters