Register Now

Login

Lost Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Login

Register Now

Welcome to All Test Answers

Chapter 12 Starting out with C++ Advanced File Operations


 

Download  file with the answers

Not a member!
Create a FREE account here to get access and download this file with answers


 

Chapter Twelve

MULTIPLE CHOICE

1. Data stored here disappears once the program stops running or the computer is powered down.
a. on a CD
b. in RAM
c. on a backup tape
d. on the hard disk
e. None of these

2. In order, the three-step process of using a file in a C++ program involves:
a. Insert a disk, open a file, remove the disk
b. Create the file contents, close the file, name the file
c. Open the file, read/write/save data, close the file
d. Name the file, open the file, delete the file
e. None of these

3. This data type can be used to create files and write information to them but cannot be used to read information from them.
a. ofstream
b. ifstream
c. afstream
d. outstream
e. None of these

4. This data type can be used to create files, read data from them, and write data to them.
a. ofstream
b. iftream
c. fstream
d. stream
e. None of these

5. Which statement opens a file and links it to a file stream object?
a. open(aFile) = link(anObject);
b. file.open(“c:\\filename.txt”);
c. linkstream(“filename.txt”);
d. link(open(filename.txt”));
e. None of these

6. What is true about the following statement?

out.open(“values.dat”, ios::app);

a. If the file already exists, its contents are preserved and all output is written to the end of the file.
b. If the file exists, it should be replaced with a new copy of values.dat
c. If the file exists, it can be opened but not modified
d. None of these

7. Which of the following statements opens the file info.txt for both input and output?
a. dataFile.open(“info.txt”, ios::in && ios::out);
b. dataFile.open(“info.txt”, ios::in , ios::out);
c. dataFile.open(“info.txt”, input || output);
d. dataFile.open(“info.txt”, ios::in | ios::out);

8. The _________ marker is the character that marks the end of a file, and is automatically written when the file is closed.
a. End of File (EOF)
b. No More Data (NMD)
c. Data Stream Close (DSC)
d. Data Read Stop (DRS)
e. None of these

9. This state bit can be tested to see if the end of an input stream is encountered.
a. ios::eof
b. ios::eofbit
c. ios::failbit
d. ios::badbit
e. None of these

10. This member function reads a single character from a file.
a. read
b. get
c. put
d. input
e. None of these

11. This member function can be used to store binary data to a file.
a. binary.out
b. write
c. put <<
d. dataout(binary)
e. None of these

12. To access files from a C++ program, you must use this directive:
a. #include
b. #include
c. #include
d. #include
e. None of these

13. To set up a file to perform file I/O, you must declare:
a. at least one variable, the contents of which will be written to the file
b. one or more file stream objects
c. a string object to store the file contents
d. All of these
e. None of these

14. ofstream, ifstream, and fstream are:
a. header files
b. libraries
c. data types
d. string arrays
e. None of these

15. This data type can be used to create files and read information from them into memory.
a. ofstream
b. istream
c. ifstream
d. instream
e. None of these

16. Outside of a C++ program, a file is identified by its _________. Inside a C++ program, a file is identified by a ____________.
a. file number, file name
b. file name, file number
c. name, address
d. name, file stream object
e. None of these

17. When used by itself, this access flag causes a file’s contents to be deleted if the file already exists.
a. ios::app
b. ios::in
c. ios::out
d. All of these
e. None of these

18. Which statement opens a file in such a way that information will only be written to its end?
a. dataFile(open.append(“info.dat”));
b. dataFile.open(“info.dat”, ios::out | ios::app);
c. dataFile.open = “C:\\info.dat” ios:append;
d. open(dataFile.append);
e. None of these

19. Closing a file causes any unsaved information still held in the file buffer to be
a. saved to the file.
b. deleted.
c. retained in the buffer for safekeeping.
d. duplicated.
e. None of these

20. The end-of-file marker is automatically written:
a. when a file is opened with ios::eof
b. when a file is opened with ios::app
c. when a file is closed
d. when the program ends
e. None of these

21. When a file is opened, the file stream object’s “read position” is:
a. at the end of the file
b. at the beginning of the file
c. nonexistent, until the programmer declares it
d. in the middle of the file
e. None of these

22. All stream objects have these, which indicate the condition of the stream.
a. error state bits
b. condition statements
c. markers
d. intrinsic error messages
e. None of these

23. This state bit is set when an attempted operation has failed.
a. ios::failbit
b. ios::badbit
c. ios::hardfail
d. ios::goodbit
e. None of these

24. This member function writes a single character to a file.
a. get
b. write
c. put
d. insert
e. None of these

25. This term means non-sequentially accessing information in a file.
a. linear access
b. incremented access
c. random access
d. protected access
e. None of these

TRUE/FALSE

1. True/False: When you store data in a variable, it is automatically saved in a file.

2. True/False: Only one file stream object can be declared per C++ program.

3. True/False: The ios::out flag causes the file’s existing contents to be deleted if the file already exists.

4. True/False: An alternative to using the open member function is to use the file stream object declaration itself to open the file.
Example: fstream DataFile(“names.dat”, ios::in | ios::out);

5. True/False: File output may be formatted the same way as console screen output.

6. True/False: When used by itself, the ios::app flag causes the file’s existing contents to be deleted if the file already exists.

7. True/False: When data is read from a file, it is automatically stored in a variable.

8. True/False: By default, files are opened in binary mode.

9. True/False: If a file already exists, you can open it with the flags ios::in | ios::out to preserve its contents.

10. True/False: To write to a file, you use the file_write() function.

11. True/False The setprecision manipulator cannot be used to format data written to a file.

12. True/False When passing a file stream object to a function, you should always pass it by reference.

13. True/False: The ios::hardfail bit is set when an unrecoverable error occurs.

About

Leave a reply

Captcha Click on image to update the captcha .

error: Content is protected !!