Worked solution from the Programming Paper 2 Algorithms, Programming and Logic booklet, Part 3 of 3.
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]
▶ 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.