C++ Chapter 12 GRADE A QUESTIONS AND
ANSWERS
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 - (correct answer)C
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 - (correct answer)A
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 - (correct answer)c
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")); - (correct answer)B
, 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 - (correct answer)A
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); - (correct answer)D
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) - (correct answer)A
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 - (correct answer)B
ANSWERS
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 - (correct answer)C
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 - (correct answer)A
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 - (correct answer)c
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")); - (correct answer)B
, 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 - (correct answer)A
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); - (correct answer)D
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) - (correct answer)A
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 - (correct answer)B