2. DESIGN
• The modular design of a software solution can be carried out in three
stages:
• Top level design
• the main steps that the program will carry out
• each of the main steps will become a sub-program
• Data flow
• shows the data that flows IN and OUT of each sub-program
• data IN – will be passed as a parameter from the main program into the sub-
program
• data OUT – will be returned from the sub-program back to the main program
• Refinements
• a break down of each of the main steps from the top level design
3. DESIGN EXAMPLE 1
Design a program that displays the leading driver in the Formula 1
championship. The program should:
• read the driver name and their number of points from a file
• work out the driver with the most points
• display the leading driver, and their number of points
4. TOP LEVEL DESIGN
(STRUCTURE DIAGRAM)
Leading
driver
Read drivers
and points
from file
Work out driver
with most
points
Display
leading driver
and their
points
5. DATA FLOW (STRUCTURE DIAGRAM)
Leading
driver
Read drivers
and points
from file
Work out driver
with most
points
Display
leading driver
and their
points
driver
array
points
array
points
array
position position
driver
array
6. REFINEMENTS (STRUCTURE DIAGRAM)
Leading
driver
Read drivers and
points from file
Work out driver with
most points
Display leading
driver and their
points
Open
drivers
file
Loop for
drivers
Read name
into array
Read
points into
array
Close
drivers
file
Set max
to
points[0]
Loop for
remaining
drivers
Display
driver[position]
Display
points[position
]
points >
max?
set max to
points
store position
7. DESIGN EXAMPLE 2
Design a program that asks the user to enter the temperature for 7 days,
and then calculates the highest and lowest temperatures.
8. TOP LEVEL DESIGN (PSEUDOCODE)
1. Get daily temperatures
2. Calculate highest temperature
3. Calculate lowest temperature
4. Display highest and lowest temperatures
9. DATA FLOW (PSEUDOCODE)
1. Get daily temperatures
• OUT: array of temperatures
2. Calculate highest temperature
• IN: array of temperatures
• OUT: highest temperature
3. Calculate lowest temperature
• IN: array of temperatures
• OUT: lowest temperature
4. Display highest and lowest temperatures
• IN: highest temperature, lowest temperature
10. REFINEMENTS (PSEUDOCODE)
1. Get daily temperatures
1.1 LOOP 7 TIMES
1.2 GET daily temperature FROM KEYBOARD
1.3 STORE daily temperature IN temperatures_array
11. REFINEMENTS (PSEUDOCODE)
2. Calculate highest temperature
1.1 SET highest_temp TO 1st element in temperatures_array
1.2 LOOP WITH counter FROM 2nd array element TO 7th array element
1.3 IF temperatures_array[counter] > highest_temp THEN
1.4 SET highest_temp TO temperatures_array[counter]
1.5 END IF
1.6 END LOOP
12. REFINEMENTS (PSEUDOCODE)
3. Calculate lowest temperature
1.1 SET lowest_temp TO 1st element in temperatures_array
1.2 LOOP WITH counter FROM 2nd array element TO 7th array element
1.3 IF temperatures_array[counter] < lowest_temp THEN
1.4 SET lowest_temp TO temperatures_array[counter]
1.5 END IF
1.6 END LOOP