Engineering Problem Solving with C++, 3e Chapter 5 Test Bank
7. Which of the following statements will close the output file associated with the object
AnsFile?
A. close.AnsFile;
B. “myanswers.txt“.close;
C. AnsFile.close();
D. AnsFile.close(“myanswers.txt ” );
8. Which of the following repetition statements will properly repeat while not at the end of the
data file associated with the object DataFile
A. while( ! DataFile)
B. while ( ! eof())
C. while ( ! DataFile.eof())
D. while ( ! eof.DataFile())
9. Use which of the following methods to recover from an input file error?
A. undo();
B. reset();
C. recover();
D. None of the above.
10. Which of the following conditions will put an input filestream object into the fail state?
A. Opening a file which already exists and is in the same directory as the program.
B. Opening a file which does not already exist, or is not in the same directory as the
program.
C. Trying to read an integer when the next character in the file is the /n.
D. All of the above will put the file object into the fail state.
11. Given the statement outFile.open(“yourAnswers.txt”); and the output file yourAnswers.txt
already exist …
A. The file object is placed into the fail state.
B. A warning message will be printed and any output sent to the file will overwrite the
existing information in the file,
C. No warning or error message is printed and any output sent to the file will overwrite the
existing information in the file.
D. Any information sent to the file will be appended to the existing information in the file.
12. Given that the name of an existing file has been stored in the string filename, which of the
following statements will correctly open the file.
A. inFile.open(filename);
B. inFile.open(str.filename);
C. inFile.open(‘filename’);
D. inFile.open(“filename”);
13. In the istream class hierarchy, ifstream inherits from, or is a subclass of, the class istream.
A. True
B. False