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
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
Represents a task or sub-task
Vertical line shows hierarchy
Horizontal arrow shows parameter passing
Example 1: Temperature Conversion (Fahrenheit to Celsius)
This structure chart shows how to convert temperature from Fahrenheit to Celsius:
• 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:
- INPUT Temperature: Gets temperature value from user
- Calculate Celsius: Uses formula: C = (F - 32) × 5/9
- OUTPUT Temperature: Displays the converted value
- Parameter passing: Temperature flows from INPUT to Calculate, Celsius flows from Calculate to OUTPUT
Example 2: Calculate Average of Two Numbers
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:
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.
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
1. What is the main purpose of a structure chart? [2 marks]
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
2. In a structure chart, what do arrows between modules represent? [2 marks]
Answer
- [1 mark] Parameters passed between modules
- [1 mark] The interface or communication between modules
- [Additional] Arrows point toward the module receiving the parameter
3. What is meant by "refinement" in structure charts? [2 marks]
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.
4. In the temperature conversion example, what parameters are passed between modules? [2 marks]
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
5. Why is decomposition important in program design? [2 marks]
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.
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:
Repetition in Structure Charts
How Repetition is Shown
Repetition is shown by adding a labelled semi-circular arrow above the modules to be repeated.
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:
The repetition arc shows that the entire process repeats until the user enters 999 as the temperature.
Example 3: Number Guessing Game (One Guess)
How it works:
- Generate SecretNumber: Creates a random number for the user to guess
- INPUT Guess: Gets the user's guess
- Decision point: Checks if guess equals secret number
- True path: Outputs congratulations message
- 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.
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:
- Prompts the user to enter username and password
- Validates the credentials against stored values
- If valid, displays "Login Successful"
- If invalid, displays "Login Failed" and allows up to 3 attempts
- After 3 failed attempts, displays "Account Locked"
Include selection for validation decision and repetition for multiple attempts.
Solution:
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:
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
1. How is selection represented in a structure chart? [2 marks]
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
2. How is repetition shown in a structure chart? [2 marks]
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")
3. In the sphere calculator example, what does the repetition condition check? [1 mark]
Answer
- [1 mark] Whether the entered radius equals 0
- [Additional] The program repeats until radius = 0 is entered (sentinel value)
4. What does the selection diamond check in the number guessing game? [1 mark]
Answer
- [1 mark] Whether the user's guess equals the secret number
- [Additional] If true, show congratulations; if false, show consolation message
5. Why would you use both selection and repetition in a structure chart? [2 marks]
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).
Round arrowhead indicates a Boolean flag parameter
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.
Double-headed arrow indicates the variable is modified
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.
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
- How many modules would be in Level 1?
- Where would selection be used?
- Where would repetition be used?
- What parameters would be passed between modules?
- 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:
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
1. What does an arrow with a solid round end represent? [2 marks]
Answer
- [1 mark] A flag (Boolean value) being passed
- [1 mark] A true/false value used for decision making
- [Additional] Examples: isValid, hasSufficientFunds, isComplete
2. What is the purpose of a double-headed arrow? [2 marks]
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)
3. Give an example of when you would use a flag in a structure chart. [2 marks]
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
4. What is the difference between a regular arrow and a double-headed arrow? [2 marks]
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)
5. Why are structure charts useful in program design? [3 marks]
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
1. What is a structure chart and what are its main components? [4 marks]
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
2. Draw a structure chart for a program that calculates the area of a rectangle. The program should input length and width, calculate area, and output the result. [5 marks]
Marking Scheme & Answer
- [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
3. Explain how selection and repetition are represented in structure charts. Include examples. [6 marks]
Marking Scheme & Answer
Selection:
• Diamond-shaped box
• Contains a condition/question
• Example: "Temperature in Fahrenheit?"
• True/false paths emerge from it
Repetition:
• 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
4. What is the difference between a regular parameter arrow and a flag arrow? Give an example of when each would be used. [4 marks]
Marking Scheme & Answer
Regular arrow
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
5. Design a structure chart for a simple ATM system that allows balance checking. Include: insert card, enter PIN, validate PIN, check balance, display balance. Use appropriate selection and repetition. [8 marks]
Marking Scheme & Answer
- [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
6. Explain the concept of "refinement" in structure charts. How does it help in program design? [3 marks]
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)
7. What is meant by "interface" in the context of structure charts? [2 marks]
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
8. Why would a programmer use a structure chart before writing code? [3 marks]
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
9. Describe a real-world scenario where a structure chart with both selection and repetition would be appropriate. [4 marks]
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
10. Compare structure charts with flowcharts. What are the key differences in their purpose and use? [4 marks]
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