Full Marks

GCSE Computer Science · Topic 7

Data structures, subroutines and robust programs

Data structures, subroutines and robust programs is about organising data and writing code that is reliable and easy to maintain.

We will use arrays and records, manipulate strings, generate random numbers and read and write files.

Then we write subroutines with parameters and local variables, validate input, test thoroughly, and use I D E tools.

In this topic

  1. 7.1Arrays (1D and 2D) and recordsFree below · 26 questions
  2. 7.2String manipulation, random numbers and file handlingOpen in Full Marks · 27 questions
  3. 7.3Subroutines: functions, procedures, parameters and local/global scopeOpen in Full Marks · 26 questions
  4. 7.4Defensive design: input validation, sanitisation, authentication and maintainable codeOpen in Full Marks · 33 questions
  5. 7.5Syntax, logic and runtime errors, and designing test plans (normal, boundary, invalid, erroneous data)Open in Full Marks · 35 questions
  6. 7.6Programming languages and IDE tools (editors, error diagnostics, debuggers, run-time environment)Open in Full Marks · 32 questions

7.1 · Free notes

Arrays (1D and 2D) and records

Diagram: Arrays (1D and 2D) and records

Key points

In more detail

Practice

Arrays (1D and 2D) and records: 10 questions

Pick an answer to check it, or open the answer for the explanation.

1. An array is created as scores = [12, 7, 9, 15, 4], with indexing starting at 0. What value does scores[3] hold?

  1. 4
  2. 15
  3. 9
  4. 7
Show answer

B: 15. Index 0 is 12, 1 is 7, 2 is 9 and 3 is 15. Counting from 0 means scores[3] is the fourth element.

2. An array is declared with 20 elements and indexing starts at 0. What is the last valid index?

  1. 18
  2. 19
  3. 21
  4. 20
Show answer

B: 19. Indices run from 0 to length − 1, so 20 elements have indices 0 to 19. Using index 20 would be out of range.

3. A 2D array stores seating for a hall with 4 rows and 6 columns. How many elements does it contain?

  1. 46
  2. 20
  3. 10
  4. 24
Show answer

D: 24. The number of elements in a 2D array is rows × columns, so 4 × 6 = 24.

4. grid = [[1,2,3],[4,5,6],[7,8,9]] and indexing starts at 0 with grid[row][col]. What is grid[2][0]?

  1. 7
  2. 3
  3. 8
  4. 6
Show answer

A: 7. grid[2] is the third row [7,8,9], and column 0 of that row is 7.

5. nums = [2, 4, 6, 8]. A loop runs i from 0 to 3 doing total = total + nums[i], starting with total = 0. What is total at the end?

  1. 12
  2. 20
  3. 14
  4. 8
Show answer

B: 20. The loop adds every element: 2 + 4 + 6 + 8 = 20.

6. Why is an array better than 100 separate variables for storing 100 test scores?

  1. It allows different data types for each score
  2. It stops the scores being changed
  3. A loop can process all the scores using one identifier
  4. It makes the numbers smaller
Show answer

C: A loop can process all the scores using one identifier. One identifier plus an index means a loop can process every score, giving shorter and more maintainable code.

7. An array holds 5 items and the program runs: print(data[5]). What is most likely to happen?

  1. An index out of range error occurs
  2. It prints the last item
  3. It prints 0
  4. It prints the first item
Show answer

A: An index out of range error occurs. Valid indices are 0 to 4. Index 5 is outside the array so the program raises an index out of range error.

8. Which data structure is the most suitable for storing one customer's name (string), age (integer) and member status (Boolean)?

  1. A 1D array
  2. A record
  3. A 2D array
  4. A single string
Show answer

B: A record. A record groups related fields of different data types about one item, accessed with dot notation.

9. Which statement about arrays in GCSE pseudocode is correct?

  1. Each element must be a different data type
  2. The first element is at index 1 in Python
  3. All elements normally have the same data type
  4. Elements are located by their name, not position
Show answer

C: All elements normally have the same data type. An array stores elements of one data type under one identifier. Python, AQA, OCR and Edexcel all count indices from 0.

10. A teacher stores 5 test marks for each of 30 students. Which structure is most suitable?

  1. A record with 5 fields
  2. A 2D array with 30 rows and 5 columns
  3. A single integer variable
  4. A 1D array with 5 elements
Show answer

B: A 2D array with 30 rows and 5 columns. Marks for many students across several tests form a table, so a 30 × 5 2D array fits, with one row per student.

Keep going in Full Marks

Full Marks has 26 questions on Arrays (1D and 2D) and records (16 more than here), set out in practice levels. You also get notes and 3D models for all 6 subtopics of Data structures, subroutines and robust programs, plus games, timed exams and past papers.

On your exam board

All GCSE Computer Science topics