SC

12.2 Structure Charts

Using structure charts to decompose problems and show module interfaces

Learning Objectives

By the end of this lesson, you will be able to:

  • Use a structure chart to decompose a problem into sub-tasks
  • Express parameters passed between modules/procedures/functions as part of algorithm design
  • Describe the purpose of a structure chart
  • Construct a structure chart for a given problem
  • Show selection and repetition in structure charts
  • Interpret different types of arrows in structure charts (flags, double-headed arrows)

Key Terms

Structure Chart

A modelling tool used in program design to decompose a problem into sub-tasks

Decomposition

Breaking down a complex problem into smaller, manageable sub-tasks

Module

A self-contained unit of code that performs a specific task

Parameter

A variable passed between modules; shown by arrows in structure charts

Interface

The way modules communicate with each other through parameter passing

Hierarchy

The arrangement of modules in levels, with higher levels refined into lower levels

Flag

A Boolean value (true/false) passed between modules

Refinement

Breaking down a module into more detailed sub-modules at lower levels

Structure Chart Basics

A structure chart is a modelling tool used in program design to decompose a problem into a set of sub-tasks. It shows the hierarchy of different modules and how they connect and interact with each other.

What Does a Structure Chart Show?

  • Hierarchy: Modules are arranged in levels
  • Modules: Each represented by a box
  • Parameters: Variables passed between modules shown by arrows
  • Interface: How modules communicate with each other
  • Refinement: Each level refines the level above into more detailed tasks
Key Concept

Level 0 (top) shows the main task. Level 1 shows the first refinement into sub-tasks. Level 2 shows further refinement if needed.

Elements of a Structure Chart

Module Name

Represents a task or sub-task

Vertical line shows hierarchy

Parameter

Horizontal arrow shows parameter passing

Example 1: Temperature Conversion (Fahrenheit to Celsius)

This structure chart shows how to convert temperature from Fahrenheit to Celsius:

Convert Temperature
INPUT Temperature
Temperature
Calculate Celsius
Celsius
OUTPUT Temperature

• Top level (Level 0): "Convert Temperature" - the main task

• Level 1: Three sub-tasks - INPUT, Calculate, OUTPUT

• Parameters: Temperature flows from INPUT to Calculate, Celsius flows from Calculate to OUTPUT

How it works:
  1. INPUT Temperature: Gets temperature value from user
  2. Calculate Celsius: Uses formula: C = (F - 32) × 5/9
  3. OUTPUT Temperature: Displays the converted value
  4. Parameter passing: Temperature flows from INPUT to Calculate, Celsius flows from Calculate to OUTPUT

Example 2: Calculate Average of Two Numbers

Calculate Average
INPUT Numbers
Number1, Number2
Calculate Average
Average
OUTPUT Average

This shows the complete interface: Number1 and Number2 are passed into the Calculate Average module, which computes the average and passes it to OUTPUT Average.

Real-Life Example: Online Food Ordering System

Think about ordering food online. The structure chart would decompose this into:

Process Food Order
Select Items
OrderItems
Calculate Total
TotalPrice
Confirm Order

Each module represents a clear sub-task: selecting items from the menu, calculating the total price (including tax and delivery), and confirming the order with payment. Parameters like OrderItems and TotalPrice flow between modules.

Structure Chart Builder

Build a simple structure chart by adding modules and connecting them with parameters.

Your structure chart will appear here. Use the controls below to add modules.
Start by adding a Main Task, then add Sub-Tasks.

How structure charts work:

  • Top-down design: Start with main task, then break it down
  • Module independence: Each module should do one specific thing
  • Parameter passing: Shows what data flows between modules
  • Hierarchy: Higher levels are more general, lower levels more specific

Check Your Understanding: Structure Chart Basics

Answer
  • [1 mark] To decompose a problem into a set of sub-tasks
  • [1 mark] To show the hierarchy of modules and how they interact
  • [Additional] It's a modelling tool used in program design
Answer
  • [1 mark] Parameters passed between modules
  • [1 mark] The interface or communication between modules
  • [Additional] Arrows point toward the module receiving the parameter
Answer
  • [1 mark] Breaking down a module into more detailed sub-modules
  • [1 mark] Each level of the chart is a refinement of the level above
  • [Additional] Level 1 refines Level 0, Level 2 refines Level 1, etc.
Answer
  • [1 mark] Temperature (passed from INPUT to Calculate)
  • [1 mark] Celsius (passed from Calculate to OUTPUT)
  • [Additional] These parameters form the interface between modules
Answer
  • [1 mark] Makes complex problems easier to understand and solve
  • [1 mark] Allows different programmers to work on different modules
  • [Additional] Facilitates testing, debugging, and maintenance of code

Selection and Repetition

Structure charts can show both selection (decisions) and repetition (loops) to represent more complex program logic.

Selection in Structure Charts

How Selection is Shown

Selection is represented using a diamond-shaped box that shows a condition that could be true or false.

Condition?
True False
Key Point

The diamond contains a question (condition). Different paths emerge from it depending on whether the condition is true or false.

Example: Temperature Conversion with Selection

Extending the temperature conversion to handle both Fahrenheit→Celsius and Celsius→Fahrenheit:

Convert Temperature
INPUT Temperature
temperature
Temperature in Fahrenheit?
True False
Convert to Celsius
Convert to Fahrenheit
convertedTemp
OUTPUT Temperature

Repetition in Structure Charts

How Repetition is Shown

Repetition is shown by adding a labelled semi-circular arrow above the modules to be repeated.

UNTIL condition
Module to Repeat
Loop Condition

The label on the arrow specifies the loop condition (e.g., "UNTIL temperature = 999")

Example: Repeated Temperature Conversion

Temperature conversion repeated until number 999 is input:

UNTIL temperature = 999
Convert Temperature
INPUT Temperature
temperature
Convert Temperature
convertedTemp
OUTPUT Temperature

The repetition arc shows that the entire process repeats until the user enters 999 as the temperature.

Example 3: Number Guessing Game (One Guess)

Number Guessing Game
Generate SecretNumber
INPUT Guess
Guess
Guess = SecretNumber?
True False
OUTPUT Congratulations
OUTPUT Consolation Message
How it works:
  1. Generate SecretNumber: Creates a random number for the user to guess
  2. INPUT Guess: Gets the user's guess
  3. Decision point: Checks if guess equals secret number
  4. True path: Outputs congratulations message
  5. False path: Outputs consolation message

Example 4: Sphere Volume/Surface Area Calculator

Draw a structure chart to input radius of sphere, calculate and output either volume or surface area. Algorithm should repeat until radius of zero is entered.

UNTIL radius = 0
Volume and Surface Area Calculator
INPUT radius
radius
Calculate Volume?
True False
Calculate volume
Calculate surface area
answer
Output answer

The repetition arc shows the entire process repeats until radius = 0 is entered. The selection diamond lets the user choose whether to calculate volume or surface area.

Activity 1: Design a Structure Chart

Design a structure chart for a simple login system that:

  1. Prompts the user to enter username and password
  2. Validates the credentials against stored values
  3. If valid, displays "Login Successful"
  4. If invalid, displays "Login Failed" and allows up to 3 attempts
  5. After 3 failed attempts, displays "Account Locked"

Include selection for validation decision and repetition for multiple attempts.

Solution:
UNTIL attempts ≥ 3 OR valid = True
Login System
INPUT Credentials
username, password
Validate Credentials
valid
valid = True?
True False
OUTPUT Success
OUTPUT Failure
attempts ≥ 3?
True False
OUTPUT Account Locked

Explanation: The repetition arc shows the loop for multiple attempts. The first selection checks if credentials are valid. The second selection checks if maximum attempts (3) have been reached. Note the flag arrow for the "valid" parameter.

Real-Life Example: ATM Cash Withdrawal

An ATM withdrawal process with selection and repetition:

// Structure would include:
- Insert card (repeats until valid card inserted)
- Enter PIN (selection: valid/invalid, repetition for attempts)
- Select transaction type (selection: withdrawal, balance, etc.)
- Enter amount (selection: check if sufficient funds)
- Dispense cash (repeats for multiple transactions)
// Selection handles decisions like "valid PIN?"
// Repetition handles multiple attempts and multiple transactions

The ATM uses selection to decide if the PIN is correct and if there are sufficient funds. It uses repetition to allow multiple transaction attempts and to handle multiple transactions per session.

Check Your Understanding: Selection & Repetition

Answer
  • [1 mark] Using a diamond-shaped box
  • [1 mark] The diamond contains a condition/question
  • [Additional] Different paths emerge from the diamond for true/false outcomes
Answer
  • [1 mark] Using a labelled semi-circular arrow above modules
  • [1 mark] The arrow indicates which modules are repeated
  • [Additional] The label specifies the loop condition (e.g., "UNTIL condition")
Answer
  • [1 mark] Whether the entered radius equals 0
  • [Additional] The program repeats until radius = 0 is entered (sentinel value)
Answer
  • [1 mark] Whether the user's guess equals the secret number
  • [Additional] If true, show congratulations; if false, show consolation message
Answer
  • [1 mark] Selection allows different paths based on conditions
  • [1 mark] Repetition allows tasks to be repeated multiple times
  • [Additional] Together they can model complex real-world processes with decisions and loops

Advanced Concepts

Structure charts include special notations for different types of parameter passing and interface specifications.

Special Arrow Notations

Flag (Boolean Value)

An arrow with a solid round end shows that the value transferred is a flag (a Boolean value - true or false).

isValid

Round arrowhead indicates a Boolean flag parameter

Example Usage

A validation module might return a flag "isValid" (true/false) to indicate whether input data is acceptable.

Updated Variable

A double-headed arrow shows that a variable value is updated within the module.

counter

Double-headed arrow indicates the variable is modified

Example Usage

A counter module might both receive and update a "counter" variable (e.g., incrementing it).

Example 5: KM to Miles Conversion

Draw a structure chart for: Input a number of km, output the equivalent number of miles.

Conversion
INPUT km
NumberOfKm
Convert to Miles
NumberOfMiles
OUTPUT miles

This shows a simple linear flow: INPUT → Convert → OUTPUT. The parameter NumberOfKm flows into the conversion module, which calculates NumberOfMiles (miles = km × 0.621371) and passes it to OUTPUT.

Activity 2: Analyze Structure Chart Elements

Analyze the following structure chart description and identify:

Student Grading System:
1. INPUT student marks (out of 100)
2. Validate marks (must be 0-100)
3. If valid, calculate grade; if invalid, show error
4. Calculate grade based on: A (90-100), B (80-89), C (70-79), D (60-69), F (0-59)
5. OUTPUT grade
6. Repeat for multiple students until "END" is entered

  1. How many modules would be in Level 1?
  2. Where would selection be used?
  3. Where would repetition be used?
  4. What parameters would be passed between modules?
  5. Would any flags be needed? If so, what would they be?
Solution:

1. Level 1 modules:

At least 4 modules: INPUT marks, Validate marks, Calculate grade, OUTPUT grade

2. Selection usage:

Two selection points:

  • After validation: check if marks are valid (true/false)
  • In grade calculation: multiple branches for different grade ranges (A, B, C, D, F)

3. Repetition usage:

The entire process would be under a repetition arc for "UNTIL 'END' is entered"

4. Parameters passed:

  • marks (from INPUT to Validate)
  • isValid flag (from Validate to decision point)
  • validMarks (from decision true path to Calculate grade)
  • grade (from Calculate grade to OUTPUT)

5. Flags needed:

Yes, one flag: isValid (Boolean) from Validate marks module, shown with round arrowhead

Real-Life Example: Online Payment Processing

Online payment systems use structure charts with flags and updated variables:

// Payment processing structure:
- INPUT payment details (card number, amount)
- Validate card (returns isValid flag)
- Selection: if isValid then process, else reject
- Check funds (returns hasSufficientFunds flag)
- Selection: if hasSufficientFunds then deduct, else decline
- Update account balance (double-headed arrow for balance)
- Generate receipt
// Flags: isValid, hasSufficientFunds (Boolean values)
// Updated variable: accountBalance (double-headed arrow)

The system uses flags to make decisions (is the card valid? are there sufficient funds?) and updates variables (account balance decreases after payment).

Structure Chart Notation Summary

Symbol Name Meaning Example
Module
Module/Box Represents a task or sub-task "Calculate Average", "INPUT Temperature"
Vertical Connector Shows hierarchy between levels Connects Level 0 to Level 1 modules
data
Parameter Arrow Shows parameter passed to a module Temperature passed to Calculate module
Condition?
Selection Diamond Represents a decision/condition "Temperature in Fahrenheit?", "Guess = SecretNumber?"
UNTIL condition
Module
Repetition Arc Shows modules to be repeated "UNTIL radius = 0", "FOR 3 attempts"
isValid
Flag Arrow Boolean value (true/false) passed isValid, hasSufficientFunds
counter
Double-headed Arrow Variable updated within module counter, accountBalance
Remember These Key Points
  • Top-down design: Start with main task, then decompose into sub-tasks
  • One task per module: Each module should do one specific thing
  • Clear interfaces: Parameters show exactly what data flows between modules
  • Hierarchy: Higher levels are more abstract, lower levels more detailed
  • Standard notations: Use correct symbols for selection, repetition, flags, etc.
  • No implementation details: Structure charts show WHAT, not HOW

Check Your Understanding: Advanced Concepts

Answer
  • [1 mark] A flag (Boolean value) being passed
  • [1 mark] A true/false value used for decision making
  • [Additional] Examples: isValid, hasSufficientFunds, isComplete
Answer
  • [1 mark] Shows that a variable value is updated within the module
  • [1 mark] Indicates the module both receives and modifies the variable
  • [Additional] Examples: counter (incremented), balance (updated)
Answer
  • [1 mark] Validation module returning whether input is valid
  • [1 mark] Authentication module returning whether login is successful
  • [Additional] Any yes/no, true/false decision point in the program
Answer
  • [1 mark] Regular arrow: data passed one-way into a module
  • [1 mark] Double-headed arrow: variable is modified/updated within the module
  • [Additional] Double-headed arrows show two-way data flow (in and out)
Answer
  • [1 mark] Help decompose complex problems into manageable sub-tasks
  • [1 mark] Show clear interfaces between modules through parameter passing
  • [1 mark] Visualize program structure and logic flow before coding
  • [Additional] Facilitate team collaboration and communication about design

Key Takeaways

  • A structure chart is a modelling tool used to decompose problems into sub-tasks
  • Structure charts show hierarchy - each level refines the level above into more detailed tasks
  • Each module is represented by a box containing the task name
  • Parameters passed between modules are shown by arrows pointing toward the receiving module
  • The set of parameters forms the interface between modules
  • Selection (decisions) is shown using a diamond-shaped box containing a condition
  • Repetition (loops) is shown using a labelled semi-circular arrow above the modules to be repeated
  • An arrow with a solid round end represents a flag (Boolean true/false value)
  • A double-headed arrow shows that a variable is updated within a module
  • Structure charts help visualize program structure before coding
  • They promote modular design where each module does one specific task
  • Common applications: input-process-output systems, validation systems, calculation systems
  • Real-world examples: temperature converters, login systems, payment processors, grading systems
  • Structure charts show WHAT the program does, not HOW it does it (no implementation details)
  • They are essential for top-down design and breaking complex problems into manageable parts

Question Bank

Marking Scheme & Answer
  • [1 mark] A modelling tool used in program design to decompose problems
  • [1 mark] Modules (boxes) representing tasks/sub-tasks
  • [1 mark] Arrows showing parameters passed between modules
  • [1 mark] Hierarchy showing refinement from higher to lower levels
  • [Additional] May also include selection diamonds and repetition arrows
Marking Scheme & Answer
Calculate Rectangle Area
INPUT Dimensions
length, width
Calculate Area
area
OUTPUT Area
  • [1 mark] Correct Level 0 module: "Calculate Rectangle Area"
  • [1 mark] Three Level 1 modules: INPUT, Calculate, OUTPUT
  • [1 mark] Correct parameters: length, width passed to Calculate
  • [1 mark] Correct parameter: area passed to OUTPUT
  • [1 mark] Proper hierarchy and connectors
Marking Scheme & Answer
Selection:
Condition?

• Diamond-shaped box
• Contains a condition/question
• Example: "Temperature in Fahrenheit?"
• True/false paths emerge from it

Repetition:
UNTIL condition
Module

• Semi-circular arrow above modules
• Label specifies loop condition
• Example: "UNTIL radius = 0"
• Shows which modules are repeated

  • [2 marks] Selection: diamond shape with condition, shows decision points
  • [2 marks] Repetition: semi-circular arrow with label, shows looping
  • [1 mark] Example for selection: temperature conversion choice
  • [1 mark] Example for repetition: repeating until sentinel value
Marking Scheme & Answer
temperature

Regular arrow

isValid

Flag arrow

  • [1 mark] Regular arrow: passes data values (numbers, strings, etc.)
  • [1 mark] Flag arrow: passes Boolean values (true/false) with solid round end
  • [1 mark] Regular arrow example: temperature value passed to conversion module
  • [1 mark] Flag arrow example: isValid flag returned from validation module
  • [Additional] Flags are used for decision making; regular data for processing
Marking Scheme & Answer
UNTIL card removed
ATM Balance Check
Insert Card
Enter PIN
PIN
Validate PIN
isValid
isValid = True?
True False
Check Balance
balance
Display Error
Display Balance
  • [2 marks] Correct modules: Insert Card, Enter PIN, Validate PIN, Check Balance, Display Balance/Error
  • [2 marks] Proper parameter passing: PIN, isValid flag, balance
  • [2 marks] Correct selection: diamond checking isValid flag
  • [1 mark] Proper use of flag arrow for isValid
  • [1 mark] Logical flow and hierarchy with repetition
Marking Scheme & Answer
  • [1 mark] Refinement is breaking down a module into more detailed sub-modules at lower levels
  • [1 mark] Each level of the structure chart is a refinement of the level above
  • [1 mark] Helps by making complex problems manageable through stepwise decomposition
  • [Additional] Allows focusing on one level of detail at a time (top-down design)
Marking Scheme & Answer
  • [1 mark] The way modules communicate with each other
  • [1 mark] The parameters passed between modules (shown by arrows)
  • [Additional] Defines what data flows into and out of each module
Marking Scheme & Answer
  • [1 mark] To plan and visualize the program structure
  • [1 mark] To decompose complex problems into manageable sub-tasks
  • [1 mark] To identify module interfaces and parameter requirements
  • [Additional] To facilitate team communication and divide work among programmers
Marking Scheme & Answer
  • [1 mark] Online shopping checkout system
  • [1 mark] Repetition: process multiple items in shopping cart
  • [1 mark] Selection: choose payment method (credit card, PayPal, etc.)
  • [1 mark] Selection: validate payment details (valid/invalid)
  • [Additional] Other examples: quiz system, hotel booking, library management
Marking Scheme & Answer
Aspect Structure Chart Flowchart
Purpose Show program structure and module hierarchy Show step-by-step algorithm flow
Focus WHAT tasks are done (modules) HOW tasks are done (steps)
Level of detail High-level, modular Detailed, procedural
Shows Module interfaces, parameters Control flow, decisions, loops
When used Program design phase Algorithm design phase
  • [2 marks] Structure charts show WHAT (modules, hierarchy); flowcharts show HOW (steps, flow)
  • [1 mark] Structure charts emphasize module interfaces; flowcharts emphasize control flow
  • [1 mark] Structure charts used in design; flowcharts used in algorithm development