Skip to content

9618 · 11.3

Structured Programming — practice questions

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

Worked example 1

A teacher needs a program to find the highest and lowest scores from a class of 25 students. Use stepwise refinement to design an algorithm and represent the first level of refinement.

Show solution outline

The problem is 'Find highest and lowest scores for 25 students'.

Level 0: Process class scores.

Stepwise Refinement (Level 1):

  1. Initialise variables (e.g., HighestScore, LowestScore).
  2. Input and process scores for all 25 students.
  3. Output the final HighestScore and LowestScore.

Further Refinement (Level 2) of Step 1 & 2: 1.1. Input the first score. 1.2. Set HighestScore and LowestScore to this first score. 2.1. Loop 24 times (for the remaining students). 2.2. Inside the loop: Input the next score. 2.3. If the new score is greater than HighestScore, update HighestScore. 2.4. If the new score is less than LowestScore, update LowestScore.

Final Pseudocode:

DECLARE HighestScore, LowestScore, StudentScore : INTEGER

INPUT StudentScore
HighestScore <- StudentScore
LowestScore <- StudentScore

FOR Counter <- 1 TO 24
  INPUT StudentScore
  IF StudentScore > HighestScore THEN
    HighestScore <- StudentScore
  ENDIF
  IF StudentScore < LowestScore THEN
    LowestScore <- StudentScore
  ENDIF
NEXT Counter

PRINT "Highest score is: ", HighestScore
PRINT "Lowest score is: ", LowestScore

Worked example 2

A program needs to calculate the total cost for a number of items. A discount of 10% is applied if the total number of items is 10 or more. Each item costs £2.50. Design a structured pseudocode algorithm that takes the number of items as input and outputs the final cost.

Show solution outline

This problem can be broken down into: get input, calculate base cost, determine if a discount applies, calculate final cost, and output the result.

Pseudocode Solution:

DECLARE NumItems : INTEGER
DECLARE ItemCost, TotalCost : REAL
CONSTANT DiscountRate = 0.10
CONSTANT ItemPrice = 2.50

// Sequence: Get input first
INPUT NumItems

// Sequence: Calculate initial cost
TotalCost <- NumItems * ItemPrice

// Selection: Check for discount condition
IF NumItems >= 10 THEN
  // Sequence: Calculate and apply discount
  TotalCost <- TotalCost - (TotalCost * DiscountRate)
ENDIF

// Sequence: Output the final result
PRINT "The final cost is: £", TotalCost

Marking Points:

  1. Correct declaration of variables.
  2. Correct input of NumItems.
  3. Correct initial calculation of TotalCost.
  4. Correct IF statement (selection) with the right condition (>=10>= 10).
  5. Correct calculation of the discounted cost inside the IF block.
  6. Correct output of the final TotalCost.