Easier to read with cream paper, a tint, more contrast or larger text? Choose your colours and text, once, for every page.

Free lesson

OS 4.1 (1 of 6): Top-down design and data flow

The whole lesson, free. Read it and have a go at the activities. To work the tasks and labs in the real lesson, press Start lab, with no account needed.

40 minutes

A quick check that you are not a bot, then your own lab opens on the interactive lesson.

Already have an account? Sign in

One pizza order, many jobs

You order a pizza on your phone. Many things happen before it arrives.

Someone checks the menu. Someone adds up the cost. Someone tells the kitchen. Someone prints the receipt.

A big system is not one big job. It is many small jobs. Today you learn how to plan them.

Key words

WordWhat it meansExample
Top-down designStarting with the whole system, then splitting it into smaller parts.Pizza app, then Take order
Function-orientated designAnother name for top-down design, which builds a system from functions.
FunctionA small named job in a program. It takes data in and gives data out.order_total()
Sub-systemA smaller part of a bigger system.The kitchen screen
Divide and conquerBreaking a big problem into small ones you solve one by one.
Data flowThe way data moves from one part to the next.
Data flow diagramA picture that shows each job and the data that moves between them.DFD

The cells students fill in are left blank in this preview.

Start at the top

In top-down design you start with one big box: the whole system.

Then you ask: what jobs must it do? Each job becomes a smaller box. Then you split those boxes again. You stop when each box is one simple job.

Each simple job becomes one function in the code.

Check: top-down design

Have a go

Check: top-down design

3 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

The pizza app, split into jobs

flowchart TD
  app[Pizza app] --> take[Take the order]
  app --> price[Work out the cost]
  app --> send[Send to the kitchen]
  app --> receipt[Print the receipt]
  take --> pick[Show the menu]
  take --> check[Check the address]
  price --> food[Add up the food]
  price --> delivery[Add the delivery fee]

Follow the data

A system is not only a list of jobs. Data moves between the jobs.

The order goes from the customer to the cost job. The cost goes to the receipt job. This movement is the data flow.

A data flow diagram (DFD) draws the jobs as boxes and the data as labelled arrows.

A data flow diagram

flowchart LR
  customer([Customer]) -->|list of items| total[1 Add up food]
  menu[(Menu prices)] -->|price of each item| total
  total -->|food total| fee[2 Add delivery fee]
  fee -->|total to pay| receipt[3 Make receipt]
  receipt -->|receipt text| customer

Data flows through functions

Code: python
def add_up(prices):
    return sum(prices)


def add_fee(total):
    return total + 3


prices = [8, 3, 2]
food = add_up(prices)
pay = add_fee(food)
print("Food", food)
print("Pay", pay)

# Each function is one box. The variables are the arrows.
# Change the prices and run again.

Make a free account to save your work and track your progress.

The four parts of a DFD

PartWhat it isExample
External entityA person or system outside your systemCustomer
ProcessA job that changes data. Name it with a verbAdd up food
Data storeWhere data waits until it is neededMenu prices
Data flowAn arrow that carries data. Name it with a nounfood total

The cells students fill in are left blank in this preview.

Two naming rules

Tip

Name each process with a verb: Add, Check, Send. Name each arrow with a noun: order, total, receipt. If an arrow has no name, you do not yet know what data moves.

Match the DFD part

Have a go

Loading…

Your answers are marked here and are not kept. A college account keeps every student’s marks.

Draw a DFD for a canteen

A school canteen has a card system. A student taps a card. The system finds the money on the card, takes off the price of lunch and shows the new balance. Finish the data flow diagram. Add a process for each job. Add a data store for the card balances. Name every arrow with a noun.

flowchart LR
  student([Student]) -->|card number| find[1 Find the balance]
  %% Add a data store for the balances.
  %% Add a process that takes off the price.
  %% Add a process that shows the new balance.
  %% Send the new balance back to the student.

Make a free account to save your work, or press Start lab to work through the whole lesson.

Code the three pizza functions

Build the three functions from the data flow diagram. Food goes in and a total comes out. The total goes into the delivery job. Both numbers go into the receipt job. Press Run Tests.

Code: python
MENU = {"pizza": 8, "chips": 3, "drink": 2}


def order_total(items):
    # items is a list of names, like ["pizza", "chips"].
    # Give back the cost of the whole food order in pounds.
    return None


def delivery_fee(total):
    # An order of 20 pounds or more has free delivery.
    # Under 20 pounds, delivery costs 3 pounds.
    return None


def receipt_line(total, fee):
    # Give back text like: Food 19, delivery 3, pay 22
    return None

Make a free account to save your work, or press Start lab to work through the whole lesson.

Key words crossword

Have a go

Loading…

Your answers are marked here and are not kept. A college account keeps every student’s marks.

Exit quiz

Have a go

Exit quiz

6 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Teach this lesson with your class

On a college account your students work the tasks and the labs as well, and every mark is kept for you.