2210/22/O/N/24 question 10: worked solution (October/November 2024, paper 22)

Show as plain text

Cambridge O Level Computer Science 2210 · 8.3 File handling Worked solution from the Programming Paper 2 Algorithms, Programming and Logic booklet, Part 3 of 3. Q67 2210/22/O/N/24 original Q10 Structured · 6 marks 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 IDEA Open a file, write, close it; use LCASE and LENGTH to process the text. TOTAL 6 marks Official mark scheme VIDEO ▶ Topic lesson A lesson on this topic · by Craig'n'Dave. Tap the picture to open it on YouTube.