Important Introduction to Programming Short Questions
Chapter: 19
Question 1:
What is a potential issue when updating a record in the middle of a file?
Answer:
Replacing data with a different length can corrupt the file structure and subsequent data.
Chapter: 19
Question 2:
What is the traditional method for inserting data into the middle of a sequential file?
Answer:
The traditional method involves copying the read data into a new file until reaching the insertion point, appending the new data, skipping the data to be overwritten, and copying the remaining data.
Chapter: 19
Question 3:
Why is the traditional method for file insertion considered wasteful for large files?
Answer:
It is wasteful because it requires copying the entire file, which is time-consuming and inefficient for large files, potentially in the range of hundreds of megabytes or gigabytes.
Chapter: 19
Question 4:
What is a random access file and why is it useful?
Answer:
A random access file allows reading and writing data at any position without disturbing the file's structure, which is useful for efficient updates and insertions.
Chapter: 19
Question 5:
How does C/C++ handle file structures?
Answer:
C/C++ treats files as streams of bytes without imposing any structure, allowing for flexible handling of different file types, whether text or binary.
Chapter: 19
Question 6:
Why is it important for each record in a file to occupy the same space?
Answer:
Consistent record sizes ensure that updates or insertions do not disrupt the file structure, as changes in data length would otherwise lead to misalignment.
Chapter: 19
Question 7:
How can you efficiently locate a specific record in a file?
Answer:
By knowing the fixed size of each record and using file pointers with functions like seekg(), you can directly access the desired position without sequentially reading through the file.
Chapter: 19
Question 8:
What does the seekg() function do?
Answer:
The seekg() function moves the file pointer to a specific position in the file for reading operations.
Chapter: 19
Question 9:
What is the difference between seekg() and seekp()?
Answer:
seekg() is used for setting the file pointer position for input operations, while seekp() is used for setting the position for output operations.
Chapter: 19
Question 10:
What file mode allows both input and output operations in C++?
Answer:
The file mode ios::in