Level:
Correct: 0
Incorrect: 0
Marks: 0/0
Exam Practice
Course:
Topics:
AQA GCSE Computer Science (Paper 1) Smart practice A mixed round aimed at your weak spots
Unit 1
3.1 Fundamentals of algorithms
Unit 2
3.2 Programming
Data types
Data types
Arithmetic operations in a programming language
Arithmetic operations, DIV and MOD
Relational operations in a programming language
Relational operations
Boolean operations in a programming language
Boolean operations in conditions
Data structures
Arrays and records
Input/output
Input and output
String handling operations in a programming language
String handling
Random number generation in a programming language
Random number generation
Structured programming and subroutines (procedures and functions)
Subroutines and structured programming
Avg
score:
–
Topics
done:
0/15

Arrays and records

Practise 35 exam-style questions on Arrays and records for AQA GCSE Computer Science (Paper 1). 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.

  • 35 questions
  • 1–8 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 teacher stores the marks of four students in three tests in a two-dimensional array. Each inner array holds one student's marks.

marks ← [[12, 15, 9], [18, 7, 14], [11, 20, 16], [8, 13, 19]]

Which expression evaluates to 14?

Choose your answer.

  • marks[2][1]
  • marks[1][2]
  • marks[0][2]
  • marks[2][2]

Model answer

marks[1][2]

Explanation

The first index chooses the inner array (the student) and the second index chooses the element within it (the test), both counting from 0. 14 is in the second inner array, index 1, at position 2, so it is marks[1][2]. marks[2][1] swaps the two indexes and gives 20, which is a common mistake.

Mark scheme
  1. 1 mark

    marks[1][2]

    If more than one option is given, 0 marks. Mark is for AO2 (apply).

Question 2

2 marks

A sports centre stores each member's details in a record. One of the fields stores the member's mobile phone number, for example 07700 900461.

Explain why String is a more suitable data type than Integer for this field.

Model answer

If it were stored as an integer, the leading 0 would be lost, so 07700 900461 would become 7700900461. Also, phone numbers are never used in calculations, and they can contain spaces or a + sign, which an integer cannot hold.

Explanation

Data made of digits is not always a number: a value should be stored as an integer or real only if it is a quantity used in arithmetic. A phone number keeps its leading zero and its spaces only if it is stored as a string. 'Because it is a phone number' does not explain anything, so it scores nothing.

Mark scheme
  1. 1 mark

    A phone number starting with 0 would lose its leading zero if it were stored as an integer;

    Max 2. All marks AO1 (understanding). Do not award two marks for one idea stated twice.

  2. 1 mark

    Phone numbers are not used in calculations (so they do not need to be stored as numbers);

  3. 1 mark

    A phone number may contain characters that an integer cannot store, such as spaces, + or brackets;

  4. 1 mark

    The number has too many digits to fit in some integer data types;

    NE. 'because it is a phone number' / 'it is easier'.

Question 3

3 marks

The algorithm below is written in pseudo-code.

01nums ← [3, 8, 1, 6, 5]
02first ← nums[0]
03FOR i ← 0 TO LEN(nums) - 2
04  nums[i] ← nums[i + 1]
05ENDFOR
06nums[LEN(nums) - 1] ← first

State the contents of the array nums after the algorithm has run, and explain why the FOR loop on line 3 stops at LEN(nums) - 2 instead of LEN(nums) - 1.

Model answer

nums = [8, 1, 6, 5, 3]
The loop copies into each position the element to its right (nums[i + 1]). If i went up to LEN(nums) - 1, which is 4, line 4 would read nums[5], which does not exist, so the program would stop with an out-of-range error. The last element is filled by line 6 instead.

Explanation

The algorithm saves the first value, moves every other value one place to the left, then puts the saved value at the end, so it rotates the array: [3, 8, 1, 6, 5] becomes [8, 1, 6, 5, 3]. Because each pass reads the element at i + 1, the largest safe value of i is LEN(nums) - 2. A common mistake is to shift the values right instead of left, which puts 5 at the front.

Mark scheme
  1. 1 mark

    8, 1, 6, 5 in the first four positions (indexes 0 to 3);

    All marks AO2 (apply). Award marks 1 and 2 for [8, 1, 6, 5, 3]. I. Brackets, commas and quotation marks.

  2. 1 mark

    3 in the last position (index 4);

  3. 1 mark

    Line 4 uses nums[i + 1], so if i reached LEN(nums) - 1 (4) it would try to access nums[5], which is out of range // there is no element after the last one to copy, so the last element is set separately on line 6;

    A. it would cause an index out of range error. NE. 'so it does not loop too many times' with no reason.

Question 4

5 marks

A school stores each pupil's details in a record:

RECORD Pupil
  name : String
  form : String
  points : Integer
ENDRECORD

The records for all the pupils are stored in an array called pupils.

Write an algorithm that:
- outputs the name of every pupil who is in form 10B and has more than 50 points
- then outputs the number of pupils whose names were output.

Your algorithm must work for any number of pupils. You do not need to write code to create the array.

You may write your answer in pseudo-code, C#, Python or VB.NET.

Model answer

count ← 0
FOR i ← 0 TO LEN(pupils) - 1
  IF pupils[i].form = '10B' AND pupils[i].points > 50 THEN
    OUTPUT pupils[i].name
    count ← count + 1
  ENDIF
ENDFOR
OUTPUT count

Explanation

Each record is reached by its index in the array and each field by its name, so pupils[i].points is the points total of the pupil at index i. Both parts of the condition must be true, so AND is needed, and 'more than 50' means > 50, so a pupil on exactly 50 points is not output. The count must be output after the loop; outputting it inside the loop is a common error.

Mark scheme
  1. 1 mark

    Mark A for iterating through every record in the array, for an array of any length;

    1 mark for AO3 (design), 4 marks for AO3 (program). Mark A (design) should be credited whether or not the syntax is correct.

  2. 1 mark

    Mark B for accessing the fields using the array index (or the loop variable) and the field name, e.g. pupils[i].form;

  3. 1 mark

    Mark C for a correct condition that checks both that form is '10B' and that points is greater than 50;

    R. points ≥ 50 / >= 50. R. OR instead of AND.

  4. 1 mark

    Mark D for outputting the name of each pupil who meets the condition, inside the loop;

  5. 1 mark

    Mark E for counting the pupils who meet the condition and outputting the count once, after the loop;

    Maximum 4 marks if any errors in code.
    I. Case. I. Indentation. A. double quotation marks. A. answers in another clear and consistent style of pseudo-code. I. Gaps/spaces throughout the code, except where to do so would explicitly alter the logic of the code in a way that makes it incorrect.
    Pseudo-code Example 1 (fully correct): the model answer.
    Python Example 1 (fully correct), with Pupil defined as a class:
    count = 0
    for pupil in pupils:
    if pupil.form == "10B" and pupil.points > 50:
    print(pupil.name)
    count = count + 1
    print(count)
    C# Example 1 (fully correct), with Pupil declared as a struct:
    int count = 0;
    foreach (Pupil pupil in pupils)
    {
    if (pupil.form == "10B" && pupil.points > 50)
    {
    Console.WriteLine(pupil.name);
    count = count + 1;
    }
    }
    Console.WriteLine(count);
    A. Write in place of WriteLine.
    VB.NET Example 1 (fully correct), with Pupil declared as a Structure:
    Dim count As Integer = 0
    For Each onePupil As Pupil In pupils
    If onePupil.form = "10B" And onePupil.points > 50 Then
    Console.WriteLine(onePupil.name)
    count = count + 1
    End If
    Next
    Console.WriteLine(count)
    A. AndAlso in place of And.

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.