Chapter 12 Quiz for May 3

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

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 Answer: A

A) End of File (EOF)

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 Answer: A

A) If the file already exists, its contents are preserved and all output is written to the end of the file.

22) All stream objects have ________, which indicate the condition of the stream. A) error state bits B) condition statements C) markers D) intrinsic error messages E) None of these Answer: A

A) error state bits

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 Answer: A

A) ios::failbit

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 Answer: A

A) ofstream

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 Answer: A

A) saved to the file

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 disk drive E) None of these

B ) in RAM

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 Answer: B

B) at the beginning of the file

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 Answer: B

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

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 Answer: B

B) file.open("c:\\filename.txt");

10) This member function reads a single character from a file. A) read B) get C) put D) input E) None of these Answer: B

B) get

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 Answer: B

B) ios::eofbit

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 Answer: B

B) one or more file stream objects

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 Answer: B

B) write

12) To access files from a C++ program, you must use this directive: A) #include<fileaccess> B) #include <filestream> C) #include <fstream> D) #include <iostream> E) None of these Answer: C

C) #include <fstream>

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

C) Open the file, read/write/save data, close the file

14) ofstream, ifstream, and fstream are: A) header files B) libraries C) data types D) string arrays E) None of these Answer: C

C) data types

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 Answer: C

C) fstream

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 Answer: C

C) ifstream

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 Answer: C

C) ios::out

24) This member function writes a single character to a file. A) get B) write C) put D) insert E) None of these Answer: C

C) put

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 Answer: C

C) random access

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 Answer: C

C) when a file is closed

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); Answer: D

D) dataFile.open("info.txt", ios::in | ios::out);

16) Outside of a C++ program, a file is identified by its ________. 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 Answer: D

D) name, file stream object

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

FALSE

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

FALSE

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

FALSE

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

FALSE

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. Answer: FALSE

FALSE

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

FALSE

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

FALSE

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

TRUE

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

TRUE

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

TRUE

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); Answer: TRUE

TRUE

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

TRUE

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

TRUE


Set pelajaran terkait

FIN240 Case Problem Analysis 4.1

View Set

Ch 1: Network Topologies: Questions (Exam Cram)

View Set

The Giver Chapter 7-9 Vocabulary

View Set

Three Possible Driving Forces Of Plate Tectonics

View Set

Help Desk Customer Service Quiz #9(slides, part two)

View Set

Organizations and Human Capital Final Exam

View Set