Level:
Correct: 0
Incorrect: 0
Marks: 0/0
Exam Practice
Course:
Topics:
OCR GCSE Computer Science (Paper 2) Smart practice A mixed round aimed at your weak spots
Unit 1
Algorithms
Unit 2
Programming fundamentals
Unit 3
Producing robust programs
Unit 4
Boolean logic
Unit 5
Programming languages and IDEs
Unit 6
Practical programming (Section B)
Avg
score:
–
Topics
done:
0/31

One-dimensional and two-dimensional arrays

Practise 32 exam-style questions on One-dimensional and two-dimensional arrays for OCR GCSE Computer Science (Paper 2). Write your answer as you would in the exam and get it marked in seconds against the mark scheme, point by point, with the Study Helper on hand if you get stuck.

  • 32 questions
  • 1–7 marks each
  • Instant marking
  • No sign-up needed
20 questions, marked as you go

Sample questions with model answers

Here are 4 of the questions in this topic, each with a model answer, an explanation of why it earns the marks and the mark scheme an examiner would use.

Question 1

1 mark

A theatre program declares this 2D array to store its seating plan:

array seats[12,20]

State how many elements the array can store.

Model answer

240

Explanation

A 2D array with 12 rows and 20 columns has 12 × 20 = 240 elements, indexed seats[0,0] to seats[11,19]. Adding the sizes, or multiplying the last indexes (11 × 19), are common mistakes.

Mark scheme
  1. 1 mark

    240

    Correct answer only. Do not accept 32 (12 + 20) or 209 (11 × 19).

Question 2

2 marks

A 2D array called grid is shown in the table. The first index is the row and the second index is the column.

State the value of grid[1,2], and give the indexes of the element that holds 0, in the form grid[row,column].

2D array: grid. Table with columns "Row", "Column 0", "Column 1", "Column 2", "Column 3". Row: 0; Column 0: 5; Column 1: 8; Column 2: 2; Column 3: 9 | Row: 1; Column 0: 7; Column 1: 1; Column 2: 6; Column 3: 3 | Row: 2; Column 0: 4; Column 1: 0; Column 2: 8; Column 3: 5.

Model answer

grid[1,2] = 6
The 0 is in grid[2,1].

Explanation

grid[1,2] means row 1, column 2: the second row (7, 1, 6, 3) and its third value, 6. The 0 is in the third row (row 2) and the second column (column 1), so it is grid[2,1]. Always count rows and columns from 0, and give the row first.

Mark scheme
  1. 1 mark

    grid[1,2] is 6

    Do not accept 8 (counted from 1) or 0 (row and column swapped).

  2. 1 mark

    grid[2,1]

    Accept 'row 2, column 1'. Accept grid[2][1]. Do not accept grid[1,2] (swapped) or grid[3,2] (counted from 1).

Question 3

3 marks

This code finds the tallest height in an array.

array heights = [152, 167, 149, 171, 160]
tallest = heights[0]
for i = 1 to 4
    if heights[i] > tallest then
        tallest = heights[i]
    endif
next i
print(tallest)

The trace table shows the value of tallest after each pass of the loop. State the values of P, Q, R, S and T.

Trace table with four columns: i, heights[i], tallest and OUTPUT. Row 1: tallest = 152; i, heights[i] and OUTPUT blank. Row 2: i = 1, heights[i] = 167, tallest is the letter P; OUTPUT blank. Row 3: i = 2, heights[i] = 149, tallest is the letter Q; OUTPUT blank. Row 4: i = 3, heights[i] = 171, tallest is the letter R; OUTPUT blank. Row 5: i = 4, heights[i] = 160, tallest is the letter S; OUTPUT blank. Row 6: OUTPUT is the letter T; i, heights[i] and tallest blank.

Model answer

P = 167
Q = 167
R = 171
S = 171
T = 171

Explanation

tallest starts as heights[0] = 152. When i is 1, 167 > 152, so tallest becomes 167; 149 is not bigger, so it stays 167. When i is 3, 171 > 167, so tallest becomes 171, and 160 does not change it. The loop starts at 1 because element 0 has already been used as the starting value.

Mark scheme
  1. 1 mark

    P = 167 and Q = 167

    For Q, accept 'unchanged' or 'still 167'.

  2. 1 mark

    R = 171 and S = 171

    For S, accept 'unchanged' or 'still 171'.

  3. 1 mark

    T = 171

Question 4

5 marks

Write a program that:
- asks the user to enter 7 temperatures (whole numbers, which may be negative)
- stores them in an array called temps
- outputs the highest temperature.

Write your program using OCR Exam Reference Language or a high-level programming language.

Model answer

array temps[7]
for i = 0 to 6
    temps[i] = int(input("Enter temperature"))
next i
highest = temps[0]
for i = 1 to 6
    if temps[i] > highest then
        highest = temps[i]
    endif
next i
print(highest)

Explanation

input returns a string, so each temperature is cast with int() before being stored. Starting highest at temps[0] works for any data, including all-negative temperatures; starting at 0 would give the wrong answer on a freezing week. For example, inputs 12, 15, 9, 18, 14, 18, 11 output 18, and inputs -3, -1, -7, -2, -5, -4, -6 output -1.

Mark scheme
  1. 1 mark

    declares an array of 7 elements called temps

    Answers must be in OCR Exam Reference Language or a high-level programming language (e.g. Python); pseudocode, natural English or bullet points score 0. Ignore minor syntax errors. Accept a Python list (e.g. temps = [] with append). Max 5.

  2. 1 mark

    uses a loop that repeats 7 times, inputting a value into temps[i] each time

  3. 1 mark

    casts each input to an integer, e.g. int(input(...))

    Accept real() or float().

  4. 1 mark

    initialises the highest value to the first element (temps[0]) or to a very low value

    Initialising it to 0 does not earn this mark: the program would output 0 if every temperature were below 0.

  5. 1 mark

    compares each element with the highest so far and updates it when the element is bigger

    Accept use of a built-in max() function for this mark and the previous one. Award this mark even if the inputs were not cast - missing casting is penalised only at mark point 3.

  6. 1 mark

    outputs the highest value once, after the loop

    Award this mark even if the inputs were not cast - missing casting is penalised only at mark point 3.

Ready to try the rest? Every answer you write is marked against the mark scheme, so you can see exactly where the marks are.

Study Helper Hints first, answers after you try

Stuck on this one? Ask for a hint and I’ll point you in the right direction, without giving the answer away. Once you’ve checked your answer, I’ll show you how the marks are awarded.