AQA 7517, section 4.1.2.2
The structured approach is a way of designing and writing procedural programs so that they are clear, logical and easy to maintain. Instead of writing one long block of code, the problem is divided into smaller parts, each of which is a subroutine.
Features of the structured approach
- A program is built only from sequence, selection and iteration, with no jumping around the code.
- The problem is broken into smaller subroutines, each with one clear job.
- Each subroutine has a defined interface (its parameters and return value) and uses local variables.
- Design works top-down: start with the whole problem, then keep dividing it into smaller sub-problems until each is simple enough to code directly. This is called stepwise refinement.
- The program is modular, so each module can be written, tested and fixed separately.
Hierarchy charts
A hierarchy chart (also called a structure chart) is a diagram that shows how a program is divided into subroutines. The top box is the main program, and each level beneath it shows the subroutines it calls.
How to read it:
- The top box is the whole task.
- Each box below shows a smaller task that its parent needs.
- A box with nothing below is simple enough to write as one subroutine.
- It shows which subroutines exist and how they relate, but not the order they run in or the detail of how they work.
To construct a hierarchy chart, start with the overall task at the top, then list the main steps beneath it, then divide any step that is still too complicated into smaller ones.
Worked example
Task: design a program that lets a user enter their test marks and see their average and grade.
Top-down design:
- Main task: Process marks.
- Break it down: Get marks, Calculate average, Work out grade, Display result.
- Get marks is complicated, so it divides again into Read one mark and Check mark is valid.
The hierarchy chart:
Each box then becomes a subroutine:
def get_marks(): ...
def calculate_average(marks): ...
def work_out_grade(avg): ...
def display_result(avg, grade): ...
The main program calls them in order. Because each one is separate, a different team member could write each, and each can be tested alone.
Advantages of the structured approach
- Easier to understand. The program is split into small named parts.
- Easier to design. A big problem is broken into manageable pieces.
- Easier to test and debug. Each subroutine can be checked on its own, and a fault can be traced to one part.
- Easier to maintain. A change usually affects only one subroutine.
- Supports teamwork. Different programmers can write different modules at the same time.
- Reusable code. A well-written subroutine can be used again elsewhere.
Exam tip: for "explain the advantages of the structured approach", give two or three advantages and link each to a reason, such as "each subroutine can be tested separately, so errors are easier to find and fix".
Check yourself
What is meant by top-down design?
Starting with the whole problem and repeatedly breaking it into smaller sub-problems until each can be written as a simple subroutine.
What does a hierarchy chart show?
How a program is divided into subroutines, and how those subroutines are related: which ones are called by which. It doesn't show the order of execution or how each one works.
Give two advantages of the structured approach
Any two of: easier to understand; easier to design; easier to test and debug; easier to maintain; allows teamwork; subroutines can be reused.