1. Why files are needed
An array is temporary storage. When the program ends or the computer is switched off, the data in it is lost.
Data written to a file is retained after the computer is switched off, so it is stored permanently and is non-volatile.
This is why a program can write its arrays to a file at the end of the day and read them back at the start of the next. The data is then only entered once.
Examiner insight
Worked example 13 marks
A concert venue uses a program to calculate admission prices and store information about ticket sales.
A number of arrays are used to store data. The computer is switched off overnight and data has to be input again at the start of each day before any tickets can be sold. This process is very time consuming.
(i) Explain how the program could use text files to speed up the process.
(ii) State the characteristic of text files that allow them to be used as explained in part (i).
- 1
(i) data from the arrays is written to the files at the end of the day / before the computer is switched off [1]
- 2
(i) data is read from the files at the start of the next day and stored in the arrays [1]
- 3
(ii) the data is retained after the computer is switched off // stored permanently // non-volatile storage [1]