GCSE (9-1) Computer Science
Mark Scheme
J277/02: 2.2 Programming Fundamentals (File Handling)
Question Answer Marks Guidance
1 1. endOfFile
2. readLine
3. close
3
1 mark for each correct keyword. Spelling must be accurate.
2 Any two from:
  • To free up system resources / memory.
  • To ensure data is physically saved/committed to the disk.
  • To prevent file corruption or locks preventing other programs from using it.
2
Must give a valid technical reason. "Because it's finished" is insufficient.
3 Output: 100100
Reason: The data read from the file is a String "100". The + operator concatenates strings rather than adding numbers.
2
Ghost Topic: If they calculate 200, award 0 marks. This tests the specific casting gap.
4a Line 02: while NOT file.endOfFile(): (Accept missing colon or handle assignment depending on ERL variation). 1
Syntax focus: In ERL methods usually need ().
4b Line 04: newPrice = float(price) * 1.2 (or int(price)).
Reason: Cannot perform arithmetic on a String data type.
2
Critical: Must mention Casting or Data Types.
5 1. val: 5 | val > 4: True | x: 5
2. val: 2 | val > 4: False | x: 3
3. val: 8 | val > 4: True | x: 11
4. Output: 11
4
1 mark for each correct iteration of x and 1 for output.
6 f1 = open("maths_scores.txt")
f2 = newFile("pass_list.txt")
while NOT f1.endOfFile()
  line = f1.readLine()
  score = int(line)
  if score >= 50:
    f2.writeLine(line)
f1.close()
f2.close()
6
BP1: Opens both files (1 read, 1 write).
BP2: Loop until EOF.
BP3: Casts input to Integer.
BP4: Comparison score >= 50.
BP5: Writes to correct handle.
BP6: Closes BOTH files.
7 (a) Opening in "Write" mode creates a new file / overwrites existing data.
(b) file = open("diary.txt", "a") OR file = append("diary.txt")
2
Must distinguish between 'Write' and 'Append'.
8 if exists("maths_scores.txt") then ...
OR
TRY ... EXCEPT ... block.
2
Ghost Topic: Defensive design discriminator.