Information Technology Topic

Top-Down Design and Stepwise Refinement

  1. Read notes
  2. Flashcards
  3. Quiz
  4. Confident

Study focus - 3 things

  1. Top-down design starts with the whole problem, splits it into a few main tasks, and then splits each task again until every step is simple enough to write as one statement
  2. Stepwise refinement means adding detail one level at a time, so each pass turns a short description of a task into a more exact set of steps, ending in pseudocode
  3. A hierarchy chart shows the tasks and subtasks as boxes, with the whole problem at the top; check the design by testing each task and making sure the order of tasks lets each one use the values it needs

Visual notes

Hierarchy chart for the marks report
A hierarchy chart. At the top is one box, Produce the marks report. Below it, joined by lines, are four task boxes in a row: 1 Get the marks, 2 Total and average, 3 Highest and lowest, and 4 Display the results. Under task 2 are two smaller boxes, 2.1 Total and 2.2 Average. Under task 3 are two smaller boxes, 3.1 Highest and 3.2 Lowest. Tasks 1 and 4 have no boxes below them. There are nine boxes in all on three levels.

The whole problem is at the top. Each level splits a box into smaller tasks, and the boxes with nothing below them are the steps ready to write as pseudocode.

Section 1Breaking a big problem into tasks

A problem with two or more jobs in it is hard to write in one go. Imagine trying to organise a school sports day by starting with the first sprint and working out every detail in order. You would soon lose track. Top-down design starts at the top instead. First say what the whole job is. Then split it into a few main tasks. Then split each task into smaller tasks, and keep splitting until each part is easy. The word 'top-down' means you start with the big picture and work down into detail.

Section 2Stepwise refinement: one level at a time

Stepwise refinement is the working method. At each step you take the tasks you have and add detail to them. 'Refine' means to make more exact. Level 1 names the main tasks in plain words. Level 2 turns each task into steps. If a step is still too big, it gets a further level. You stop when every step can be written as one simple statement: Read, Store, Display, If-then or a loop. Here's the trick: ask of every task, 'Could I write this as one or two lines of pseudocode?' If not, split it again.

Section 3A small example: the tuck shop

Problem: a tuck shop in Portmore wants a program that reads the price of an item, the number bought and the money given, then displays the cost and the change. Level 1, the main tasks: 1 Get the data 2 Work out the cost 3 Work out the change 4 Display the answers Level 2, each task as steps: 1 Get the data: Read price, Read qty, Read paid 2 Work out the cost: Store price * qty in cost 3 Work out the change: Store paid - cost in change 4 Display the answers: Display cost, Display change Join the steps in order and you have the finished pseudocode: Read price Read qty Read paid Store price * qty in cost Store paid - cost in change Display cost Display change The order matters. Task 3 uses cost, so task 2 must come first. Task 4 uses both cost and change, so it comes last.

Section 4The hierarchy chart

A hierarchy chart draws the tasks as boxes. The whole problem is the box at the top. Lines join it to the main tasks below, and each task joins to its own subtasks. The numbers show who belongs to whom: 2.1 and 2.2 are parts of task 2. The chart shown with this topic is for a program that reads three marks and displays the total, average, highest and lowest. It has nine boxes on three levels. The boxes with nothing below them (1, 2.1, 2.2, 3.1, 3.2 and 4) are the steps that are ready to be written as pseudocode. The chart shows how the problem is split up. It does not show the detail of each step or the order in which the statements run, so you still write the pseudocode.

Section 5Refining the marks report

Problem: a school in Mandeville wants a program that reads three marks and displays the total, the average, the highest and the lowest. Level 1: 1 Get the marks. 2 Total and average. 3 Highest and lowest. 4 Display the results. Level 2: task 1 is Read a, Read b, Read c. Task 2 splits into 2.1 (store a + b + c in total) and 2.2 (store total / 3 in average). Task 3 splits into 3.1 (find the highest) and 3.2 (find the lowest), each using the start-from-the-first-value method with an If block for each other mark. Task 4 is four Display statements. Put the steps together and the whole program is: Read a Read b Read c Store a + b + c in total Store total / 3 in average Store a in max Store a in min If b > max then Store b in max End If If c > max then Store c in max End If If b < min then Store b in min End If If c < min then Store c in min End If Display total Display average Display max Display min There is no nesting: the four If blocks follow one another. Because each task is a separate chunk, you can read the program task by task.

Section 6Checking a top-down design

Check three things. First, does every task do one job? A task such as 'work out everything' is too big and should be split. Second, is the order right? A task can only use values that earlier tasks have already worked out. Third, can each lowest-level step be written as one simple statement? If the order is wrong, the program fails. Put Display cost before the line that works out cost and the program stops, because cost has no value yet. Because the tasks are separate, you can test each one by itself with test data, then test them all together. A team can share the tasks too, with one student writing task 2 while another writes task 3.

Examples

A tuck shop in Portmore needs a program that reads the price of one item, the number bought and the money given, then displays the cost and the change. (a) List the main tasks (level 1). (b) Refine each task into pseudocode. (c) State what the program displays for a price of 150, a quantity of 3 and money given of 500.

(a) Level 1: 1 Get the data. 2 Work out the cost. 3 Work out the change. 4 Display the answers. (b) Refined: task 1 is Read price, Read qty, Read paid. Task 2 is Store price * qty in cost. Task 3 is Store paid - cost in change. Task 4 is Display cost and Display change. In order, that gives: Read price Read qty Read paid Store price * qty in cost Store paid - cost in change Display cost Display change (c) Cost is 150 x 3 = 450. Change is 500 - 450 = 50. The program displays 450 and then 50. The order matters: task 3 needs cost, so it must come after task 2.

A school in Mandeville wants a program that reads three marks and displays the total, the average, the highest and the lowest. The hierarchy chart for the design is shown with this topic. (a) Describe the chart: how many boxes it has, how many tasks are on level 1, and which tasks are split again. (b) Write the refined pseudocode. (c) State what the program displays for the marks 60, 48 and 72.

(a) The chart has 9 boxes on 3 levels: the whole problem at the top, 4 tasks on level 1, and 4 subtasks on level 2. Task 2 splits into 2.1 Total and 2.2 Average. Task 3 splits into 3.1 Highest and 3.2 Lowest. Tasks 1 and 4 are not split. (b) Task 1 gives three Read lines. Task 2 gives the total and then the average (total first, because the average uses it). Task 3 starts max and min at the first mark, then uses one If block for each other mark and each extreme. Task 4 gives four Display lines: Read a Read b Read c Store a + b + c in total Store total / 3 in average Store a in max Store a in min If b > max then Store b in max End If If c > max then Store c in max End If If b < min then Store b in min End If If c < min then Store c in min End If Display total Display average Display max Display min (c) Total = 60 + 48 + 72 = 180. Average = 180 / 3 = 60. Highest = 72. Lowest = 48. The program displays 180, 60, 72 and 48, in that order.

Now let's water it

Session runs notes to flashcards to quiz back-to-back.

Where this comes from