2210/21/M/J/24 question 7: worked solution (May/June 2024, paper 21)
Show as plain textHide 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. Q66 2210/21/M/J/24 original Q7 Structured · 6 marks 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 IDEA Files keep data permanently; open, read, process and close in that order. TOTAL 6 marks Official mark scheme VIDEO ▶ Whole paper Video solution of the whole paper · by ZAINEMATICS. Tap the picture to open it on YouTube.