CS316 Lab __ CH 14 : File Processing

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

Q11. In C++, how can you check if a file was opened successfully? a) By checking the return value of the open() function b) By using the close() function c) By checking the file's size d) By using the read() function

a) By checking the return value of the open() function

Q22. What is the significance of object serialization in C++? a) It converts objects to binary data for storage or transmission b) It converts objects to text format for readability c) It converts objects to JSON format d) It converts objects to XML format

a) It converts objects to binary data for storage or transmission

Q27. What is the primary purpose of the `std::ios::in` flag when opening a file in C++? a) Opens the file for input b) Opens the file for output c) Opens the file for reading and writing d) Opens the file in binary mode

a) Opens the file for input

Q17. What is the primary advantage of using random-access files over sequential files in C++? a) Random-access files are faster to read and write. b) Random-access files use less memory. c) Random-access files are easier to implement. d) Random-access files do not support concurrent access.

a) Random-access files are faster to read and write.

Q23. In C++, what is the purpose of the `reinterpret_cast` operator in file handling? a) To convert between different pointer types b) To convert between different data types c) To convert between text and binary data d) To convert between integer and floating-point data

a) To convert between different pointer types

Q3. What is the purpose of the bool operator overload in file handling in C++? a) To test whether a file was opened successfully b) To close a file c) To process data from the file d) To write data to the file

a) To test whether a file was opened successfully

Q19. Which function is used to delete a file in C++? a) remove() b) delete() c) erase() d) destroy()

a) remove()

Q24. Which function is used to convert objects to strings in C++ file handling? a) to_string() b) toString() c) stringify() d) serialize()

a) to_string()

Q28. Which function is used to truncate a file to a specified length in C++? a) truncate() b) resize() c) shrink() d) cut()

a) truncate()

Q25. What does the `std::ios::app` flag indicate when opening a file in C++? a) Opens the file in text mode b) Appends data to the end of the file c) Opens the file for binary reading d) Sets the file-position pointer to the end of the file

b) Appends data to the end of the file

Q20. What is the main purpose of the `std::ios::binary` flag in C++ file handling? a) Opens the file for binary reading b) Opens the file for binary writing c) Opens the file for binary appending d) Opens the file in text mode

b) Opens the file for binary writing

Q26. How are sequential files different from random-access files in C++? a) Sequential files allow data access at any position, while random-access files only allow sequential access. b) Random-access files allow data access at any position, while sequential files only allow sequential access. c) Sequential files and random-access files are the same in terms of data access. d) Sequential files are more efficient for reading, while random-access files are more efficient for writing.

b) Random-access files allow data access at any position, while sequential files only allow sequential access.

Q14. What does the function `seekg()` do in C++ file handling? a) Writes data to a specific position in the file b) Reads data from a specific position in the file c) Closes the file d) Opens the file for reading

b) Reads data from a specific position in the file

Q15. In C++, what does the `tellg()` function return? a) The size of the file b) The current position of the file-position pointer for input c) The current position of the file-position pointer for output d) The number of characters in the file

b) The current position of the file-position pointer for input

Q30. What happens if the `std::ofstream` object is not closed after writing to a file in C++? a) The file will be automatically closed. b) The data written to the file will be lost. c) The file will remain open but in read-only mode. d) The file will become corrupted.

b) The data written to the file will be lost

Q6. What is the purpose of object serialization in C++? a) To convert objects to strings b) To convert objects to binary data c) To convert objects to integers d) To convert objects to floating-point numbers

b) To convert objects to binary data

Q8. What is the primary function of the ostream member function write in C++? a) To open a file for writing b) To write bytes to a file c) To read bytes from a file d) To close a file

b) To write bytes to a file

Q21. Which function is used to read data sequentially from a random-access file in C++? a) seekg() b) read() c) write() d) put()

b) read()

Q10. What is the significance of the file-position pointer in C++ file handling? a) It indicates the end of the file. b) It points to the last byte written in the file. c) It tracks the current position for reading or writing in the file. d) It marks the beginning of the file.

c) It tracks the current position for reading or writing in the file

Q5. How are random-access files different from sequential files in C++? a) Random-access files can only be read sequentially. b) Sequential files can only be read randomly. c) Random-access files allow both reading and writing at any position. d) Sequential files allow reading only from the beginning.

c) Random-access files allow both reading and writing at any position

Q18. What does the `std::ios::ate` flag indicate when opening a file in C++? a) Appends data to the end of the file b) Opens the file in text mode c) Sets the file-position pointer to the end of the file d) Opens the file in binary mode

c) Sets the file-position pointer to the end of the file

Q29. What does the `tellp()` function return in C++ file handling? a) The current position of the file-position pointer for input b) The size of the file c) The current position of the file-position pointer for output d) The number of characters in the file

c) The current position of the file-position pointer for output

Q1. What is the purpose of opening a file in C++? a) To declare variables b) To define macros c) To read data from the file d) To process data in the file

c) To read data from the file

Q12. What is the main purpose of the write() function in C++ file handling? a) To read data from a file b) To open a file for writing c) To write data to a file d) To close a file

c) To write data to a file

Q4. In C++, what is the purpose of the write function in relation to file handling? a) To open a file for writing b) To read data from a file c) To write data to a file d) To close a file

c) To write data to a file

Q2. Which member function is used to open a file in C++? a) read() b) write() c) open() d) close()

c) open()

Q16. Which function is used to write data randomly to a random-access file in C++? a) put() b) get() c) write() d) read()

c) write()

Q13. Which mode should be used when opening a file for binary output in C++? a) "w" b) "r" c) "a" d) "wb"

d) "wb"

Q9. What is the purpose of reading data from a sequential file in C++? a) To declare variables b) To define macros c) To write data to the file d) To process data from the file

d) To process data from the file

Q7. Which operator is used to convert between pointer types in C++? a) & b) * c) -> d) reinterpret_cast

d) reinterpret_cast


Set pelajaran terkait

Interpersonal Communication Final

View Set

NU270 Week 3 PrepU: Health, Wellness, & Illness

View Set

British Empire in Asia, Africa, and the Pacific

View Set

TESTING AND MEASURE FINAL, PART 3

View Set

Hiltz PHIL1317 Quiz 1,2,3,4,5,6,7,8. True/False + Box Words

View Set

Unit 21: NC Statutes and Regulations

View Set