DigiBacc

Practice questions › IB Computer Science › Programming › File processing
IB Computer Science · Programming

File processing practice questions.

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.

At a glance

About this topic

Syllabus code
B2.5
Subject
IB Computer Science
Topic
B2 · Programming
Questions
40 with worked answers
Question types
13 multiple-choice questions · 9 flashcards · 8 fill-in-the-gap questions · 4 true/false questions · 3 matching tasks · 2 structured questions · 1 diagram task
Try it

Sample questions on File processing

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?

  • The records can be held in less memory while the program runs
  • The records can be searched with a binary search rather than a linear search
  • The records survive after the program ends and can be read back next time
  • The records are checked for typing errors as they are written

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?

  • Open it for reading, then write at the position reached
  • Open it for writing, so the new record is placed first
  • Open it twice at once, for reading and for writing
  • Open it for appending, so writing starts at the end

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?

  • Copy every record except the unwanted one into a new file
  • Write spaces over the unwanted record where it is stored
  • Write the unwanted record again at the end of the file
  • Close the file without writing anything and reopen it for reading

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?

  • Sequential, because the records stay in the order they were entered
  • Sequential, because reading forwards needs no calculation
  • Direct, because every record must be read to find the right one
  • Direct, because one record can be located and read on its own

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?

  • Whether the file holds more records than the array can store
  • Whether a file of that name exists and could be opened
  • Whether the records are sorted on the key field
  • Whether the file was written by the same program

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?

  • Reading the file at start-up makes each later change slower
  • The array cannot hold records made up of several fields
  • Work done in the session is lost if the program stops early
  • The file has to be sorted before the array can be filled

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 free
Exam tips

Command terms in this topic

Keep going

More topics in Programming

All of Programming →

40 File processing questions — free with an account. Spaced repetition, streaks and full exam simulations included.

Practise them free

This 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.