Six original Cambridge-style questions on file handling in 0478 pseudocode, with mark points.
Explain why a program might store data in a file.
Write pseudocode to input a user's name and store it in a new file called User.txt.
INPUT UserName ✓OPENFILE "User.txt" FOR WRITE then WRITEFILE "User.txt", UserName ✓CLOSEFILE "User.txt" ✓The file Words.txt contains at least five lines of text. Write pseudocode to read the first five lines and output each one.
OPENFILE "Words.txt" FOR READ ✓FOR Count ← 1 TO 5 ... NEXT Count ✓READFILE "Words.txt", LineOfText then OUTPUT LineOfText inside the loop ✓CLOSEFILE "Words.txt" after the loop ✓Data.txt contains the lines 7, 4 and 9. State the output.
DECLARE Value : INTEGER DECLARE Total : INTEGER Total ← 0 OPENFILE "Data.txt" FOR READ READFILE "Data.txt", Value Total ← Total + Value READFILE "Data.txt", Value Total ← Total + Value CLOSEFILE "Data.txt" OUTPUT Total, " ", Value
A program opens Results.txt FOR WRITE every time it runs, to add one new result. Explain the problem.
Write pseudocode to copy the first line of Old.txt into a new file New.txt.
OPENFILE "Old.txt" FOR READ and OPENFILE "New.txt" FOR WRITE ✓READFILE "Old.txt", LineOfText ✓WRITEFILE "New.txt", LineOfText ✓CLOSEFILE "Old.txt" and CLOSEFILE "New.txt" ✓Mark this once you have attempted all six and checked your working. It records a Practiced badge on the topic and adds a one-time bonus. Revealing the solutions alone does not count.