Chapter 23 – C How to Program 6e Multiple Choice Test Bank
Download file with the answers
Chapter 23 - C How to Program 6e Multiple Choice Test Bank
1 file(s) 213.51 KB
Not a member!
Create a FREE account here to get access and download this file with answers
Chapter 23: Stream Input/Output
Section 23.1 Introduction
23.1 Q1: Which of the following statements is not true about C++ input/output (I/O) features?
a. C++ allows users to specify I/O for their own data types.
b. C++ automatically calls the correct I/O operations for standard types.
c. C++ has some object-oriented I/O features.
d. C++ borrowed its type safe I/O capabilities from C.
Section 23.2 Streams
23.2 Q1: Select the correct statement regarding C++ I/O streams:
a. C++ provides only high-level I/O capabilities because it is a high-level programming language.
b. High-level (formatted) I/O is best for large-volume transfers.
c. Low-level I/O breaks information down into small, meaningful groups of related bytes.
d. Programmers generally prefer high-level I/O to low-level I/O.
23.2 Q2: __________ is usually faster than __________.
a. High-level I/O, low-level I/O.
b. Low-level I/O, high-level I/O.
c. Low-level I/O, internal data processing.
d. High-level I/O, internal data processing.
Section 23.2.1 Classic Streams vs. Standard Streams
23.2.1 Q1: Which C++ data type was designed to store Unicode characters?
a. char
b. long
c. wchar_t
d. size_t
Section 23.2.2 iostream Library Header Files
23.2.2 Q1: Which of the following libraries does not deal with input/output?
a. iostream
b. iomanip
c. fstream
d. fiostream
Section 23.2.3 Stream Input/Output Classes and Objects
23.2.3 Q1: Which of the following classes is a base class of the other three?
a. basic_ios
b. basic_istream
c. basic_ostream
d. basic_iostream
Q2: Which of the following is not a member of the ostream class?
a. cout
b. cerr
c. cin
d. clog
23.2.3 Q3: Which of the following classes is deepest in the inheritance hierarchy?
a. basic_iostream
b. basic_ofstream
c. basic_ifstream
d. basic_fstream
ANS d. basic_fstream
Section 23.3 Stream Output
23.3 Q1: Which of the following is not a member function of the C++ ostream class?
a. Stream-insertion operator (<<). b. Stream-extraction operator (>>).
c. put.
d. write.
ANS b. Stream-extraction operator (>>).
Section 23.3.1 Output of char * Variables
23.3.1 Q1: Which of the following prints the address of character string string given the following declaration?
char * string = “test”;
a. cout << string;
b. cout << *&string;
c. cout << static_cast< void * >( string );
d. cout << * string;
Section 23.3.2 Character Output using Member Function put
23.3.2 Q1: Which of the following is an illegal use of function put?
a. cout.put( ‘A’ );
b. cout.put( “A” );
c. cout.put( ‘A’ ).put( ‘\n’ );
d. cout.put( 65 );
Section 23.4 Stream Input
23.4 Q1: The stream-extraction operator:
a. Does not normally accept white-space characters.
b. Returns true when the end-of-file is encountered.
c. Sets the stream’s failbit if the operation fails.
d. Sets the stream’s badbit if the data is of the wrong type.
Section 23.4.1 get and getline Member Functions
23.4.1 Q1: One difference between the three-argument version of the get function and the getline function is that:
a. Only get has a delimiter.
b. The getline function removes the delimiter from the stream.
c. Only get adds the delimiter to the array.
d. getline stores the characters it reads into its character array argument.
Section 23.4.2 istream Member Functions peek, putback and ignore
23.4.2 Q1: The putback member function returns to the input stream the previous character obtained by:
a. A get from the input stream.
b. Using the stream extraction operator on the input stream.
c. Reading input from the keyboard.
d. Reading a file from disk.
23.4.2 Q2: Upon encountering the designated delimiter character, the ignore member function will:
a. Read it in and return its value.
b. Ignore it and continue reading and discarding characters.
c. Terminate.
d. Replace it with an EOF character.
Section 23.4.3 Type-Safe I/O
23.4.3 Q1: If unexpected data is processed in an I/O operation:
a. An exception will be thrown.
b. An error message will automatically be displayed.
c. The program will terminate execution.
d. Various error bits will be set.
Section 23.5 Unformatted I/O using read, write and gcount
23.5 Q1: Which of the following is a difference between the read and write functions?
a. One performs formatted I/O and the other does not.
b. They take different types of parameters.
c. write and gcount are member functions of the same class, whereas read is not.
d. The failbit is set only with read.
Section 23.6 Introduction to Stream Manipulators
Section 23.6.1 Integral Stream Base: dec, oct, hex and setbase
23.6.1 Q1: Which of the following is not a difference between hex and setbase?
a. setbase is a parameterized stream manipulator and hex is not.
b. setbase is provided by a different header file than hex.
c. setbase(16) and hex have different effects on stream output.
d. setbase takes an argument but hex does not.
Section 23.6.2 Floating-Point Precision (precision, setprecision)
23.6.2 Q1: What will be output by the following statements?
double x = 1.23456789;
cout << fixed;
cout << setprecision(5) << x << endl;
cout.precision(3);
cout << x << endl;
cout << x << endl;
a. 1.2346
1.23
1.23
b. 1.23457
1.235
1.23456789
c. 1.2346
1.23
1.23456789
d. 1.23457
1.235
1.235
Section 23.6.3 Field Width (width, setw)
23.6.3 Q1: Which of the following is not true about setw and width?
a. If the width set is not sufficient the output prints as wide as it needs.
b. They are used to set the field width of output.
c. Both of them can perform two tasks, setting the field width and returning the current field width.
d. They only apply for the next insertion/extraction.
Section 23.6.4 User-Defined Output Stream Manipulators
23.6.4 Q1: Which of the following is a valid user-defined output stream manipulator header?
a. ostream& tab( ostream& output )
b. ostream tab( ostream output )
c. istream& tab( istream output )
d. void tab( ostream& output )
Section 23.7 Stream Format States and Stream Manipulators
Section 23.7.1 Trailing Zeros and Decimal Points (showpoint)
23.7.1 Q1: What will be output by the following statement?
cout << showpoint << setprecision(4) << 11.0 << endl;
a. 11
b. 11.0
c. 11.00
d. 11.000
Section 23.7.2 Justification (left, right and internal)
23.7.2 Q1: Which of the following stream manipulators causes an outputted number’s sign to be left justified, its magnitude to be right justified and the center space to be filled with fill characters?
a. left
b. right
c. internal
d. showpos
Section 23.7.3 Padding (fill, setfill)
23.7.3 Q1: Which of the following statements restores the default fill character?
a. cout.defaultFill();
b. cout.fill();
c. cout.fill( 0 );
d. cout.fill( ‘ ‘ );
Section 23.7.4 Integral Stream Base (dec, oct, hex, showbase)
23.7.4 Q1: When the showbase flag is set:
a. The base of a number precedes it in brackets.
b. Decimal numbers are not output any differently.
c. “oct” or “hex” will be displayed in the output stream.
d. Octal numbers can appear in one of two ways.
Section 23.7.5 Floating-Point Numbers; Scientific and Fixed Notation (scientific, fixed)
23.7.5 Q1: What will be output by the following statements?
double x = .0012345;
cout << fixed << x << endl;
cout << scientific << x << endl;
a. 1.234500e-003
0.001235
b. 1.23450e-003
0.00123450
c. .001235
1.234500e-003
d. 0.00123450
1.23450e-003
1.234500e-003
Section 23.7.6 Uppercase/Lowercase Control (uppercase)
23.7.6 Q1: Which of the following outputs does not guarantee that the uppercase flag has been set?
a. All hexadecimal numbers appear in the form 0X87.
b. All numbers written in scientific notation appear the form 6.45E+010.
c. All text outputs appear in the form SAMPLE OUTPUT.
d. All hexadecimal numbers appear in the form AF6.
ANS: c. All text outputs appear in the form SAMPLE OUTPUT.
Section 23.7.7 Specifying Boolean Format (boolalpha)
23.7.7 Q1: Which of the following is not true about bool values and how they’re output with the output stream?
a. The old style of representing true/false values used -1 to indicate false and 1 to indicate true.
b. A bool value outputs as 0 or 1 by default.
c. Stream manipulator boolalpha sets the output stream to display bool values as the strings “true” and “false”.
d. Both boolalpha and noboolalpha are “sticky” settings.
Section 23.7.8 Setting and Resetting the Format State via Member Function flags
23.7.8 Q1: To reset the format state of the output stream:
a. Call the reset member function.
b. Call the flags member function with the ios_base::fmtflags constant as the argument.
c. Save a copy of the fmtflags value returned by calling member function flags before making any format changes, and then call flags again with that fmtflags value as the argument.
d. You must manually apply each individual format change member function or stream manipulator to restore the default format state.
Section 23.8 Stream Error States
23.8 Q1: The good member function will return false if:
a. The eof member function would return true.
b. The bad member function would return true.
c. The failbit member function would return true.
d. Any of the above.
23.8 Q2: The difference between the operator! member function and the operator void* member function is that:
a. They always return opposite boolean values.
b. They occasionally return opposite boolean values.
c. Of the two member functions, only operator! checks if eof has been set.
d. Of the two member functions, only operator void* checks if eof has been set.
Section 23.9 Tying an Output Stream to an Input Stream
23.9 Q1: Select the false statement. Outputs are:
a. Flushed automatically at the end of a program.
b. Flushed when the buffer fills.
c. Able to be synchronized with inputs.
d. Never automatically tied to inputs.
23.9 Q2: Untying an input stream, inputStream, from an output stream, outputStream, is done with the function call:
a. inputStream.untie().
b. inputStream.untie( &outputStream ).
c. inputStream.tie().
d. inputStream.tie( 0 ).
Leave a reply