T4Tutorials .PK

VU Past Papers CS201-Most Importants MCQs on Random Access

Q#1: What is the purpose of the seekg() and tellg() functions in C++?
(A) To read characters from a file
(B) To determine the length of a file
(C) To search for specific data in a file
(D) To insert data in the middle of a file
Answer: (B) To determine the length of a file

Q#2: How can seekg() and tellg() be used to find the actual data length of a file?
(A) By moving to the beginning of the file and using
(B) By moving to the end of the file and using
(C) By moving 10 bytes from the beginning and using
(D) By moving 0 bytes from the end and using
Answer: (B) By moving to the end of the file and using

Q#3: Why can the size of a file be greater than the actual data length of the file?
(A) Due to inefficient disk operations
(B) Because of electromagnetic devices
(C) File storage complexity
(D) Disk blocks allocation
Answer: (D) Disk blocks allocation

Q#4: What is the main drawback of the Merge Method for inserting data in the middle of a file?
(A) It requires a lot of computation
(B) It is wasteful in terms of time and space
(C) It cannot handle large-sized data
(D) It disturbs the file structure
Answer: (B) It is wasteful in terms of time and space

Q#5: What is the key element in resolving the issue of insertion in the middle of a file without disturbing the file structure?
(A) Serial numbers
(B) File sorting
(C) Constant record length
(D) Merge method
Answer: (C) Constant record length

Q#6: In C++, what function is used for output during the process of writing to a file?
(A) –
(B) –
(C) –
(D) tellp()
Answer: (D) tellp()

Q#7: What happens when a file is opened with ifstream in C++?
(A) It can only be used for output
(B) It can only be used for input
(C) It can be used for both input and output
(D) It cannot be used for input or output
Answer: (B) It can only be used for input

Q#8: Which operation is performed to open a file in both input and output modes using fstream in C++?
(A) AND (&&)
(B) OR (||)
(C) NOT (!)
(D) XOR (^)
Answer: (B) OR (||)

Q#9: Why is the OR (||) operation used when opening a file in both input and output modes in C++?
(A) To ensure the file is opened in input mode
(B) To ensure the file is opened in output mode
(C) To achieve both input and output behavior
(D) To prevent opening the file in any mode
Answer: (C) To achieve both input and output behavior

Q#10: What does the ios::end flag represent in the context of file handling in C++?
(A) The beginning of the file
(B) The current file position
(C) The end of the file
(D) The size of the file
Answer: (C) The end of the file

Q#11: How can seekg() be used to move to a specific position in a file without loops or comparisons?
(A) By specifying the position directly
(B) By using to calculate the position
(C) By using brute force technique
(D) By using seekp() instead
Answer: (A) By specifying the position directly

Q#12: What is the purpose of the tellp() function in C++?
(A) To read characters from a file
(B) To determine the length of a file
(C) To search for specific data in a file
(D) To get the current output file position
Answer: (D) To get the current output file position

Q#13: When using fstream, what does ios::in || ios::out passed into the open() function signify?
(A) Input mode only
(B) Output mode only
(C) Both input and output modes
(D) Neither input nor output modes
Answer: (C) Both input and output modes

Q#14: What does a constant record length in a file help to achieve?
(A) Efficient disk operations
(B) Quick random access
(C) Data compression
(D) Insertion in the middle of a file
Answer: (B) Quick random access

Q#15: What is the significance of a key in a file in the context of data updation?
(A) It helps in file sorting
(B) It ensures constant record length
(C) It is used to locate a specific record
(D) It prevents file corruption
Answer: (C) It is used to locate a specific record

Q#16: In what situation is the Merge Method used for inserting data into a file?
(A) When the data size is small
(B) When the file is not sorted
(C) When the data is in gigabytes
(D) When there are holes in student ids
Answer: (A) When the data size is small

Q#17: What is the algorithm of the Merge Method for inserting data in the middle of a sequential file?
(A) Open the data file and an empty file, read and copy data until the insertion point, insert new data, skip overwritten data, and copy remaining data.
(B) Use seekg() and tellg() to locate the insertion point, then directly insert new data.
(C) Sort the file, then directly insert new data.
(D) Perform a brute force search for the insertion point and then insert new data.
Answer: (A) Open the data file and an empty file, read and copy data until the insertion point, insert new data, skip overwritten data, and copy remaining data.

Q#18: Why are disks divided into logical blocks when storing files?
(A) To increase disk speed
(B) To simplify file storage
(C) To prevent data corruption
(D) To minimize wastage of disk space
Answer: (D) To minimize wastage of disk space

Q#19: How does seekg() help in determining the actual data length of a file?
(A) By moving to the end of the file and using tellg() to get the position
(B) By reading every byte of the file sequentially
(C) By comparing file size with disk block size
(D) By moving to the beginning of the file
Answer: (A) By moving to the end of the file and using tellg() to get the position

Q#20: What is the primary reason for employing seekg() and tellg() when updating data in the middle of a file?
(A) To allow direct random access to a record without reading the entire file
(B) To compress file data
(C) To encrypt the file
(D) To check for file corruption
Answer: (A) To allow direct random access to a record without reading the entire file

Exit mobile version