PROGRAM DESIGN
Higher Computing Science
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
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
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
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
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
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.
TOP LEVEL DESIGN (PSEUDOCODE)
1. Get daily temperatures
2. Calculate highest temperature
3. Calculate lowest temperature
4. Display highest and lowest temperatures
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
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
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
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
REFINEMENTS (PSEUDOCODE)
4. Display highest and lowest temperatures
1.1 DISPLAY highest_temp
1.2 DISPLAY lowest_temp

Program Design

  • 1.
  • 2.
    DESIGN • The modulardesign 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 Designa 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 (STRUCTUREDIAGRAM) Leading driver Read drivers and points from file Work out driver with most points Display leading driver and their points
  • 5.
    DATA FLOW (STRUCTUREDIAGRAM) 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 Readdrivers 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 Designa 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. Getdaily 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. Calculatehighest 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. Calculatelowest 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
  • 13.
    REFINEMENTS (PSEUDOCODE) 4. Displayhighest and lowest temperatures 1.1 DISPLAY highest_temp 1.2 DISPLAY lowest_temp