Engineering Problem Solving With C++, 3e Chapter 5 Test Bank
Engineering Problem Solving With C++, 3e Chapter 5 Test Bank
6. Read a number from the input file object MyInput into variable value
A. MyInput >> value;
B. MyInput >> cin >> value;
C. cin >> MyInput >> value;
D. value = read.MyInput();
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 the 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 the name of the file you want to open has been stored in the string object filename,
which of the following will statements will correctly open the file.
A. inFile.open(filename);
B. inFile.open(c_str.filename());
C. inFile.open(‘filename’);
D. inFile.open("filename");
13. In the class hierarchy, ifstream inherits from, or is a subclass of, the class istream.
A. True
B. False
14. A blank character can be input and stored into character variable c using the statement:
cin >> c;
A. True
B. False
15. The peek() method can be used to examine the next character in the input stream, without
actually removing it from the input stream.
A. True
B. False
16. When an input file encounters an input error and goes into the fail state an error message is
automatically generated and displayed on the output screen.
A. True
B. False
17. When an open statement is successful the stream state flag goodbit is set to 1.
A. True
B. False
18. C++ iostream class multiply inherits from both istream and ostream classes.
A. True
B. False
19. If you have an overloaded output operator that can send data to an ostream, which of the
following are possible left-hand operands to the operator:
A. cout
B. cerr
C. an instance of ofstream
D. Because all of these are kinds of ostream, this output operator may be used for all.
20. Derived classes like ifstream may only use inherited methods from the parent (base) class;
therefore ifstream has no specialized methods for working with files.
A. True
B. False
21. When an error occurs when reading from an istream, the fail bit is set on the stream and
execution of the program stops.
A. True
B. False
22. By default, C++ ofstream objects are opened in overwrite mode.
A. True
B. False
23. No prior knowledge of a file’s structure is needed to be able to read the file in C++.
A. True
B. False
24. Errors may occur when attempting to read data that is not of an appropriate type.
A. True
B. False