Chhetri AcademyGCSE & A level Paper Builder

Arrays and records

OCR GCSE Computer Science (J277) · Algorithms and programming (Paper 2) › Programming fundamentals › Additional programming techniques

Practise Arrays and records. 12 exam-style questions plus unlimited generated ones on this subtopic, at up to four difficulty levels, with full mark schemes and a progress tracker. Free, no account needed.

Build a paper on this topic

▶ Watch videos on Arrays and records (Craig 'n' Dave OCR on YouTube) · Practise all of Additional programming techniques

Quick recall

Cover the answers and test yourself. The app has these as flashcards that come back just before you'd forget them.

A program contains this line of code:
colours = ["red", "green", "blue", "yellow"]
State the value of colours[2].
blue
Look at this program.
01 array colours[5]
02 colours[0] = "red"
03 colours[1] = "blue"
04 colours[4] = "green"
05 array gameboard[8, 8]
06 for r = 0 to 7
07    for c = 0 to 7
08       gameboard[r, c] = "-"
09    next c
10 next r
11 gameboard[0, 4] = "K"
State the number of elements in the array colours.
5

Sample questions

Written for this site in the style of OCR exam questions. They are not taken from real past papers.

Question 1Easy4 marks
A program contains this line of code:
colours = ["red", "green", "blue", "yellow"]
(a) State the value of colours[2].[1]
(b) State the index of "red" in the array.[1]
(c) Write a line of code that changes "green" to "purple".[1]
(d) Give one reason why an array is used rather than four separate variables.[1]
Show the answer and mark scheme
(a) Answer: blue
  • blue
(b) Answer: 0
  • 0
(c)
  • colours[1] = "purple"
(d)
  • the items can be processed using a loop
  • one identifier is used for all the related items
  • less code is needed / easier to add more items
Question 2Medium5 marks
This program should output the mean of the temperatures stored in the array temps. Three parts are missing.
01 temps = [12.5, 14.0, 9.5, 11.0, 13.5, 13.0, 10.5]
02 total = 0
03 for i = 0 to ....(1)....
04    total = ....(2)....
05 next i
06 average = ....(3)....
07 print(average)
(a) Write the missing code for each of the gaps (1) to (3).[3]
(b) State the output of the completed program.[1]
(c) Explain why the loop on line 03 must stop at 6 and not at 7.[1]
Show the answer and mark scheme
(a) Answer: (1) 6 or temps.length - 1; (2) total + temps[i]; (3) total / 7 or total / temps.length
  • (1) 6 or temps.length - 1
  • (2) total + temps[i]
  • (3) total / 7 or total / temps.length
(b) Answer: 12
  • 12 (allow 12.0)
(c)
  • the seven items have indexes 0 to 6, so temps[7] does not exist / would be out of range
Question 3Hard7 marks
A 2D array scores holds the scores of 5 students in 4 tests. The first index is the student number (0 to 4) and the second index is the test number (0 to 3).
(a) Write an algorithm that outputs, for each student, the student number and that student's highest score.
You must use either OCR Exam Reference Language or a high-level programming language that you have studied.[6]
(b) Explain why highest must be reset at the start of each student.[1]
Show the answer and mark scheme
(a) Answer:
for s = 0 to 4
   highest = scores[s, 0]
   for t = 1 to 3
      if scores[s, t] > highest then
         highest = scores[s, t]
      endif
   next t
   print(str(s) + ": " + str(highest))
next s
  • outer loop for each student from 0 to 4
  • sets highest to that student's first score (or a very low value) at the start of each student
  • inner loop through the tests
  • compares scores[student, test] with highest
  • updates highest when a larger score is found
  • outputs the student number and highest once for each student, after the inner loop
(b)
  • otherwise a higher score from an earlier student would be carried over and output for the next student

Related subtopics

Stuck? Get 1-to-1 help. Chhetri Academy tutors GCSE and A level Maths and Science online, with a free 30-minute trial lesson.

Book a free trial