Cambridge O Level Computer Science 2210 · 8.3 File handling

Q66 · 2210/21/M/J/24 Q7

Worked solution from the Programming Paper 2 Algorithms, Programming and Logic booklet, Part 3 of 3.

Q662210/21/M/J/24original Q7Structured · 6 marks
Question 7 from 2210/21/M/J/24

Worked solution

(a)

Think about what a file does that variables in memory cannot. Write any two of these:

A file gives a permanent copy of the data, so it is not lost when the program ends or the power is off [1]

The data can be used again by the same program or by another program [1]

Or: the file can be copied or transferred to another computer (also accepted, but only two marks in total)

Write any two of the points above.

(b)

Declare a string, open the file for reading, read the line into the string, then output it in upper case with its length.

DECLARE Words : STRING
OPENFILE Quotation.txt FOR READ
READFILE Quotation.txt, Words
OUTPUT UCASE(Words), LENGTH(Words)
CLOSEFILE Quotation.txt

Declaration of a string variable [1]

OPENFILE with the file name and FOR READ [1]

READFILE into the string variable [1]

UCASE and LENGTH used and both output [1]

Closing the file with CLOSEFILE also earns a mark, but the maximum is four.

KEY IDEAFiles keep data permanently; open, read, process and close in that order.
TOTAL 6 marks

Official mark scheme

Mark scheme for 2210/21/M/J/24 question 7
VIDEO
▶ Whole paper

Video solution of the whole paper · by ZAINEMATICS. Tap the picture to open it on YouTube.

Solutions follow the official Cambridge mark schemes; marks are shown in grey. Videos are from other YouTube channels. Paper codes read component / series / year: M/J = May/June, O/N = October/November. Past-paper questions © UCLES, reproduced for classroom practice.