Back to the topic

The mark scheme starts on a new page, so you can print pages one and two for a student and keep the last page yourself. Everything prints in black on white whichever theme you are using.

AQA GCSE CS · 3.2.6 to 3.2.9

Data Structures, Strings and Files

Section A: 10 multiple choice questions, 10 marks. Section B: 5 written questions, 16 marks. Total 26 marks.

Name

Class

Date

Mark  / 26

Section A

Circle the letter of the correct answer. One mark each.

  1. 1An array called names holds 6 items. What is the index of the last one?1
    1. A0
    2. B5
    3. C6
    4. D7
  2. 2Which data structure would you use to store a student's name, year group and average mark together?1
    1. AA two dimensional array
    2. BA constant
    3. CAn array
    4. DA record
  3. 3What does SUBSTRING(2, 4, 'Computing') return?1
    1. A'omp'
    2. B'mpu'
    3. C'mp'
    4. D'mput'
  4. 4What is LEN('Computer Science')?1
    1. A14
    2. B15
    3. C16
    4. D17
  5. 5Why must a number read from a text file be converted before it is used in a calculation?1
    1. AEverything read from a text file arrives as a string
    2. BText files cannot contain numbers
    3. CThe file must be closed first
    4. DFiles store numbers in hexadecimal
  6. 6Why are computer generated random numbers described as pseudo-random?1
    1. AThey repeat after exactly one hundred values
    2. BThey only work for small ranges
    3. CThey are not really numbers
    4. DThey are produced by an algorithm from a seed, so the same seed always gives the same sequence
  7. 7In a two dimensional array board, what does board[2][0] refer to?1
    1. AAn error, since two indexes are not allowed
    2. BThe first item of the third row
    3. CThe third item of the first row
    4. DThe second row and the first column of a one based grid
  8. 8What is the value of CHAR_TO_CODE('B') if 'A' is 65?1
    1. A42
    2. B65
    3. C66
    4. D97
  9. 9Why should a file be closed after a program has finished writing to it?1
    1. AOutput may be buffered, so data can be lost if the file is not closed
    2. BClosing a file deletes it from memory
    3. CClosing a file converts it to binary
    4. DThe file cannot be read by another program until it is closed forever
  10. 10A program needs the last digit of an integer n. Which expression gives it?1
    1. An DIV 10
    2. Bn MOD 2
    3. Cn MOD 10
    4. DLEN(n)

Section B

Answer in the space provided. The number of marks tells you how many separate points to make.

  1. 1StateState one difference between an array and a record.2
  2. 2WriteA program stores 30 test scores in an array called scores. Write an algorithm that outputs the highest score.4
  3. 3ExplainExplain why a program that reads a number from a text file must cast it before performing a calculation.3
  4. 4DescribeA programmer needs to store the names, ages and email addresses of 200 club members. Describe a suitable data structure and justify your choice.4
  5. 5ExplainExplain why pseudo-random numbers are unsuitable for generating encryption keys.3

Mark scheme

Section A

1B2D3B4C5A6D7B8C9A10C

Section B

1 State one difference between an array and a record. 2

One mark for each of the following, to a maximum of 2.

  • An array stores values that are all of the same data type
  • A record stores values of different data types in named fields

Model answer. An array holds many values that must all be of the same data type, accessed by an index. A record holds several values of different data types that belong to one thing, each stored in its own named field.

2 A program stores 30 test scores in an array called scores. Write an algorithm that outputs the highest score. 4

One mark for each of the following, to a maximum of 4.

  • Sets a starting highest value, for example the first element
  • Loops through the array using the correct index range
  • Compares each element with the current highest
  • Updates the highest and outputs it at the end

Model answer. Set highest to scores[0], then loop i from 1 to LEN(scores) minus 1. Inside the loop, if scores[i] is greater than highest then set highest to scores[i]. After the loop finishes, output highest. Starting from the first element rather than from zero matters, because a list of negative scores would otherwise report zero as the highest.

3 Explain why a program that reads a number from a text file must cast it before performing a calculation. 3

One mark for each of the following, to a maximum of 3.

  • A text file stores characters, so the value read is a string
  • Arithmetic operators do not behave as intended on strings
  • Casting converts the string into an integer or real so the calculation works

Model answer. A text file holds characters, so a line read from it is a string even when every character in it is a digit. Applying an arithmetic operator to a string either causes an error or joins values together rather than adding them, so the result is wrong. Casting the string to an integer or a real converts it into a numeric value, after which the calculation behaves as intended.

4 A programmer needs to store the names, ages and email addresses of 200 club members. Describe a suitable data structure and justify your choice. 4

One mark for each of the following, to a maximum of 4.

  • Uses records to hold the three fields for one member
  • Justifies the record because the fields have different data types
  • Uses an array to hold the 200 records
  • Justifies the array because every member has the same set of fields and a loop can process them all

Model answer. The right structure is an array of records. Each member is one record with three named fields: name as a string, age as an integer and email as a string. A record is needed rather than an array for the individual member because the three values have different data types and belong together as a description of one person. The two hundred records are then held in an array, because every member has exactly the same set of fields, which means one loop can process all of them and the program does not have to change if the club gains or loses members.

5 Explain why pseudo-random numbers are unsuitable for generating encryption keys. 3

One mark for each of the following, to a maximum of 3.

  • They are produced by an algorithm from a seed value
  • The same seed always produces the same sequence, so the numbers are predictable
  • An attacker who works out or guesses the seed can reproduce the keys

Model answer. Pseudo-random numbers come from a deterministic algorithm applied to a starting seed, so they only appear random. Give the algorithm the same seed and it produces exactly the same sequence every time. If an attacker can work out or guess the seed, perhaps because it was taken from the system clock, they can regenerate the whole sequence and therefore every key the program produced. Cryptographic use requires a source of genuine unpredictability rather than a repeatable formula.