Lesson 4.2.1.3
4.2.1.3 Reading and writing text and binary files Quiz: AQA Computer Science, Unit 2
20 questions
In partnership with Revision Ninja
Lesson 4.2.1.3, Reading and writing text and binary files: 20 multiple choice questions for the AQA Computer Science (7517), Unit 2: Fundamentals of data structures, written with Revision Ninja.
Host it live on the board and students join with a game code on their own devices, or revise alone with Free Play. The answers are revealed in the game.
The 20 questions
-
What is the difference between a text file and a binary file?
- A binary file holds only characters, while a text file holds only numbers stored in raw form
- A text file holds characters that can be read as text, while a binary file holds raw data that is not plain text
- Text files cannot be read by programs, so they can only be opened and printed by a person directly
- Binary files can only store strings, so any number must be converted to text before it is saved
-
Which operation is needed to read data from a text file into a program?
- Convert the file to a binary format
- Write each item to the file before opening it
- Open the file for reading, then read each line or item
- Delete the file first
-
Which operation adds data to the end of an existing text file without deleting what is already there?
- Open the file in append mode and write
- Open the file in read mode and write
- Open the file as binary and read
- Delete the file and create a new one
-
Why might a program write data to a binary file rather than a text file?
- Binary files cannot store numbers, so they can only be used to hold characters of text
- Binary files store data in a compact form that does not need text conversion
- Binary files can be read by people without any tools, because the data is in plain English
- Binary files do not need to be opened, because the operating system loads them automatically
-
A text file is read line by line until the end of the file is reached. What is the main purpose of the end-of-file check?
- To delete the file after reading, so that the same data cannot be read again by the program
- To convert every line to a number, so that the file contents are ready for arithmetic
- To open the file for writing, so that new lines can be added after the last line read
- To stop the loop when there is no more data to read
-
A binary file stores a record with a name and a score. Which statement is correct?
- Fields can be read back in any order without knowing their types
- Each field must be read back in the same order and type it was written
- The name and score must be stored as text
- Binary files cannot store records
-
What does it mean to write a record to a file?
- Delete the record from memory, freeing the space it used so that the file can be closed
- Convert the record into a constant, so its values can never be changed by the program later
- Print the record on a screen only, so that the user can see its fields but nothing is saved
- Store all the fields of the record in the file so it can be read back later
-
A program writes a record to a text file as the line Sam,42. Which operation is needed when reading the age back as a number?
- Boolean conversion of Sam
- Float to date/time conversion of 42
- String to integer conversion of the text 42
- Integer to string conversion of Sam
-
Which description best fits a file used to hold a list of records that can be read sequentially?
- A file with no records
- A file where records are accessed only by a hash key
- A file processed from the first record to the last in order
- A file that is always randomly accessed
-
What is a potential problem if a program fails to close a file after writing to it?
- The file becomes a constant, so it can no longer be written to by any program in the future
- Data may not be saved correctly or the file may be left in an inconsistent state
- The program runs faster, because the operating system stops checking the file for changes
- The file is automatically converted to binary, so the text content is lost when the program ends
-
Which check should a program make before reading from a file that the user names?
- Check that the file exists and can be opened
- Check that the file is in alphabetical order
- Check the file's colour
- Check that the file has exactly 10 lines
-
A program reads a text file of 100 numbers, one per line. Which structure is most suitable to hold them for processing?
- A binary tree of strings only
- A single Boolean
- An array of 100 integers
- A single constant
-
A file contains records of students in a fixed order. Which access method reads one record after another?
- Parallel access by pointer
- Direct access by hash
- Sequential access
- Random access by key
-
Why must a text file be opened in the correct mode before it is used?
- Reading and writing require different modes, and using the wrong one causes an error
- The mode decides the file's name, so the program must choose a mode before naming the file
- The mode changes the colour of the text on screen, so that reading and writing show different colours
- Modes are only needed for binary files, since text files can always be read and written freely
-
A binary file of records is written with the name field before the score field. What must happen when it is read?
- The name is read first, then the score, in the same order
- Only the name is read and the score is ignored
- The score is read first, then the name, to save time
- The file cannot be read back at all
-
What is the main reason to use a file rather than only variables in memory?
- Data is kept after the program ends and can be used again later
- Files reduce the need for any data types
- Files stop the program from crashing
- Variables in memory are always slower to use than files
-
A program writes a line of text to a file, then reads the file expecting to see that line but gets nothing. What is a likely cause?
- Text files cannot contain lines, so each line written is discarded when the file is saved
- The file was not closed or flushed before reading back
- The program used the constant keyword, which stops the file from being read until it is closed
- The program was run too quickly, so the file had not yet been created when it was read back
-
Which statement best describes a field in a record that is stored in a file?
- A single named item of data within the record, such as a name or score
- A whole file on a disk, which holds many records that are stored one after another in order
- A pointer to another file, which gives the location of the record's data on the disk
- A stack frame for one subroutine, which holds the locals and parameters of a single call
-
A program must update one record in a large binary file without rewriting the rest. Which access method helps?
- Random access to the record's position
- Only sequential reading from the start
- Deleting the whole file first
- Converting the file to text
-
Which is a suitable use of a binary file?
- Storing an image's raw pixel data
- Storing a list of names for a printed report
- Storing a note that a person needs to read
- Storing a sentence in a letter
Related quizzes
- Data structures and abstract data types Quiz · 4.2.1.1 · 20 questions
- Single- and multi-dimensional arrays Quiz · 4.2.1.2 · 20 questions
- Linear, circular and priority queues Quiz · 4.2.2.1 · 20 questions
- Stack operations Quiz · 4.2.3.1 · 20 questions
- Graphs: weighted, directed and adjacency representations Quiz · 4.2.4.1 · 20 questions
- Trees and binary trees Quiz · 4.2.5.1 · 20 questions
- Hash tables, hashing and collisions Quiz · 4.2.6.1 · 20 questions
- Dictionaries and key-value pairs Quiz · 4.2.7.1 · 20 questions
- Vectors and vector operations Quiz · 4.2.8.1 · 20 questions
- Data types Quiz · 4.1.1.1 · 20 questions