12.2 Programme Design – Structure Charts
Learning Objective
Use a structure chart to decompose a problem into sub‑tasks and to specify the parameters passed between the modules, procedures or functions that form part of the algorithm design.
1. What is a Structure Chart?
- Definition: A hierarchical diagram that shows how a program is broken into modules (or routines) and how data (parameters) flow between them.
- Purpose:
- Logical decomposition of a problem (top‑down design).
- Explicit definition of module interfaces.
- Facilitates modular programming and independent testing.
- Key symbols
- Rectangle – a module (procedure, function or sub‑program).
- Arrow – a parameter (data) passed from a parent module to a child module.
- Solid line – input or output parameter.
- Dotted line – in‑out (read‑and‑write) parameter.
2. Relationship to Other Design Artefacts (Cambridge 9618)
| Design artefact | When to use it | What it shows |
|---|
| Structure chart | During analysis → design for procedural/functional solutions. | Module hierarchy and parameter flow. |
| Flowchart | When you need to detail the internal logic of a single module. | Control flow (decisions, loops, sequence) inside a module. |
| State‑transition diagram | For event‑driven or reactive systems (e.g., GUIs, vending machines). | System states, events and transitions. |
3. Role in the Development Life‑Cycle
- Produced after problem analysis and before coding.
- Drives:
- Module‑level design (AO2 – analyse the problem).
- Implementation planning – each box becomes a routine.
- Testing strategy – each module can be unit‑tested (AO3 – design & evaluate).
- Provides a reference for documentation and for the examiner when marking.
4. Steps to Create a Structure Chart
- Analyse the problem statement. Identify the main goal and any sub‑goals.
- Define the top‑level module. Usually called
main or a descriptive name such as ProcessLoan. - Decompose the top‑level module. Keep breaking it into logical sub‑modules until each is small enough to be coded comfortably (≈10–20 lines of code).
- Identify data items for each module.
- What the module receives (input parameters).
- What the module returns (output parameters).
- What the module both reads and modifies (in‑out parameters).
- Decide on scope and naming. Avoid global variables; pass everything a module needs as a parameter. Use lower‑case, self‑explanatory names (e.g.,
studentMarks, totalScore). - Draw the chart. Use rectangles for modules and arrows for parameter flow. Read from top (high‑level) to bottom (low‑level).
- Validate the design. Check that:
- Every required data item is passed exactly once.
- No unnecessary dependencies exist.
- The hierarchy matches the intended algorithm.
5. Parameter Types
| Type | Description | Typical use |
|---|
| Input | Values supplied to a module; read‑only inside the module. | Marks, weights, IDs, search strings. |
| Output | Values returned to the caller; not modified by the caller. | Calculated score, grade letter, boolean result. |
| In‑out | Values that are both read and modified by the module. | Running totals, counters, data structures that must be updated. |
6. Parameter Scope & Naming Conventions
- Local scope – a parameter exists only inside the module that receives it.
- Avoid globals – passing parameters makes dependencies explicit and simplifies testing.
- Naming guidelines
- lower‑case, meaningful words (e.g.,
studentID, weightedScore). - Arrays: plural nouns (
marksArray). - Direction hint (optional):
inMarks, outGrade.
7. Illustrative Example – Grade Calculation
7.1 Problem Statement
Calculate the final grade for each student in a class.
Each student has marks for three assessments with different weights.
The final grade is the weighted sum, rounded to the nearest integer, and then classified as A, B, C, D or F.
7.2 Decomposition into Modules
| Module | Purpose | Input parameters | Output / In‑out parameters |
|---|
Main | Coordinates overall processing. | – | – |
ReadData | Read number of students and their three assessment marks. | – | studentsMarks[][3] (array), numStudents (int) – output |
ProcessStudent | Handles the complete calculation for one student. | marks[3] | grade (char) – output |
ComputeWeightedSum | Calculate S = w₁·m₁ + w₂·m₂ + w₃·m₃. | marks[3], weights[3] | rawScore (real) – output |
RoundResult | Round the raw score to the nearest integer. | rawScore (real) | roundedScore (int) – output |
ClassifyGrade | Map the rounded score to a grade letter. | roundedScore (int) | grade (char) – output |
OutputResult | Display the student’s final grade. | studentID, grade | – |
UpdateRunningTotal (in‑out example) | Maintain a cumulative total of all rounded scores. | roundedScore (int) | totalScore (int) – in‑out |
7.3 Parameter Flow (single student)
ReadData → ProcessStudent: marks[3]ProcessStudent → ComputeWeightedSum: marks[3], weights[3]ComputeWeightedSum → RoundResult: rawScoreRoundResult → ClassifyGrade: roundedScoreClassifyGrade → OutputResult: gradeRoundResult → UpdateRunningTotal: roundedScore (in‑out modifies totalScore)
7.4 Sketch of the Structure Chart
Note: In an exam you would draw the chart on paper. The text description below shows the hierarchy and arrows.
Main
│
├─ ReadData
│
└─ ProcessStudent
├─ ComputeWeightedSum
├─ RoundResult
├─ ClassifyGrade
├─ UpdateRunningTotal (in‑out)
└─ OutputResult
8. Key Points to Remember
- Each module should have a single, well‑defined purpose.
- Pass only the data that is needed – keep the parameter list as short as possible.
- Use meaningful, consistent names for modules and parameters.
- Prefer parameter passing to global variables; this clarifies scope and aids testing.
- Identify and label in‑out parameters – they are frequently examined in the exam.
- When drawing, keep the hierarchy clear: parent modules above child modules, arrows pointing downwards.
- Validate the chart by checking that every required data item appears exactly once in the flow.
9. Alignment with Cambridge Assessment Objectives
- AO2 – Analyse: Decompose the problem, identify sub‑tasks and required data items.
- AO3 – Design & evaluate: Produce a structure chart, define module interfaces, justify design choices (e.g., avoiding globals, using in‑out where appropriate), and evaluate the design against criteria such as readability and testability.
10. Practice Exercise – Library System
Task: Design a structure chart for a library system that allows a user to search for a book by title, check its availability, and, if available, issue the book to the user. The system must also update the inventory and record the transaction.
Guidelines
- Identify the top‑level module (e.g.,
ProcessLoan). - Break it into logical sub‑modules such as:
SearchBookCheckAvailabilityIssueBookUpdateInventoryRecordTransaction
- For each module, list:
- Purpose
- Input parameters
- Output or in‑out parameters
- Draw the hierarchy (top‑down) and indicate the direction of each arrow.
- Check your design against the “Key Points” checklist and the AO2/AO3 alignment.
Suggested Module Table
| Module | Purpose | Input | Output / In‑out |
|---|
ProcessLoan | Coordinates the whole loan process. | – | – |
SearchBook | Find a book by title. | title (string) | bookID (int) – output |
CheckAvailability | Determine if the identified book is on the shelf. | bookID (int) | available (bool) – output |
IssueBook | Record that the book is loaned to a user. | bookID, userID | – |
UpdateInventory | Decrement the stock count for the book. | bookID | stockCount (int) – in‑out |
RecordTransaction | Write the loan details to the transaction log. | bookID, userID, date | – |
Sample Parameter Flow (simplified)
ProcessLoan
│
├─ SearchBook ──► bookID
│
├─ CheckAvailability ──► available
│
├─ IssueBook (bookID, userID)
│
├─ UpdateInventory (bookID) ──► stockCount (in‑out)
│
└─ RecordTransaction (bookID, userID, date)
11. Quick Checklist for Exam Candidates
- □ Have I identified a clear top‑level module?
- □ Have I decomposed it until each sub‑module is simple enough to code?
- □ Does every arrow represent a parameter, and is the direction correct?
- □ Have I labelled each parameter as input, output or in‑out?
- □ Are all names meaningful and consistent with the naming conventions?
- □ Have I avoided global variables?
- □ Does the chart match the problem description and satisfy AO2/AO3?