Question bank › GCSE › GCSE Computer Science › Programming fundamentals

Arrays, records and SQL

10 questions49 marksabout 60 min

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

1Grade 6–76 marks

A weather station records 10 temperatures each day.

Write a program that:

• asks the user to enter 10 temperatures and stores them in an array

• calculates and outputs the mean temperature

• outputs how many temperatures are above 20.

Use OCR Exam Reference Language or a high-level programming language. [6]

2Grade 4–54 marks

A database table called Pupils is shown.

PupilIDFirstNameSurnameYearPoints
1AmirKhan1064
2BellaHughes1145
3ChenLi1038
4DaraOkafor1172
5EllaPatel1055

(a) Write an SQL statement to display the FirstName and Points of every pupil in Year 11. [3]

(b) State the output of this SQL statement:

SELECT Surname FROM Pupils WHERE Year = 10 AND Points > 50

[1]

3Grade 6–76 marks

A 2D array marks stores test marks for 3 students (rows 0–2) in 4 tests (columns 0–3). marks[student, test] is used to access a value.

Test 0Test 1Test 2Test 3
Student 01215918
Student 17142011
Student 216101319

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

(b) Write code that calculates and outputs the total mark for each student. Use OCR Exam Reference Language or a high-level programming language. [5]

Stuck on Arrays, records and SQL?

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 1–34 marks

A game stores the eight highest scores achieved by a player.

(a) Write a line of code to declare a 1D array called scores that can hold 8 integers. Use OCR Exam Reference Language or a high-level programming language. [1]

(b) State the index of the last element in the array scores. [1]

(c) Explain why an array is described as a static data structure. [2]

5Grade 4–53 marks

A hardware shop stores the following details about each product:

  • product code (string)
  • price (real)
  • whether it is in stock (Boolean)

(a) Explain why a record is more suitable than a 1D array for storing the details of one product. [2]

(b) A record called item has the fields code, price and inStock.

Write a line of code that outputs the price of item. [1]

6Grade 4–56 marks

An airline stores flight details in a database table called Flights.

FlightNoDestinationDepartsSeatsPrice
BX101Rome06:401289.00
BX118Lisbon09:1545120.00
BX142Rome13:308165.00
BX177Oslo15:053099.00
BX203Lisbon18:503210.00

(a) State the output of the following SQL statement. [2]

SELECT FlightNo, Price FROM Flights WHERE Seats < 20 OR Price > 150

(b) Write an SQL statement to display the Destination and Departs fields of all flights that cost 100.00 or less. [3]

(c) A student writes this SQL statement to find all flights to Rome.

SELECT * WHERE Destination = "Rome" FROM Flights

Identify the error in the statement. [1]

7Grade 4–54 marks

A greenhouse sensor stores temperatures in a 2D array called temps. Each row is one day and each column is one reading (morning, midday, evening). The contents of the array are shown.

Column 0Column 1Column 2
Row 0141821
Row 1121923
Row 2151720
Row 3111622

Elements are accessed as temps[row, column].

(a) State the total number of elements the array temps can store. [1]

(b) The following code is run.

total = 0
for i = 0 to 3
   total = total + temps[i, 1]
next i
print(total)

State the value that is output. Show your working. [2]

(c) Write a line of code that stores the value 9 in row 2, column 0 of the array. [1]

8Grade 6–75 marks

A small shop does not use a database. Instead it stores its stock in a 2D array called stock, where each row is one record and each column is one field. All values are stored as strings. Part of the array is shown.

Column 0 (name)Column 1 (quantity)Column 2 (price)
Row 0Bolt400.12
Row 1Nut30.08
Row 2Hinge72.50
Row 3Washer20.05

The array has 50 rows. Elements are accessed as stock[row, column].

Write an algorithm that:

  • asks the user to enter a product name
  • searches every row of stock for that product name
  • if the product is found, outputs its quantity
  • if the product is not found, outputs the message Not found.

Use OCR Exam Reference Language or a high-level programming language. [5]

9Grade 6–75 marks

A function posMin takes a 1D array of integers as a parameter and returns the index of the smallest value in the array.

For example, if the array holds 34, 19, 52, 19, 27 the function returns 1.

(a) Write the function posMin. Use OCR Exam Reference Language or a high-level programming language. [4]

(b) An array called ages has already been filled with values. Write a line of code that calls posMin with ages and stores the result in a variable called pos. [1]

10Grade 8–96 marks

A cinema has 5 rows of 4 seats. Bookings are stored in a 2D array seats[5, 4] of Boolean values, accessed as seats[row, seat]. The value true means the seat is booked and false means it is free. The current contents are shown in the diagram.

Write an algorithm that:

  • counts the number of free seats in each row
  • outputs the row number of the row with the most free seats.

If two rows have the same number of free seats, the lower row number should be output. For the data shown, the algorithm should output 1.

Use OCR Exam Reference Language or a high-level programming language. [6]

Screenrowseat 0seat 1seat 2seat 301234booked (true)free (false)

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