0% found this document useful (0 votes)
298 views4 pages

Engineering Problem Solving With C++, 3e Chapter 5 Test Bank

This document contains a test bank of multiple choice questions about input and output file streams in C++. There are 25 questions covering topics like declaring input file objects, opening and closing files, reading from and writing to files, and error handling for file streams. Correct answers are provided for self-assessment.

Uploaded by

noora
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
298 views4 pages

Engineering Problem Solving With C++, 3e Chapter 5 Test Bank

This document contains a test bank of multiple choice questions about input and output file streams in C++. There are 25 questions covering topics like declaring input file objects, opening and closing files, reading from and writing to files, and error handling for file streams. Correct answers are provided for self-assessment.

Uploaded by

noora
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Engineering Problem Solving with C++, 3e Chapter 5 Test Bank

1. The class name used to declare an input file is …


A. inFile
B. ifstream
C. iostream
D. istream
2. Which include statement must you use to define and use input file streams
A. #include <ifstream>
B. #include <filestream>
C. #include <cstream>
D. #include <fstream>
3. Which of the following statements correctly declares the input file object MyInput and
initializes the file object to stream from the file exam.txt?
A. ifstream MyInput("exam.txt");
B. MyInput ifstream("exam.txt");
C. ifstream MyInput(exam.txt);
D. MyInput ifstream(exam.txt);
4. Which of the following statements correctly opens the output file myanswers.txt ?
A. AnsFile.open("myanswers.txt");
B. open.AnsFile("myanswers.txt");
C. open.AnsFile(myanswers.txt);
D. AnsFile.open(myanswers.txt);
5. Which of the following statements will properly store the value of the variable value into the
output file object AnsFile?
A. AnsFile << value;
B. AnsFile << cout << value;
C. cout << AnsFile << value;
D. store.AnsFile(value);

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();

©2017 Pearson Education, Inc. Hoboken, NJ. All Rights Reserved.


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

©2017 Pearson Education, Inc. Hoboken, NJ. All Rights Reserved.


Engineering Problem Solving with C++, 3e Chapter 5 Test Bank

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

©2017 Pearson Education, Inc. Hoboken, NJ. All Rights Reserved.


Engineering Problem Solving with C++, 3e Chapter 5 Test Bank

24. Errors may occur when attempting to read data that is not of an appropriate type.
A. True
B. False

25. Select ALL of the following that are considered whitespace:


A. The blank character.
B. The tab character.
C. The newline character.
D. The carriage return character.
E. The form feed character.

©2017 Pearson Education, Inc. Hoboken, NJ. All Rights Reserved.

You might also like