Worked solution from the Programming Paper 2 Algorithms, Programming and Logic booklet, Part 1 of 3.
Declare each variable with a suitable type: text, whole number, TRUE or FALSE.
DECLARE Name : STRING DECLARE Age : INTEGER DECLARE Found : BOOLEAN
DECLARE Name : STRING [1]
DECLARE Age : INTEGER [1]
DECLARE Found : BOOLEAN [1]
Open the file for writing, write the name, then close the file, all inside the procedure.
PROCEDURE StoreData(Name : STRING)
OPENFILE People.txt FOR WRITE
WRITEFILE People.txt, Name
CLOSEFILE People.txt
ENDPROCEDUREUses PROCEDURE StoreData and ENDPROCEDURE [1]
Parameter defined correctly (Name : STRING) [1]
File opened for write [1]
Name written to the file with WRITEFILE [1]
File closed [1]
Use CALL with the name in quotes.
CALL StoreData("Suella")Uses CALL [1]
Correct call with the parameter "Suella" [1]
▶ Topic lesson
A lesson on this topic · by Mr Bulmer's Learning Zone. 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.