Question bank › GCSE › GCSE Computer Science › Programming

Data structures: 1D/2D arrays & records

10 questions45 marksabout 55 min

Answer on paper first, then reveal the mark scheme one mark at a time.

1Grade 6–76 marks

A library stores data about books using this record structure.

RECORD Book
   title : String
   year : Integer
   onLoan : Boolean
ENDRECORD

(a) Write AQA pseudocode to create a variable b1 holding a Book record for Holes, published in 1998, which is currently on loan. [2]

(b) The array library contains many Book records. Write an algorithm, using AQA pseudocode, that outputs the title of every book that was published before 2000 and is not on loan. [4]

2Grade 1–33 marks

A weather station records the temperature at midday every day for a week. The seven values are stored in a one-dimensional array called temps.

(a) Describe what is meant by an array. [2]

(b) State one advantage of storing the seven temperatures in an array rather than in seven separate variables. [1]

3Grade 1–34 marks

A quiz program stores the scores of five contestants in the array scores.

scores ← [14, 9, 17, 12, 20]

In AQA pseudocode, the first element of an array has index 0.

(a) State the value of scores[2]. [1]

(b) State the value returned by LEN(scores). [1]

(c) State the output of the following line. [1]

OUTPUT scores[1] + scores[4]

(d) Explain why the statement OUTPUT scores[5] would cause an error. [1]

Stuck on Data structures: 1D/2D arrays & records?

Get it sorted in a free 30-minute session

We work through your weakest questions on this topic on Zoom. I reply the same day.

4Grade 4–54 marks

A vending machine has 3 shelves, each with 4 slots. The number of items left in each slot is stored in a two-dimensional array called stock, shown in the diagram. The array is accessed as stock[row][column], with both indexes starting at 0.

(a) State the value of stock[1][2]. [1]

(b) State the total number of elements in the array stock. [1]

(c) Write one line of AQA pseudocode that records that the slot on the bottom shelf, far-left, now contains 6 items. [1]

(d) The slot at row 0, column 1 is empty. State the number of empty slots in the whole machine. [1]

column index0123row index012201000311200stock[row][column]
5Grade 4–54 marks

The array rain holds the rainfall, in mm, for each of seven days.

rain ← [3, 0, 12, 7, 0, 5, 2]
total ← 0
wet ← 0
FOR i ← 0 TO 6
   IF rain[i] > 0 THEN
      wet ← wet + 1
      total ← total + rain[i]
   ENDIF
ENDFOR
OUTPUT total
OUTPUT wet

(a) State the two values that are output when the algorithm is run. [2]

(b) Describe the purpose of the variable wet. [1]

(c) The programmer changes the loop to FOR i ← 0 TO LEN(rain) - 1. Explain why this is an improvement. [1]

6Grade 4–54 marks

A vet's surgery stores the following data about each animal: its name, its age in years, its weight in kg and whether it has been vaccinated.

(a) Explain why a record is more suitable than an array for storing the data about one animal. [2]

(b) Complete the record definition below by giving a suitable data type for each of the fields age and vaccinated. [2]

RECORD Animal
   name : String
   age : ...........
   weight : Real
   vaccinated : ...........
ENDRECORD
7Grade 6–75 marks

The array temps stores the highest temperature, in °C, recorded on each day of a six-day holiday.

temps ← [18, 23, 21, 27, 19, 27]

(a) Write an algorithm, using AQA pseudocode, that finds the highest temperature in the array and outputs it together with the index of the day on which it was first reached. For the array above the output should be 27 and 3. [4]

(b) State why your algorithm must initialise the highest value to temps[0] (or a very low number) rather than to 0. [1]

8Grade 6–75 marks

A cinema stores whether each seat is booked in a two-dimensional array seats. Each element is True if the seat is booked and False if it is free. The screen has 8 rows of 12 seats, accessed as seats[row][col] with indexes starting at 0.

(a) Write an algorithm, using AQA pseudocode, that counts the number of free seats and outputs the count. [4]

(b) State the number of times the inner loop body is executed in your algorithm. [1]

9Grade 6–74 marks

The two-dimensional array marks stores the marks of three students in three tests. Each row is one student.

marks ← [[6, 8, 7],
         [9, 4, 10],
         [5, 5, 5]]
FOR r ← 0 TO 2
   t ← 0
   FOR c ← 0 TO 2
      t ← t + marks[r][c]
   ENDFOR
   OUTPUT t
ENDFOR

(a) State the three values output by the algorithm. [2]

(b) The programmer moves the line t ← 0 so that it comes before the outer FOR loop. State the three values that would now be output. [1]

(c) The programmer wants the algorithm to output the total for each test instead of each student. State the change needed to the line t ← t + marks[r][c]. [1]

10Grade 8–96 marks

A running club stores the results of a race in the array results. Each element is a Runner record.

RECORD Runner
   name : String
   time : Integer      // seconds
   junior : Boolean
ENDRECORD

The array can hold any number of runners. Write an algorithm, using AQA pseudocode, that:

  • calculates the mean time of all the runners
  • outputs the name of every junior runner whose time is faster than (less than) the mean.

Your algorithm should work for an array of any length. [6]

Stuck on this topic?

Book a free 30-minute session on WhatsApp and we'll find exactly which step is costing you the marks. Or build a timed paper on it.

Free 30-minute session