Exam code: 9618
1/370Still learning
Know0
What does file processing involve?
File processing involves interacting with external files stored on secondary storage, such as hard drives and SSDs.

Join for free to unlock a full flashcard set, track what you know,
and turn revision into real progress.
State the three stages a file must go through for data to be handled correctly.
A file must be properly opened, then read from or written to, and then closed.
Name the three modes a file can be opened in.
The three modes are read, to read data, write, to overwrite data, and append, to add new data to the end.
Was this flashcard helpful?
What does file processing involve?
File processing involves interacting with external files stored on secondary storage, such as hard drives and SSDs.
State the three stages a file must go through for data to be handled correctly.
A file must be properly opened, then read from or written to, and then closed.
Name the three modes a file can be opened in.
The three modes are read, to read data, write, to overwrite data, and append, to add new data to the end.
Why must a file be closed after use?
Closing the file ends access to it and ensures all the data is saved properly.
Define serial access.
In serial access, records are stored one after another and accessed in the order they were added, which makes it suited to logging.
Define sequential access.
In sequential access, records are read in order from the beginning of the file to the end, which suits batch processing and text files.
Define random access.
In random access, records can be accessed directly using a key or file position, which suits databases and indexed files.
Random access requires indexed files or records of a length, so that the position of any record can be calculated.
Random access requires indexed files or records of a fixed length, so that the position of any record can be calculated.
True or False?
Opening a file in write mode adds the new data after the data already in the file.
False.
Write mode overwrites the existing data, and it is append mode that adds new data to the end.
Which type of file access would you use to write an event log, and in which mode would the file be opened?
Serial access is used for a log, with the file opened in APPEND mode so each entry is added after the last.
What does the OPENFILE command do, and what must follow it?
OPENFILE opens a file in a specified mode, written as OPENFILE "file.txt" FOR READ.
What do READFILE and WRITEFILE each do?
READFILE reads one line from a text file into a variable, and WRITEFILE writes one line to a text file.
What does the EOF function test, and where is it typically used?
EOF tests whether the end of the file has been reached, and is typically used as the condition of a loop, such as WHILE NOT EOF("file.txt").
The command moves to a specific record in a file opened for random access.
The SEEK command moves to a specific record in a file opened for random access.
What is the difference between GETRECORD and PUTRECORD?
GETRECORD reads the record at the file pointer into a variable, while PUTRECORD writes a record at the file pointer.
A program must update the grade in the 5th record of a random access file. Why is SEEK used twice?
SEEK is used once before reading the record and again before writing it back, because reading the record moves the file pointer past it.
True or False?
A user-defined record type is declared between TYPE and ENDTYPE.
True.
A record such as Student, holding a Name and a Grade, is declared between TYPE and ENDTYPE before it can be used.
In Python, what is the advantage of opening a file with with open(...)?
The file is closed automatically, so there is no need for a separate file.close() call.
In Java, how is a file opened for appending rather than overwriting?
By passing true as the second argument to FileWriter, as in new FileWriter("file.txt", true).
Python and Java both simulate random access rather than using it directly. How?
The whole file is read into a list of records, the required record is changed by its index, and the list is then written back over the file.
Define exception.
An exception is an unexpected event that disrupts the normal execution of a program.
Define exception handling.
Exception handling is how a program detects and responds to errors, allowing it to recover or to shut down cleanly.
State three benefits of using exception handling.
It prevents the program crashing unexpectedly, allows user-friendly error messages, and makes the program more robust and reliable.
Give four problems that exception handling can deal with.
Division by zero, a file not being found or an end-of-file error, hardware or device failure such as a lost printer connection, and invalid input from a user.
Name the three causes of exceptions, with an example of each.
Programming errors, such as an uninitialised variable; user errors, such as entering text instead of a number; and hardware failure, such as a lost connection to a printer.
What does the TRY keyword do?
TRY starts a block of code that may raise an error.
When does the code in an EXCEPT block run?
It runs only if an error occurs in the TRY block.
The keyword marks the end of the exception handling structure.
The keyword ENDTRY marks the end of the exception handling structure.
True or False?
The code inside an EXCEPT block runs every time the program is executed.
False.
The EXCEPT block runs only when an error occurs in the TRY block it belongs to.
In Python, which exception is raised when a program tries to open a file that does not exist?
A FileNotFoundError is raised.
In Python, which exception is raised by an attempt to divide by zero?
A ZeroDivisionError is raised.
Why is more than one except branch written for a single try block?
So that each type of error can be given its own specific handling and message, rather than one message covering every possible fault.
What is the purpose of a general except Exception branch at the end of the list?
It catches any error that the earlier, more specific branches did not, so an unexpected fault still leaves the program under control.
Code placed in a block runs whether or not an exception was raised, so it is used to close the file.
Code placed in a finally block runs whether or not an exception was raised, so it is used to close the file.
True or False?
In Java, dividing an integer by zero raises an ArithmeticException.
True.
Java raises an ArithmeticException, which is caught in its own catch branch.
In Java, which keyword introduces the block that handles a particular type of exception?
The catch keyword, which names the exception type it handles, as in catch (FileNotFoundException e).
Why does the finally block itself contain error handling when it closes a file?
Because the file may never have been opened successfully, so the attempt to close it could raise an error of its own.
By signing up you agree to our Terms and Privacy Policy