Ch.12 Test Questions & Answers Advanced File Operations - Test Bank | C++ Control Structures 9e by Tony Gaddis. DOCX document preview.

Ch.12 Test Questions & Answers Advanced File Operations

Starting Out with C++ from Control Structures to Objects, 9e (Gaddis)

Chapter 12 Advanced File Operations

TRUE/FALSE

1. When you store data in a variable, it is automatically saved in a file.

2. Only one file stream object can be declared per C++ program.

3. The ios::out flag causes the file's existing contents to be deleted if the file already exists.

4. When used by itself, the ios::app flag causes the file's existing contents to be deleted if the file already exists.

5. An alternative to using the open member function is to use the file stream object declaration itself to open the file. For example:

fstream DataFile("names.dat", ios::in | ios::out);

6. File output may be formatted the same way as console screen output.

7. When data is read from a file, it is automatically stored in a variable.

8. By default, files are opened in binary mode.

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

10. To write to a file, you use the file_write function.

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

12. The ios::hardfail bit is set when an unrecoverable error occurs.

13. When passing a file stream object to a function, you should always pass it by reference.

MULTIPLE CHOICE

1. Data stored __________ disappears once the program stops running or the computer is powered down.

a.

on a CD

b.

in RAM

c.

on a flash drive

d.

on the disk drive

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 the 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. Which of the following is the data type that 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. Which of the following is the data type that can be used to create files, read data from them, and write data to them?

a.

ofstream

b.

ifstream

c.

fstream

d.

stream

e.

None of these

5. Which of the following statements opens a file and links it to a file stream object?

a.

open(aFile) = link(anObject);

b.

file.open("filename.txt");

c.

linkstream("filename.txt");

d.

link(open("filename.txt");

e.

None of these

6. Which of the following statements opens a file named 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);

e.

None of these

7. Which of the following is the state bit that 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

8. Which of the following is the member function that reads a single character from a file?

a.

read

b.

get

c.

put

d.

input

e.

None of these

9. Which of the following is the member function that can be used to store binary data to a file?

a.

binary.out

b.

write

c.

put <<

d.

dataout(binary)

e.

None of these

10. Which of the following is the directive you must use to access files from a C++ program?

a.

#include <fileaccess>

b.

#include <filestream>

c.

#include <fstream>

d.

#include <iostream>

e.

None of these

11. 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

12. 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 already exists, it should be replaced with a new copy of values.dat.

c.

If the file already exists, it can be opened but not modified.

d.

None of these

13. To set up a file to perform 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. Outside of a C++ program, a file is identified by its __________while inside a C++ program, a file is identified by a(n) __________.

a.

file number, file name

b.

file name, file number

c.

name, address

d.

name, file stream object

e.

None of these

16. Which of the following data types 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

17. Which statement opens a file in such a way that information will only be written to the end of the file?

a.

dataFile(open.append("info.dat");

b.

dataFile.open("info.dat", ios::out | ios::app);

c.

datFile.open = "c:\\info.dat" ios::append;

d.

open(dataFile.append);

e.

None of these

18. Which of the following access flags, when used by itself, causes a file's contents to be deleted if the file already exists?

a.

ios::app

b.

ios::in

c.

ios::out

d.

Any of these

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 __________ which indicate the position of the stream.

a.

error state bits

b.

condition statements

c.

markers

d.

intrinsic error messages

e.

None of these

23. Which of the following is the state bit that is set when an attempted operation fails?

a.

ios::failbit

b.

ios::badbit

c.

ios::hardfail

d.

ios::goodbit

e.

None of these

24. Which of the following is the member function that writes a single character to a file?

a.

get

b.

write

c.

put

d.

insert

e.

None of these

25. Which of the following means accessing information from a file non-sequentially?

a.

linear access

b.

incremented acces

c.

random access

d.

protected access

e.

None of these

Document Information

Document Type:
DOCX
Chapter Number:
12
Created Date:
Aug 21, 2025
Chapter Name:
Chapter 12 Advanced File Operations
Author:
Tony Gaddis

Connected Book

Test Bank | C++ Control Structures 9e

By Tony Gaddis

Test Bank General
View Product →

$24.99

100% satisfaction guarantee

Buy Full Test Bank

Benefits

Immediately available after payment
Answers are available after payment
ZIP file includes all related files
Files are in Word format (DOCX)
Check the description to see the contents of each ZIP file
We do not share your information with any third party