Skip to content

9618 · 10.2

Arrays — practice questions

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

Worked example 1

A programmer is creating a game and needs to store the high scores of the top 5 players. The scores are whole numbers. Declare a suitable array to store these scores.

Show solution outline
// 1 mark for correct identifier, ARRAY keyword, and data type.
// 1 mark for correct bounds [1:5].

DECLARE HighScores : ARRAY[1:5] OF INTEGER

Explanation:

  • DECLARE HighScores: We give the array a meaningful name.
  • ARRAY[1:5]: We specify it's an array with 5 elements, indexed from 1 to 5. The lower bound is 1 and the upper bound is 5.
  • OF INTEGER: We specify that each element will be a whole number.

Worked example 2

An array, TestScores, has been declared as ARRAY[1:30] OF INTEGER and is filled with student scores. Write pseudocode to find and output the highest score in the array.

Show solution outline
// Declare a variable to hold the highest score found so far
DECLARE HighestScore : INTEGER

// Initialise HighestScore with the first element of the array (1 mark)
HighestScore <- TestScores[1]

// Loop from the second element to the end of the array (1 mark for correct loop)
FOR Index <- 2 TO 30
  // Check if the current element is greater than the highest score found so far (1 mark for comparison)
  IF TestScores[Index] > HighestScore THEN
    // If it is, update HighestScore (1 mark for correct assignment)
    HighestScore <- TestScores[Index]
  ENDIF
NEXT Index

// Output the final result (1 mark)
OUTPUT "The highest score is: ", HighestScore