Cambridge O Level Computer Science 2210 · 8.3 File handling

Q67 · 2210/22/O/N/24 Q10

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

Q672210/22/O/N/24original Q10Structured · 6 marks
Question 10 from 2210/22/O/N/24

Worked solution

Whole answer

Declare variables, input the line, write it to Main.txt, make a lower-case copy, output it with its length, then write the copy to Lowercase.txt.

DECLARE LineOfText : STRING
DECLARE LowercaseText : STRING
INPUT LineOfText
OPENFILE Main.txt FOR WRITE
WRITEFILE Main.txt, LineOfText
CLOSEFILE Main.txt
LowercaseText ← LCASE(LineOfText)
OUTPUT LowercaseText, LENGTH(LineOfText)
OPENFILE Lowercase.txt FOR WRITE
WRITEFILE Lowercase.txt, LowercaseText
CLOSEFILE Lowercase.txt

Declaration of suitable string variable(s) and input of the line of text [1]

Main.txt opened FOR WRITE and the line written to it with WRITEFILE [1]

Correct use of LCASE to make the lower-case text [1]

Correct use of LENGTH, with the lower-case text and the length output [1]

Lowercase.txt opened and the lower-case text written to it [1]

Both files closed with CLOSEFILE [1]

KEY IDEAOpen a file, write, close it; use LCASE and LENGTH to process the text.
TOTAL 6 marks

Official mark scheme

Mark scheme for 2210/22/O/N/24 question 10
VIDEO
▶ Topic lesson

A lesson on this topic · by Craig'n'Dave. 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.