Cambridge O Level Computer Science 2210 · 8.1 Programming concepts

Q41 · 2210/23/O/N/25 Q9

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

Q412210/23/O/N/25original Q9Structured · 10 marks
Question 9 from 2210/23/O/N/25

Worked solution

(a)

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]

(b)(i)

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
ENDPROCEDURE

Uses 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]

(b)(ii)

Use CALL with the name in quotes.

CALL StoreData("Suella")

Uses CALL [1]

Correct call with the parameter "Suella" [1]

KEY IDEADeclare a type for each variable; a procedure that writes to a file must open, write and close it.
TOTAL 10 marks

Official mark scheme

Mark scheme for 2210/23/O/N/25 question 9
VIDEO
▶ 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.