This quiz covers fundamental concepts of file handling and stream I/O, crucial for storing and retrieving data persistently. These topics are essential for Cambridge IGCSE Computer Science (0478/0984) Paper 2, focusing on how programs interact with external files for input and output. You'll be tested on file open modes (READ, WRITE, APPEND), reading from files, writing to files, appending data, the importance of closing files, and the concept of End-Of-File (EOF).
Scenario: Game High Scores
The following pseudocode outlines a program to manage a list of high scores for a game. It reads existing scores, adds a new one, and saves the updated list.
1. PROCEDURE ManageHighScores(NewPlayerName : STRING, NewPlayerScore : INTEGER)
2. DECLARE Scores : ARRAY OF STRING
3. DECLARE CurrentLine : STRING
4. DECLARE Index : INTEGER
5. OPENFILE "highscores.txt" FOR READ
6. Index = 0
7. WHILE NOT EOF("highscores.txt")
8. READFILE "highscores.txt", CurrentLine
9. Scores[Index] = CurrentLine
10. Index = Index + 1
11. CLOSEFILE "highscores.txt"
12. OPENFILE "highscores.txt" FOR APPEND
13. WRITEFILE "highscores.txt", NewPlayerName + "," + STRING(NewPlayerScore)
14. CLOSEFILE "highscores.txt"
15. // For simplicity, this example doesn't re-sort or limit the number of scores.
16. // It also doesn't explicitly show writing the entire 'Scores' array back if needed after modification.
17. // The primary focus here is reading all, then appending a new score.
18. ENDPROCEDURE