Ch.6 Flashcards
What is the output of the following code?
char ch = ‘G’;
cout ≤≤ tolower(ch) ≤≤ endl;
the integer value of ‘g’
The command outFile.width(10) is used to
display the next value in at least 10 characters.
Which of the following function declarations will correctly pass an output stream to the function?
A) void display( ofstream& out);
B) void display( ostream out);
C) void display( ostream& out);
D) void display( ofstream out);
E) A and C
void display( ostream& out);
After a stream is opened, before it is used for input and output, it should be
checked to see if it opened correctly.
The command outFile.precision(2);
displays all floating point values sent to outFile with 2 decimal places.
If a file did not open correctly, you should
display an error message and take some suitable action such as exit.
Which function returns true if the character argument is a letter?
isalpha
To open a file with a user supplied name, you would need to store the name in a variable. If the file name was to have no more than 20 characters in it, which would be an appropriate declaration of the file name variable?
char filename[21];
Which of the following is the correct way to determine if a file stream named inFile opened correctly?
if( inFile.fail( ) )
A function that is associated with an object is called a ________ function.
member
What is wrong with the following code?
while( ! fileIn.eof( ) )
{
fileIn >> value;
fileout << value;
}
We have read past the end of the input file
If the name of the input file was in a variable named filename, which of the following is the correct way to open the input stream named inFile and associate it with this file?
inFile.open(filename);
The ifstream class is derived from the
istream class
ios::showpos is a flag that
always displays a + in front of positive integers.
The member function setf stands for
set the flags
When is the external name of the file used in the program?
when opening the file stream
To open an output file and add to the end of the data already in the file you would write ________.
outFile.open(“project.txt”, ios::app);
Which of the following loop condition statements will read all the data in the file assuming that each record in the file is two integer values, and you will read the first one into a variable named intOne, and the other into intTwo?
while(inFile >> intOne >> intTwo)
Which of the following function declarations will accept either cout or a file stream object as its argument?
void output( ostream &outFile);
Which statement correctly opens an input stream named in_file and attaches it to a file name project.txt?
in_file.open(“project.txt”);
A value that can be turned on or off is called a
flag
A ________ is a flow of characters or other data.
stream
The flag to always show the decimal point in floating numbers is ios::
showpoint
The manipulator used to change the number of decimal places displayed is
setprecision
The flag to display floating point numbers in non-scientific notation is ios::
fixed
In the following function declaration, the istream object cin is called a \_\_\_\_\_\_\_\_. void output(istream& in = cin);
default argument
Which command reads one character even if that character is a blank space?
get
“\n” is a ________ and ‘\n’ is a ________.
string, character
The member function eof( ) is (true/false) when we are ready to read the end of file character.
false
A type whose variables are objects is known as a
class
You may not have more than one input and one output stream open at any one time.
False
Two different objects of the same class have a different set of member functions.
False
You may use a read (extraction) as a boolean expression in an if or while statement.
True
Streams may be passed to a function.
True
You must use a width statement before each variable that you want output in a certain width
True
Using directives can be placed either directly after the include directives, or at the beginning of each function definition.
True
If you use the width command, it stays in effect for all values that are sent to the stream.
True