Skip to content

9618 · 12.2

Program Design — practice questions

Practice and worked examples for 9618 Program Design. Short previews only — attempt the full question in MarkScheme against the official scheme.

Worked example 1

A simple payroll program needs to get an employee's hours worked and rate of pay, calculate the gross pay, and display the result.

  1. Design a structure diagram for this program.
  2. Using your design, show the calculation for an employee who worked 37.5 hours at a rate of $20.00 per hour.
Show solution outline

1. Design (Structure Diagram) The design process follows top-down decomposition:

  • Top Level: The main module is 'Process Payroll'.
  • First Breakdown: 'Process Payroll' is broken into three main steps: GetData, CalculateGrossPay, and DisplayGrossPay.
  • Second Breakdown: The GetData module is refined into GetHoursWorked and GetRateOfPay.

This results in a structure diagram with 'Process Payroll' at the top, calling 'GetData', 'CalculateGrossPay', and 'DisplayGrossPay'. 'GetData' in turn calls 'GetHoursWorked' and 'GetRateOfPay'.

2. Worked Calculation Let's trace the process with sample data. Assume the user inputs the following values:

  • Hours Worked = 37.5 hours
  • Rate of Pay = $20.00 per hour

Step 1: Get Data

  • The GetHoursWorked module gets the value 37.5.
  • The GetRateOfPay module gets the value 20.00.

Step 2: Calculate Gross Pay

  • The CalculateGrossPay module receives these two values.
  • Formula: Gross Pay = Hours Worked × Rate of Pay
  • Calculation: GrossPay=37.520.00Gross Pay = 37.5 * 20.00
  • Result: GrossPay=750.00Gross Pay = 750.00

Step 3: Display Gross Pay

  • The DisplayGrossPay module receives the calculated gross pay.
  • Output: The program displays a message like "Gross Pay: $750.00".

Worked example 2

A program is required to analyse a set of student exam scores. The program must read a list of scores from a file, calculate the average, find the highest and lowest scores, and display the results.

  1. Design a structure diagram for this system.
  2. Show the calculated results for the following list of scores: [85, 72, 94, 68, 72, 88, 94, 79].
Show solution outline

1. Design (Structure Diagram) The top-down design is as follows:

  • Top Level: AnalyseStudentScores
  • First Breakdown: ReadScoresFromFile, ProcessScores, DisplayResults
  • Second Breakdown: The ProcessScores module calls three sub-modules: CalculateAverage, FindHighestScore, FindLowestScore.

This structure diagram shows AnalyseStudentScores at the root, calling the three main modules on the second level. The ProcessScores module then calls the three calculation modules on the third level.

2. Worked Calculation Assume the file scores.txt contains the following integer scores: [85, 72, 94, 68, 72, 88, 94, 79]

Step 1: Read Scores

  • The ReadScoresFromFile module reads the data into an array: Scores=[85,72,94,68,72,88,94,79]Scores = [85, 72, 94, 68, 72, 88, 94, 79]

Step 2: Process Scores This step involves calling the three calculation functions.

  • (a) Calculate Average:
    • Formula: Average = Sum of Scores / Number of Scores
    • Sum: 85+72+94+68+72+88+94+79=65285 + 72 + 94 + 68 + 72 + 88 + 94 + 79 = 652
    • Count: There are 8 scores.
    • Calculation: Average=652/8Average = 652 / 8
    • Result: Average=81.5Average = 81.5
  • (b) Find Highest Score:
    • The module iterates through the array [85, 72, 94, 68, 72, 88, 94, 79].
    • It keeps track of the maximum value found so far.
    • Result: HighestScore=94Highest Score = 94
  • (c) Find Lowest Score:
    • The module iterates through the array [85, 72, 94, 68, 72, 88, 94, 79].
    • It keeps track of the minimum value found so far.
    • Result: LowestScore=68Lowest Score = 68

Step 3: Display Results

  • The DisplayResults module receives the three calculated values.
  • Output:
    • Average Score: 81.5
    • Highest Score: 94
    • Lowest Score: 68