File handling: IGCSE Computer Science questions with answers
Free File handling questions for IGCSE Computer Science (0478), part of Algorithms & programming. Each question has the answer and the marking points an examiner would look for.
A program needs to store data permanently in a text file called Members.txt.
(a)
Explain why data is stored in a file rather than only in variables.
[2]
(b)
Write pseudocode to input 5 lines of text from the user and write them to the file Members.txt, then close the file.
[4]
Show answers and mark scheme
Part
Answer and marking points
Marks
(a)
Data in variables is lost when the program ends / computer is switched off; a file stores it permanently so it can be used again / by another program
Variables / RAM lose data when the program closes B1 File stores data permanently for later use / to share B1
2
(b)
OPENFILE "Members.txt" FOR WRITE; FOR Count ← 1 TO 5; INPUT Line; WRITEFILE "Members.txt", Line; NEXT Count; CLOSEFILE "Members.txt"
OPENFILE "Members.txt" FOR WRITE B1 Loop 5 times with INPUT inside B1 WRITEFILE "Members.txt", Line inside the loop B1 CLOSEFILE "Members.txt" after the loop B1
4
Question 2Structured · 2 marks
State what is meant by the term file.
[2]
Show answers and mark scheme
Part
Answer and marking points
Marks
A collection of data stored permanently so it can be used after the program ends
A collection of data stored permanently so it can be used after the program ends B2
2
Question 3Structured · 6 marks
A program needs to store data permanently in a text file called Members.txt.
(a)
Explain why data is stored in a file rather than only in variables.
[2]
(b)
Write pseudocode to input 20 lines of text from the user and write them to the file Members.txt, then close the file.
[4]
Show answers and mark scheme
Part
Answer and marking points
Marks
(a)
Data in variables is lost when the program ends / computer is switched off; a file stores it permanently so it can be used again / by another program
Variables / RAM lose data when the program closes B1 File stores data permanently for later use / to share B1
2
(b)
OPENFILE "Members.txt" FOR WRITE; FOR Count ← 1 TO 20; INPUT Line; WRITEFILE "Members.txt", Line; NEXT Count; CLOSEFILE "Members.txt"
OPENFILE "Members.txt" FOR WRITE B1 Loop 20 times with INPUT inside B1 WRITEFILE "Members.txt", Line inside the loop B1 CLOSEFILE "Members.txt" after the loop B1
4
Question 4Structured · 6 marks
A program needs to store data permanently in a text file called Results.txt.
(a)
Explain why data is stored in a file rather than only in variables.
[2]
(b)
Write pseudocode to input 20 lines of text from the user and write them to the file Results.txt, then close the file.
[4]
Show answers and mark scheme
Part
Answer and marking points
Marks
(a)
Data in variables is lost when the program ends / computer is switched off; a file stores it permanently so it can be used again / by another program
Variables / RAM lose data when the program closes B1 File stores data permanently for later use / to share B1
2
(b)
OPENFILE "Results.txt" FOR WRITE; FOR Count ← 1 TO 20; INPUT Line; WRITEFILE "Results.txt", Line; NEXT Count; CLOSEFILE "Results.txt"
OPENFILE "Results.txt" FOR WRITE B1 Loop 20 times with INPUT inside B1 WRITEFILE "Results.txt", Line inside the loop B1 CLOSEFILE "Results.txt" after the loop B1
4
Question 5Structured · 6 marks
A program needs to store data permanently in a text file called Stock.txt.
(a)
Explain why data is stored in a file rather than only in variables.
[2]
(b)
Write pseudocode to input 20 lines of text from the user and write them to the file Stock.txt, then close the file.
[4]
Show answers and mark scheme
Part
Answer and marking points
Marks
(a)
Data in variables is lost when the program ends / computer is switched off; a file stores it permanently so it can be used again / by another program
Variables / RAM lose data when the program closes B1 File stores data permanently for later use / to share B1
2
(b)
OPENFILE "Stock.txt" FOR WRITE; FOR Count ← 1 TO 20; INPUT Line; WRITEFILE "Stock.txt", Line; NEXT Count; CLOSEFILE "Stock.txt"
OPENFILE "Stock.txt" FOR WRITE B1 Loop 20 times with INPUT inside B1 WRITEFILE "Stock.txt", Line inside the loop B1 CLOSEFILE "Stock.txt" after the loop B1
Riyaz Shaikh has mentored IGCSE, IB and A Level students for 15+ years, one-on-one, online and in Mumbai. The hardest questions on this site are the ones he uses to find a student's weak points.
Original Cambridge-style practice questions written for mentorriyaz.in. These are not Cambridge past paper questions, and this site is not affiliated with or endorsed by Cambridge University Press & Assessment. Updated 2026-11-04. Paper generator · mentorriyaz.in