A-Level Computer Science / Unit 12: Software Design, Testing and Evolution

12.2.3 Turning a Structure Chart into Pseudocode

πŸ”’ Lesson slides are available to signed-in users. Sign in

12.2.3 Turning a Structure Chart into Pseudocode

A structure chart describes the organisation of a modular solution. It identifies the modules, their relationships, the values passed between them and any selection or repetition used by the design.

To implement that design, each module must be represented by pseudocode and the parent modules must contain suitable calls, arguments and control structures.

By the end of this section, you should be able to:

  • Translate module boxes into procedure or function definitions.
  • Convert module connections into calls with suitable arguments.
  • Represent returned values and updated parameters correctly.
  • Translate selection and repetition notation into pseudocode.
  • Check that pseudocode preserves the meaning of a structure chart.
  • Derive a complete modular pseudocode solution from a given chart.

What Does β€œEquivalent Pseudocode” Mean?

Equivalent pseudocode implements the design expressed by the structure chart. It should preserve the same:

  • module responsibilities;
  • parent and child relationships;
  • parameter flow;
  • returned or updated values;
  • selection conditions;
  • repetition conditions.
Equivalent pseudocode: pseudocode that represents the same modular organisation, communication and control behaviour as the structure chart.

Equivalent does not necessarily mean that only one answer is possible. A returned result might be represented by a function, while another valid design might use a procedure with a reference parameter.

The important question is whether the pseudocode has the same effect as the chart.

Common misconception: Deriving pseudocode is not simply copying module names into a list. The calls, arguments, control structures and module definitions must also be represented.

Mapping Structure-Chart Features to Pseudocode

Structure-chart feature Pseudocode representation Example
Top-level module Main procedure or controlling module PROCEDURE ProcessDonationBatch
Child module Procedure or function definition PROCEDURE ReadDonation(...)
Parent-to-child connection Procedure call or function call CALL DisplayBatchTotal(TotalPackets)
Parameter arrow into a module Argument in the call and parameter in the header PacketCount
Value returned by a function Assignment containing a function call Accepted ← DonationIsValid(PacketCount, GerminationRate)
Selection marker IF ... THEN ... ELSE ... ENDIF IF DonationAccepted = TRUE THEN
Repetition marker WHILE, REPEAT or FOR WHILE MoreDonations = TRUE DO
Updated parameter Reference parameter or a returned value assigned back to the variable BYREF TotalPackets : INTEGER
Boolean control flag Boolean variable used in a condition DonationAccepted
Exam tip: Translate the chart in layers: first the module skeleton, then the interfaces, and finally the selection and repetition.

Start with the Top-Level Module

The highest module represents the complete task. It normally becomes the main procedure that coordinates the lower-level modules.

Suppose the top-level box is:

ProcessDonationBatch

An initial pseudocode skeleton can be written as:

PROCEDURE ProcessDonationBatch

ENDPROCEDURE

At this stage, the module body is intentionally empty. Calls and control structures will be added by reading the lower levels of the chart.

Declare local variables

Values that must be retained by the controlling procedure should normally be declared locally inside it.

PROCEDURE ProcessDonationBatch
    DECLARE SeedType : STRING
    DECLARE PacketCount : INTEGER
    DECLARE GerminationRate : INTEGER
    DECLARE TotalPackets : INTEGER
    DECLARE DonationAccepted : BOOLEAN
    DECLARE MoreDonations : BOOLEAN
ENDPROCEDURE
Common mistake: Do not automatically declare every identifier as global. The chart's interfaces allow modules to communicate using parameters.

Turn Child Modules into Calls

A lower-level module used by a parent must normally be called from the parent's pseudocode.

Consider this simplified hierarchy:

ProcessDonationBatch
β”œβ”€β”€ ReadDonation
β”œβ”€β”€ DonationIsValid
└── DisplayBatchTotal

The controlling procedure might contain:

CALL ReadDonation(SeedType, PacketCount, GerminationRate)

DonationAccepted ← DonationIsValid(
    PacketCount,
    GerminationRate
)

CALL DisplayBatchTotal(TotalPackets)
Module type Typical call form
Procedure performing an action CALL ProcedureName(Arguments)
Function returning a value Result ← FunctionName(Arguments)
Function used directly in a condition IF FunctionName(Arguments) = TRUE THEN
Exam tip: Every child module shown as part of the design should be represented either by a call or by a clearly justified alternative.

Deciding Between a Procedure and a Function

A structure-chart box identifies a module but does not always state whether that module must be implemented as a procedure or a function.

Use a procedure when... Use a function when...
The module performs an action such as input or output. The module calculates and returns one value.
The module needs to update several reference parameters. The returned result belongs naturally inside an expression.
No single value represents the module's main result. The function has one clear result with a suitable data type.

Procedure example

PROCEDURE DisplayBatchTotal(
    BYVALUE TotalPackets : INTEGER
)
    OUTPUT "Accepted packets: ", TotalPackets
ENDPROCEDURE

Function example

FUNCTION DonationIsValid(
    BYVALUE PacketCount : INTEGER,
    BYVALUE GerminationRate : INTEGER
) RETURNS BOOLEAN

    RETURN PacketCount > 0
           AND GerminationRate >= 70
ENDFUNCTION
Common misconception: A module is not a function merely because it communicates with another module. A function has a return value that replaces its call.

Translate Parameter Arrows into Interfaces

A labelled arrow identifies a value that crosses a module boundary. That value must appear in the module header and in the corresponding call.

Parameter: an identifier in a procedure or function header.
Argument: the actual value or expression supplied in a call.

Structure-chart information

DonationIsValid receives:
    PacketCount
    GerminationRate

DonationIsValid returns:
    DonationAccepted

Equivalent pseudocode

DonationAccepted ← DonationIsValid(
    PacketCount,
    GerminationRate
)
FUNCTION DonationIsValid(
    BYVALUE NumberOfPackets : INTEGER,
    BYVALUE Rate : INTEGER
) RETURNS BOOLEAN

    RETURN NumberOfPackets > 0
           AND Rate >= 70
ENDFUNCTION

In the call, PacketCount and GerminationRate are arguments. In the function header, NumberOfPackets and Rate are parameters.

Common mistake: Argument names do not need to match parameter names. Their order, purpose and compatible data types must match.

Translate Selection into an IF Statement

A selection marker and its labelled branches become a conditional statement.

Structure-chart meaning

DonationAccepted?
β”œβ”€β”€ TRUE: AddAcceptedPackets
β”‚         DisplayAcceptance
└── FALSE: DisplayRejection

Equivalent pseudocode

IF DonationAccepted = TRUE THEN
    CALL AddAcceptedPackets(
        PacketCount,
        TotalPackets
    )

    CALL DisplayAcceptance(
        SeedType,
        PacketCount
    )
ELSE
    CALL DisplayRejection(SeedType)
ENDIF

All modules below the true branch are placed inside the THEN block. Modules below the false branch are placed inside the ELSE block.

Exam tip: Preserve the branch condition exactly. Do not reverse the true and false module calls.
Common mistake: Do not call both branch modules before writing the IF statement. Only the selected branch should execute.

Translate Repetition into a Loop

A repetition arrow identifies the module or modules that must be called repeatedly. The label identifies the controlling condition.

Structure-chart meaning

Repeat while MoreDonations = TRUE:
    ReadDonation
    DonationIsValid
    selected acceptance or rejection modules
    CheckForMoreDonations

Equivalent pseudocode

MoreDonations ← CheckForMoreDonations()

WHILE MoreDonations = TRUE DO
    CALL ReadDonation(
        SeedType,
        PacketCount,
        GerminationRate
    )

    DonationAccepted ← DonationIsValid(
        PacketCount,
        GerminationRate
    )

    // selection pseudocode belongs here

    MoreDonations ← CheckForMoreDonations()
ENDWHILE

The flag is checked before the first cycle, so a WHILE loop is suitable. A REPEAT loop would be more suitable if the repeated group had to run at least once before the condition was tested.

Exam tip: Choose the loop form from the position and meaning of the condition, not from personal preference.
Common mistake: A loop-control flag must be updated inside the loop when its value can change. Otherwise, the loop may never terminate.

Translate an Updated Parameter

A double-headed arrow means that a value is supplied to a module and comes back with a possible update.

Structure-chart meaning

AddAcceptedPackets receives:
    PacketCount
    TotalPackets

AddAcceptedPackets updates:
    TotalPackets

One valid implementation uses a reference parameter:

CALL AddAcceptedPackets(
    PacketCount,
    TotalPackets
)
PROCEDURE AddAcceptedPackets(
    BYVALUE PacketCount : INTEGER,
    BYREF TotalPackets : INTEGER
)
    TotalPackets ← TotalPackets + PacketCount
ENDPROCEDURE

Another valid implementation could use a function:

TotalPackets ← CalculateNewTotal(
    PacketCount,
    TotalPackets
)
FUNCTION CalculateNewTotal(
    BYVALUE PacketCount : INTEGER,
    BYVALUE CurrentTotal : INTEGER
) RETURNS INTEGER

    RETURN CurrentTotal + PacketCount
ENDFUNCTION
The structure chart defines the required effect: the parent receives an updated total. It does not, by itself, force one parameter-passing method.
Common misconception: Do not add BYREF merely because an arrow is drawn. Use it when the procedure must alter the caller's variable.

Worked Example: Seed-Library Donation Batch

A community seed library processes donation forms. Each form contains:

  • a seed type;
  • the number of packets;
  • a germination-rate percentage.

A donation is accepted when the number of packets is greater than zero and the germination rate is at least 70%. Accepted packet quantities are added to a batch total. Processing continues while more donation forms remain.

Text representation of the structure chart

ProcessDonationBatch
β”œβ”€β”€ InitialiseBatch
β”‚   └── returns TotalPackets
β”œβ”€β”€ CheckForMoreDonations
β”‚   └── returns MoreDonations
β”œβ”€β”€ WHILE MoreDonations = TRUE
β”‚   β”œβ”€β”€ ReadDonation
β”‚   β”‚   └── returns SeedType, PacketCount,
β”‚   β”‚       GerminationRate
β”‚   β”œβ”€β”€ DonationIsValid
β”‚   β”‚   β”œβ”€β”€ receives PacketCount, GerminationRate
β”‚   β”‚   └── returns DonationAccepted
β”‚   β”œβ”€β”€ IF DonationAccepted = TRUE
β”‚   β”‚   β”œβ”€β”€ AddAcceptedPackets
β”‚   β”‚   β”‚   β”œβ”€β”€ receives PacketCount
β”‚   β”‚   β”‚   └── updates TotalPackets
β”‚   β”‚   └── DisplayAcceptance
β”‚   β”‚       └── receives SeedType, PacketCount
β”‚   └── ELSE
β”‚       └── DisplayRejection
β”‚           └── receives SeedType
└── DisplayBatchTotal
    └── receives TotalPackets

Step 1: Create the controlling procedure

PROCEDURE ProcessDonationBatch
    DECLARE SeedType : STRING
    DECLARE PacketCount : INTEGER
    DECLARE GerminationRate : INTEGER
    DECLARE TotalPackets : INTEGER
    DECLARE DonationAccepted : BOOLEAN
    DECLARE MoreDonations : BOOLEAN
ENDPROCEDURE

Step 2: Add initialisation

CALL InitialiseBatch(TotalPackets)
MoreDonations ← CheckForMoreDonations()

Step 3: Add the repeated module calls

WHILE MoreDonations = TRUE DO
    CALL ReadDonation(
        SeedType,
        PacketCount,
        GerminationRate
    )

    DonationAccepted ← DonationIsValid(
        PacketCount,
        GerminationRate
    )

    MoreDonations ← CheckForMoreDonations()
ENDWHILE

Step 4: Place the selected calls inside the loop

IF DonationAccepted = TRUE THEN
    CALL AddAcceptedPackets(
        PacketCount,
        TotalPackets
    )

    CALL DisplayAcceptance(
        SeedType,
        PacketCount
    )
ELSE
    CALL DisplayRejection(SeedType)
ENDIF

Step 5: Add the final output

CALL DisplayBatchTotal(TotalPackets)

Complete Derived Pseudocode

Controlling procedure

PROCEDURE ProcessDonationBatch
    DECLARE SeedType : STRING
    DECLARE PacketCount : INTEGER
    DECLARE GerminationRate : INTEGER
    DECLARE TotalPackets : INTEGER
    DECLARE DonationAccepted : BOOLEAN
    DECLARE MoreDonations : BOOLEAN

    CALL InitialiseBatch(TotalPackets)

    MoreDonations ← CheckForMoreDonations()

    WHILE MoreDonations = TRUE DO
        CALL ReadDonation(
            SeedType,
            PacketCount,
            GerminationRate
        )

        DonationAccepted ← DonationIsValid(
            PacketCount,
            GerminationRate
        )

        IF DonationAccepted = TRUE THEN
            CALL AddAcceptedPackets(
                PacketCount,
                TotalPackets
            )

            CALL DisplayAcceptance(
                SeedType,
                PacketCount
            )
        ELSE
            CALL DisplayRejection(SeedType)
        ENDIF

        MoreDonations ← CheckForMoreDonations()
    ENDWHILE

    CALL DisplayBatchTotal(TotalPackets)
ENDPROCEDURE

Initialisation procedure

PROCEDURE InitialiseBatch(
    BYREF TotalPackets : INTEGER
)
    TotalPackets ← 0
ENDPROCEDURE

Input procedure

PROCEDURE ReadDonation(
    BYREF SeedType : STRING,
    BYREF PacketCount : INTEGER,
    BYREF GerminationRate : INTEGER
)
    OUTPUT "Seed type:"
    INPUT SeedType

    OUTPUT "Number of packets:"
    INPUT PacketCount

    OUTPUT "Germination rate:"
    INPUT GerminationRate
ENDPROCEDURE

Validation function

FUNCTION DonationIsValid(
    BYVALUE PacketCount : INTEGER,
    BYVALUE GerminationRate : INTEGER
) RETURNS BOOLEAN

    RETURN PacketCount > 0
           AND GerminationRate >= 70
ENDFUNCTION

Updated-total procedure

PROCEDURE AddAcceptedPackets(
    BYVALUE PacketCount : INTEGER,
    BYREF TotalPackets : INTEGER
)
    TotalPackets ← TotalPackets + PacketCount
ENDPROCEDURE

Output procedures

PROCEDURE DisplayAcceptance(
    BYVALUE SeedType : STRING,
    BYVALUE PacketCount : INTEGER
)
    OUTPUT PacketCount,
           " packet(s) of ",
           SeedType,
           " accepted"
ENDPROCEDURE
PROCEDURE DisplayRejection(
    BYVALUE SeedType : STRING
)
    OUTPUT "Donation of ",
           SeedType,
           " rejected"
ENDPROCEDURE
PROCEDURE DisplayBatchTotal(
    BYVALUE TotalPackets : INTEGER
)
    OUTPUT "Total accepted packets: ",
           TotalPackets
ENDPROCEDURE

More-donations function

FUNCTION CheckForMoreDonations()
RETURNS BOOLEAN

    DECLARE Response : CHAR

    OUTPUT "Another donation? Y/N"
    INPUT Response

    RETURN Response = 'Y'
ENDFUNCTION
Important: The detailed statements inside each module come from the problem requirements. A structure chart normally gives the module organisation and interfaces, but it may not provide every internal algorithmic step.

Check That the Pseudocode Is Equivalent

After writing the pseudocode, compare it systematically with the chart.

Check Question Seed-library example
Module coverage Has every chart module been defined and called? ReadDonation, DonationIsValid and all output modules appear.
Interface accuracy Do calls and headers contain matching values? DonationIsValid receives two integer arguments.
Return values Are returned results captured? The result of DonationIsValid is assigned to DonationAccepted.
Selection Are true and false modules inside the correct branches? Accepted packets are added only when the Boolean flag is true.
Repetition Are exactly the intended modules inside the loop? Reading, checking and responding repeat for each donation.
Loop update Can the repetition condition change? MoreDonations is recalculated at the end of each cycle.
Updated values Does the new value reach the parent module? TotalPackets is passed by reference and updated.
Variable scope Are temporary values kept local where possible? Each procedure uses only its parameters and local variables.
Exam tip: Trace one sample value through the chart and the pseudocode. It should be created, passed, processed and returned in the same way.

Interactive: Chart-to-Pseudocode Translator

Build the pseudocode in layers. Use the tabs to move from module boxes to interfaces, control structures and the complete modular solution.

Scenario: community seed-library donations

Module skeleton

Translate each module into a pseudocode definition

Begin with procedure and function headers. Calls, parameters and control structures will be added in later stages.

Focus: one module box normally becomes one procedure or function.

Mapping 1 of 5

Top-level module

ProcessDonationBatch becomes the controlling procedure.

Common Mistakes and Misconceptions

  • Writing calls but no module definitions. Each procedure or function used by the design should also be defined.
  • Defining modules but never calling them. Child modules need to be connected to their parent in the pseudocode.
  • Ignoring parameter arrows. Calls and headers must represent values passed across interfaces.
  • Confusing arguments and parameters. Arguments appear in calls; parameters appear in headers.
  • Ignoring a function's return value. The result should be assigned or used in an expression.
  • Calling both selection branches. Alternative module calls belong inside the correct THEN and ELSE blocks.
  • Placing final output inside the loop. Only modules below the chart's repetition marker should repeat.
  • Failing to update the loop flag. This can produce an infinite loop.
  • Assuming chart position gives complete execution order. Use parameter dependencies and control labels to determine the algorithm.
  • Inventing internal logic not supported by the problem. The chart provides the design structure; module bodies must follow the stated requirements.

Practice

Core questions

  1. Explain what is meant by deriving equivalent pseudocode from a structure chart.
  2. State how a child module is represented in its parent's pseudocode.
  3. Explain how a returned function value should be used.
  4. Explain how a selection marker is translated.
  5. Explain how a repetition marker is translated.
  6. Give two possible ways of representing an updated value.
  7. Explain why a structure chart may not provide every statement needed inside a module.

Scenario A: Community Fridge Deliveries

A program processes food deliveries while more delivery records remain. It reads a food category, quantity and use-by date. A function checks whether the delivery can be accepted. Accepted quantities update TotalItems. Rejected deliveries display a reason.

  1. Write a suitable top-level procedure header.
  2. Write the call to the input procedure.
  3. Write a Boolean validation function header.
  4. Write the assignment that captures the function result.
  5. Write the selection structure.
  6. Write the repetition structure.
  7. Define a procedure that updates TotalItems.

Scenario B: Observatory Image Review

A program repeatedly reads an image identifier and confidence score. Images with a confidence score of at least 85 are stored for expert review. Other images are recorded as uncertain. After all images have been processed, the program outputs the number stored for review.

  1. Design a structure chart for the problem.
  2. Identify every parameter arrow.
  3. Identify the selection flag and repetition flag.
  4. Derive the controlling pseudocode.
  5. Define the procedures and functions.
  6. Check the pseudocode against the chart.
Challenge: Implement an updated value twice: first using BYREF, then using a function return. Explain why both versions have the same external effect.

Review

Structure-chart feature Pseudocode equivalent
Top-level module Controlling procedure
Child module Procedure or function definition and call
Downward parameter Argument supplied to the called module
Upward function result Return value assigned or used in an expression
Updated parameter Reference parameter or value returned and reassigned
Selection marker IF ... THEN ... ELSE ... ENDIF
Repetition marker A suitable WHILE, REPEAT or FOR loop
Control flag Boolean variable used by a condition
Final exam tip: Work in the order modules β†’ calls β†’ interfaces β†’ selection β†’ repetition β†’ module bodies β†’ final check.