40 exam-style questions on File processing — topic B2.5 of Programming in the IB Computer Science syllabus — with answers and explanations. Samples below; the full set is free with an account.
A club program builds an array of member records each time it runs and asks the user to type them in again. What is the main advantage of writing the records to a file instead?
Answer: The records survive after the program ends and can be read back next time
A file is secondary storage, so its contents remain when the program and the power are gone; an array lives in primary memory and disappears with the process. Files make no promise about validation or search method.
A program must add one new member record to a file that already holds 200 member records, without disturbing them. Which way of opening the file achieves this?
Answer: Open it for appending, so writing starts at the end
Appending sets the write position beyond the existing records, so nothing already stored is touched. Opening the same file for writing starts a fresh copy and throws the 200 records away, which is the classic way of losing a data file.
A record must be removed from a sequential file. Which method deletes it without leaving a gap in the stored data?
Answer: Copy every record except the unwanted one into a new file
Records in a sequential file sit one after another, so the only clean removal is to rewrite the file with the unwanted record left out. Blanking the record in place keeps its space and forces every later program to test for empty records.
A booking system must fetch the record of one seat out of 50 000 as soon as a customer gives the seat number, and the seat number can be turned into a position in the file. Which file organisation suits this best?
Answer: Direct, because one record can be located and read on its own
Direct access means the program works out where a record lies from its key and reads only that record, which is what a single fast lookup needs. Sequential access would have to read up to 50 000 records to reach the last one.
A program opens a data file whose name the user types in. Which check should the program make before it starts reading?
Answer: Whether a file of that name exists and could be opened
If the open fails there is nothing to read and every later operation is meaningless, so the existence check has to come first. The other checks may be sensible afterwards, but they all assume the file was opened successfully.
A stock program reads a file of 5000 product records into an array at start-up, changes some of them during the session and writes the whole array back at the end. What is the main risk of this design?
Answer: Work done in the session is lost if the program stops early
Between the read and the final write, the only up-to-date copy of the data is in volatile memory, so a crash or a power cut loses everything done in the session. Writing each change out as it happens, or saving at intervals, is the usual remedy.
That was 6 of 40 File processing questions.
Practise all 40 freeOutlineAO1 · 1–2 marks
A brief account or summary: the main points in two or three sentences, no evaluation.
DistinguishAO2 · 2–4 marks
Make the difference clear for BOTH terms — a definition of one of them is only half an answer.
StateAO1 · 1–2 marks
One word or one short sentence. No explanation, no working: the mark is for the fact itself.
40 File processing questions — free with an account. Spaced repetition, streaks and full exam simulations included.
Practise them freeThis platform is independently developed and is not endorsed by, affiliated with, or sponsored by the International Baccalaureate Organization. “International Baccalaureate” and “IB” are registered trademarks of the IBO.