Sub-systems and Decomposition
Splitting a system into sub-systems, finding its inputs, processes, outputs and storage, and designing a solution with structure diagrams, flowcharts and pseudocode.
WATCH IT EXPLAINED
EXPLORE IT IN 3D
Design the canteen
A school canteen and its ordering system: a kiosk, a card reader, a receipt printer. Take the system apart, then design it with flowcharts you can run, while a glowing token follows every arrow.
Every system is made of sub-systems
Split a system into smaller and smaller parts until each part is one small job.
A computer system is made up of sub-systems (smaller parts). Each sub-system is made up of even smaller sub-systems. You keep splitting until every part is one small job that can be written on its own.
A structure diagram shows this as a tree:
- The whole system is the box at the top.
- The parts it is made of sit underneath it.
- Each box at the bottom can then be written as one procedure or function.
Watch out:A structure diagram shows what the parts are. It does not show the order they run in.
Inputs, processes, outputs and storage
Before designing, list the inputs, processes, outputs and storage of the problem.
Every problem can be broken down into four kinds of part.
| Part | What it is |
|---|---|
| Inputs | the data the system needs from outside |
| Processes | the calculations and decisions made on that data |
| Outputs | the results it gives back |
| Storage | the data it must keep |
Storage can be in two places:
- in variables and arrays, while the program runs;
- in a file, so that the data lasts after the program stops.
Remember:List the four parts before you design anything. They tell you which variables you will need.
Problem: work out a bus fare
INPUT : the passenger's Age and the
number of Stops
PROCESS: Fare ← Stops * 500
if Age < 12,
Fare ← DIV(Fare, 2)
OUTPUT : the fare, in tugrik
STORAGE: DayTotal, the money taken
so far todayThree ways to design a solution
Structure diagrams, flowcharts and pseudocode each show a different side of a design.
The syllabus names three methods for designing a solution.
| Method | What it shows |
|---|---|
| Structure diagram | the parts of a system and how they break down |
| Flowchart | the order of the steps, and where a decision makes the path branch |
| Pseudocode | the steps as statements that are almost a program |
A full design often uses all three. First a structure diagram for the whole system. Then a flowchart or pseudocode for each part.
The code below is the quiz's box "Check it is 2 to 12", written in pseudocode.
INPUT Table WHILE Table < 2 OR Table > 12 DO OUTPUT "Choose 2 to 12" INPUT Table ENDWHILE
The six flowchart symbols
A flowchart uses six standard symbols, and a wrong shape can lose the mark.
| Symbol | Shape | What it holds or does |
|---|---|---|
| Terminator | a box with rounded ends | Start and Stop |
| Input/output | a parallelogram | an INPUT or an OUTPUT |
| Process | a rectangle | a calculation or an assignment |
| Decision | a diamond | a question |
| Subroutine symbol | a rectangle with a double line at each side | calls a separate flowchart |
| Flow line | an arrow | shows where control goes next |
Exam:A decision has exactly two exits, labelled Yes and No (or True and False).
Reading a flowchart: follow the token
Read a flowchart like a board game: move a token from START along the arrows.
- Start at START.
- Follow the arrows, and do what each box says.
- At a diamond, answer its question with the values the variables hold now. Take that exit.
An arrow that goes back up to an earlier box is a loop. The boxes inside it run again until the decision sends you another way.
Example:With the inputs 15, 1 and 7, the token goes round the loop twice before 7 is accepted. Change the INPUT values to 7 on its own, and the loop body never runs.
From flowchart to pseudocode
Turn a flowchart into pseudocode by writing one statement for each box, from the top down.
Each symbol becomes one kind of statement.
| Flowchart box | Pseudocode |
|---|---|
| input/output box | INPUT or OUTPUT |
| process box | an assignment |
| subroutine box that runs a procedure | CALL |
| decision, both arrows carry on down the page | IF |
| decision, one arrow goes back up | a loop |
Work down the chart and write one statement for each box.
The code below does the same job with a FOR loop. FOR gives Count each value from 1 to 5 by itself. Both print five lines, from 1 x 7 = 7 to 5 x 7 = 35.
INPUT Table FOR Count ← 1 TO 5 OUTPUT Count, " x ", Table, " = ", Count * Table NEXT Count
A subroutine is its own flowchart
A long or repeated job can get its own flowchart, which the main flowchart calls.
A job that is used more than once, or is long, can be drawn as a separate flowchart.
- The main chart calls it with the subroutine symbol. That symbol holds only the subroutine's name.
- MarkAnswer is a procedure, so in pseudocode that box is
CALL MarkAnswer. - The separate chart starts with a terminator holding the name MarkAnswer.
- It ends with
RETURN: back to the box that called it.
Watch out:The syllabus does not say what these two terminators must hold. This lesson writes them this way.
With the answers 7, 15 and 21, the score is 2 out of 3.
Explaining what an algorithm is for
The purpose says what an algorithm achieves; the processes say what happens, in order.
Two exam questions sound alike but ask for different things.
- State the purpose: say in one sentence what the algorithm achieves, in the words of the problem. It does not mean retelling the steps.
- Describe the processes: say what happens, in order: what is input, what is repeated, what is decided and what is output.
To find the purpose:
- Run the algorithm with a few small inputs.
- Look at what comes out.
- Say what it is for.
The model answer below does both for this flowchart.
Purpose: to let a user try up to three
times to enter the correct PIN,
outputting Welcome if it is right and
Locked after three wrong tries.
Processes: Tries starts at 0. The loop
outputs "Enter PIN", inputs Pin and
adds 1 to Tries, until Pin is 4821 or
Tries is 3. Then, if Pin is 4821, it
outputs Welcome; otherwise, Locked.Drawing a flowchart in the exam
Examiners mark a flowchart's shapes, arrows and labels, not only its logic.
Look at the 0478 Paper 22 mark scheme for October/November 2024. One mark needed a fully correct chart: every arrow, the Yes and No labels and the right symbols.
Before you hand in a flowchart, check for:
- one START and one STOP terminator;
- an arrowhead on every flow line;
- both exits of every decision labelled Yes and No;
- one statement in each box;
- every loop drawn as an arrow going back up;
- the six standard shapes, and nothing else.
Exam:Write each decision as a precise condition, such as Count > 10?, never as words such as "is it big?". The syllabus wants this in every algorithm: x > y is acceptable, but "x is greater than y" is not.
Total ← 0
FOR Count ← 1 TO N
Total ← Total + Count
NEXT Count
OUTPUT TotalSTARTN = 5
| Count | Total | OUTPUT |
|---|---|---|
One row per pass through the loop. Leave a cell blank if it does not change on that pass.
KEY TERMS
CHECK YOURSELF
1.Which flowchart shape is used for a decision?
2.Decomposing a problem means splitting it into which four parts?
3.What does the subroutine symbol in a flowchart stand for?
4.A loop's decision is drawn at the bottom, after the boxes it repeats. Which pseudocode loop is it?
5.What does a structure diagram show?