Skip to the page
Year 10 · Computer Science · Spring 2 · Algorithm design and problem solving

Flowcharts and Cambridge pseudocode

PracticalPresent ▶

What this lesson covers

7.2 Systems, decomposition and design tools

Cambridge IGCSE Computer Science 0478 · Topic 7: Algorithm design and problem-solving · Paper 2

7.3 The purpose of an algorithm

Cambridge IGCSE Computer Science 0478 · Topic 7: Algorithm design and problem-solving · Paper 2

You will learn to

  • Identify the standard flowchart symbols and what each one is for.
  • Read and write simple Cambridge pseudocode, using ← for assignment.
  • Convert an algorithm from a flowchart to pseudocode, and back.
  • State the purpose of a given algorithm in one clear sentence.

Success criteria

  • I can draw and name each flowchart symbol.
  • I can turn a short flowchart into correct pseudocode.
  • I can say what an algorithm does after reading it once.
The syllabus points for these sections
  • Explain that a computer system is made of sub-systems.
  • Decompose a problem into inputs, processes, outputs and storage.
  • Draw and read a structure diagram.
  • Draw and read flowcharts using the six standard symbols.
  • Read and write simple Cambridge pseudocode.
  • State the purpose of a given algorithm in one clear sentence.
  • Describe the processes an algorithm carries out, in order.
  • Use the variable names and values in the algorithm to support your answer.

Key words

Say each word, then read what it means. Every one is in the glossary too.

Algorithm
A precise, ordered set of steps that solves a problem.
Program development life cycle
The four stages of making a program: analysis, design, coding and testing.
Decomposition
Breaking a problem into smaller parts that are easier to solve.
Sub-system
A smaller part of a system that does one job.
Structure diagram
A top-down diagram that shows how a system is split into sub-systems.
Flowchart
A diagram of an algorithm using standard shapes joined by flow lines.
Pseudocode
A structured, code-like way of writing an algorithm that is not tied to one language.
Check digit
An extra digit calculated from the other digits, used to catch typing errors.

The explanation

Read it here, or open the study page below to go one step at a time with things to try.

7.2 Systems, decomposition and design tools

Sub-systems, and inputs, processes, outputs and storage

A system is a set of parts that work together to do a job. Each part is a sub-system. A sub-system can be split again until each part is small enough to code easily.

Example: a supermarket self-checkout is a system. Scanning, weighing, payment and printing the receipt are its sub-systems.

Every problem can also be decomposed into four parts.

Inputs: the data going in. Processes: what is done to the data. Outputs: the results that come out. Storage: data that must be kept for later.

PartSupermarket self-checkout
InputsBarcode of each item, weight, payment card
ProcessesLook up the price, add to the running total, check the weight
OutputsItem name and price on screen, total, receipt
StorageProduct file of barcodes and prices, record of the sale
?Why?

Small parts are easier to write, test and fix. Different programmers can work on different sub-systems at the same time.

!Watch out

Do not put the same thing in two places. 'Total' is calculated (process) and then shown (output). Say which one you mean.

Structure diagrams

A structure diagram shows how a system is broken down into sub-systems. The whole system is in the top box.

Each level below shows smaller parts. Read it top to bottom. Boxes on one level are usually read from left to right.

It shows what the parts are, not the order of every step or the decisions.

?Why?

A structure diagram is a picture of decomposition. It helps a team share out the work: one person can code 'Take payment' while another codes 'Update card'.

There is a diagram for this step in the IGCSE library.

Flowcharts: the six symbols

A flowchart shows the steps of an algorithm as shapes joined by arrows. Each shape has one meaning.

Follow the flow lines from START to STOP. A decision diamond has two exits, labelled Yes and No.

A loop is drawn as a flow line that goes back up to an earlier step.

e.g.Example
Flowchart to count passes in 6 marks: START (terminator) → Count ← 0, Index ← 1 (process) → INPUT Mark (input/output) → Mark >= 25? (decision) Yes → Count ← Count + 1 (process); No → go on → Index ← Index + 1 (process) → Index > 6? (decision) No → back up to INPUT Mark; Yes → go on → OUTPUT Count (input/output) → STOP (terminator)
!Watch out

Use the right shape. INPUT and OUTPUT go in a parallelogram, not a rectangle. Every decision diamond needs two labelled exits.

There is a diagram for this step in the IGCSE library.

Pseudocode: Cambridge's planning language

Pseudocode is a way of writing an algorithm that looks like code but is not tied to one language.

Cambridge has its own rules. Keywords are in CAPITALS. Assignment uses `←`. Comments start with `//`. Not equal is `<>`.

Paper 2 answers must be in pseudocode. Program code only earns marks in the 15-mark scenario question.

JobCambridge pseudocode
Make a variable`DECLARE Total : INTEGER`
Store a value`Total ← 0`
Input and output`INPUT Mark` and `OUTPUT "Total: ", Total`
Array of 30 items`DECLARE Marks : ARRAY[1:30] OF INTEGER`
Selection`IF … THEN … ELSE … ENDIF`
Count-controlled loop`FOR Index ← 1 TO 10` … `NEXT Index`
Pre-condition loop`WHILE … DO` … `ENDWHILE`
Post-condition loop`REPEAT` … `UNTIL …`
DECLARE Mark : INTEGER
OUTPUT "Enter your mark: "
INPUT Mark
IF Mark >= 25
  THEN
    OUTPUT "Pass"
  ELSE
    OUTPUT "Fail"
ENDIF
mark = int(input("Enter your mark: "))
if mark >= 25:
    print("Pass")
else:
    print("Fail")
?Why?

Pseudocode lets you think about the logic without worrying about the exact rules of Python. An examiner can read it whatever language you learned.

7.3 The purpose of an algorithm

Stating the purpose

The purpose of an algorithm is the job it does overall. It is the reason the algorithm exists.

To find it, look at the inputs, then look at what is output at the end. The purpose links the two.

Write one sentence: 'The algorithm inputs … and outputs …'.

e.g.Example
Purpose: the algorithm lets a user enter a bank card PIN up to three times. It outputs 'Card unlocked' if the PIN is correct, or 'Card blocked' after three wrong attempts. Test: 1111 then 4821 → Card unlocked (2 attempts). Test: 1111, 2222, 3333 → Card blocked.
CONSTANT CorrectPin ← "4821"
DECLARE Guess : STRING
DECLARE Attempts : INTEGER
Attempts ← 0
REPEAT
  OUTPUT "Enter your PIN: "
  INPUT Guess
  Attempts ← Attempts + 1
UNTIL Guess = CorrectPin OR Attempts = 3
IF Guess = CorrectPin
  THEN
    OUTPUT "Card unlocked"
  ELSE
    OUTPUT "Card blocked"
ENDIF
CORRECT_PIN = "4821"
attempts = 0
guess = ""
# Python has no REPEAT ... UNTIL, so the loop condition is reversed
while guess != CORRECT_PIN and attempts < 3:
    guess = input("Enter your PIN: ")
    attempts = attempts + 1
if guess == CORRECT_PIN:
    print("Card unlocked")
else:
    print("Card blocked")
!Watch out

Do not translate each line into English ('it sets Total to 0, then it starts a loop…'). That describes the code but does not state the purpose.

Describing the processes

Sometimes a question asks you to describe the processes. Now you do go through the steps, but in plain words and in order.

Mention the loop, what is checked, and what is changed or output. Use the identifiers from the algorithm.

e.g.Example
Describe the processes (4 marks): 1. Attempts is set to 0. 2. The user is asked to input a PIN, and Attempts goes up by 1. 3. This repeats until the PIN matches CorrectPin or 3 attempts have been made. 4. If the last guess matches, 'Card unlocked' is output. Otherwise 'Card blocked' is output.
?Why?

'State' wants a short answer. 'Describe' wants the steps. Reading the command word tells you how much to write.

Study it

Open the study page and go one step at a time.

Check yourself

One question at a time. The reason shows after each answer.

Saved on this device.