Deck 6: Io Streams As an Introduction to Objects and Classes

Full screen (f)
exit full mode
Question
Streams may be passed to a function.
Use Space or
up arrow
down arrow
to flip the card.
Question
'\n' is two characters.
Question
A type whose variables are objects is known as a ___________.
Question
Two different objects of the same class have a different set of member functions.
Question
Using directives can be placed either directly after the include directives,or at the beginning of each function definition.
Question
You must use a width statement before each variable that you want output in a certain width
Question
Which command reads one character even if that character is a blank space? ___________
Question
A _____________ is a flow of characters or other data.
Question
When passing a stream to a function,it must always be pass-by-__________.
Question
open is a __________ function of the ofstream and ifstream class.
Question
The flag to display floating point numbers in non-scientific notation is ios:: _________
Question
You may not have more than one input and one output stream open at any one time.
Question
A value that can be turned on or off is called a ________.
Question
The manipulator used to change the number of decimal places displayed is _________
Question
The flag to always show the decimal point in floating numbers is ios:: _________
Question
If you use the width command,it stays in effect for all values that are send to the stream.
Question
All data is input and output as ____________ data.
Question
The formatting options that were discussed for cout do not work for output file streams.
Question
You may use a read extraction)as a boolean expression in an if or while statement.
Question
Data that is sent to an output stream representing a file will be immediately saved to disk.
Question
Which of the following is the correct way to determine if a file stream named inFile opened correctly?

A)if inFile.open))
B)if inFile.fail))
C)if inFile.opened))
D)if inFile.failed))
Question
Which statement correctly opens an input stream named in_file and attaches it to a file name project.txt?

A)in_file=project.txt
B)in_file="project.txt"
C)in_file.open"project.txt");
D)in_file.openproject.txt);
Question
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?

A)char filename;
B)char filename20);
C)char filename[20];
D)char filename[21];
Question
The command outFile.precision2);

A)truncates all floating point variables to 2 decimal places
B)sets all output streams in your program to display 2 secimal places
C)displays integers as floating point numbers.
D)displays all floating point values sent to outFile with 2 decimal places.
Question
To open an output file and add to the end of the data already in the file you would write

A)outFile.open"project.txt");
B)outFile.append"project.txt");
C)outFile.open"project.txt",append);
D)outFile.open"project.txt",ios::app);
Question
Which of the following is not used when using files for input and output

A)Opening the file stream
B)Ensuring that the stream opened
C)Closing the stream
D)Prompting for file data
Question
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?

A)inFile.openfilename);
B)inFile=filename;
C)inFile="filename";
D)inFile.open"filename");
Question
The member function eof)is true/false)when we are ready to read the end of file character.
Question
The _______ function puts one character back into the input stream.
Question
Which of the following is the correct way to close a file stream named outFile?

A)outFile.close);
B)outFile.close;
C)outFile.close"project.txt");
D)closeoutFile);
Question
Which include directive is necessary for file IO

A)#include
B)#include
C)#include
D)#include
Question
If a file did not open correctly,you should

A)continue on anyway
B)display an error message and continue on
C)display an error message and take some suitable action such as exit
D)exit the program immediately
Question
After a stream is opened,before it is used for input and output,it should be

A)declared
B)closed
C)checked to see if it opened correctly
D)none of the above
Question
When is the external name of the file used in the program?

A)Any time you read or write to the file
B)Never
C)Only when reading from the file
D)When opening the file stream
Question
In the following function declaration,the istream object cin is called a ___________________.
void outputistream& in=cin);
Question
"\n" is a ________ and '\n' is a _______________.
Question
In order to read data from a file you

A)must know the kind of data in the file
B)do not need to know the kind of data in the file
C)should prompt the user for the data you are looking for
D)a and c
Question
A __________ is a variable that has functions as well as data associated with it.

A)member
B)int
C)object
D)float
Question
A function that is associated with an object is called a _________ function.

A)input
B)output
C)member
D)instantiated
Question
The member function setf stands for

A)set the file name
B)set the flags
C)set the format
D)nothing
Question
We have a file that has a name in it,but the name is written one character per line.We need to write this name to the screen.What is wrong with the following code?
Ifstream fileIn;
FileIn.open"file.txt");
Char ch;
FileIn.getch)
While!fileIn.eof))
{
Cout.putch);
FileIn.getch);
}

A)can not use put with cout.
B)our output has new lines in it.
C)nothing is wrong
D)eof is not a member of an ifstream object
Question
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?

A)whileinFile >> intOne >> intTwo)
B)whileinFileintOne,intTwo))
C)whileinFile)
D)whileinFile << intOne << intTwo)
E)A and B
Question
What is the output of the following code?
Char ch='G';
Cout << tolowerch)<< endl;

A)G
B)g
C)the integer value of 'g'
D)the integer value of 'G'
Question
In order to use the stream manipulators,you must include the ______ library

A)manip
B)iomanip
C)cstdlib
D)fstream
Question
If the user types in the characters 10,and your program reads them into an integer variable,what is the value stored into that integer?

A)1
B)0
C)10
D)none of the above.
Question
What is wrong with the following code?
While ! fileIn.eof))
{
FileIn >> value;
FileOut << value;
}

A)We have read past the end of the input file and attempt to output a nonexistent value
B)We have written past the end of the output file
C)Nothing
D)A and B
Question
Which function returns true if the character argument is a letter?

A)isdigit
B)islower
C)isalpha
D)isspace
Question
The put function outputs

A)one character value
B)one float value
C)one integer value
D)one double value
Question
ios::showpos is a flag that

A)always displays a + in front of positive integers
B)can be used to find the absolute value of an integer
C)always displays a + in front of all integers
D)all of the above
Question
The command outFile.width10)is used to

A)change the number of characters in the output
B)sets the filename of outFile to 10 characters
C)always uses 10 characters to display the output
D)displays the next value in at least 10 characters
Question
The get function reads

A)one integer value
B)one float value
C)one double value
D)one character value
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/51
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 6: Io Streams As an Introduction to Objects and Classes
1
Streams may be passed to a function.
True
2
'\n' is two characters.
False
3
A type whose variables are objects is known as a ___________.
class
4
Two different objects of the same class have a different set of member functions.
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
5
Using directives can be placed either directly after the include directives,or at the beginning of each function definition.
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
6
You must use a width statement before each variable that you want output in a certain width
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
7
Which command reads one character even if that character is a blank space? ___________
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
8
A _____________ is a flow of characters or other data.
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
9
When passing a stream to a function,it must always be pass-by-__________.
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
10
open is a __________ function of the ofstream and ifstream class.
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
11
The flag to display floating point numbers in non-scientific notation is ios:: _________
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
12
You may not have more than one input and one output stream open at any one time.
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
13
A value that can be turned on or off is called a ________.
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
14
The manipulator used to change the number of decimal places displayed is _________
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
15
The flag to always show the decimal point in floating numbers is ios:: _________
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
16
If you use the width command,it stays in effect for all values that are send to the stream.
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
17
All data is input and output as ____________ data.
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
18
The formatting options that were discussed for cout do not work for output file streams.
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
19
You may use a read extraction)as a boolean expression in an if or while statement.
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
20
Data that is sent to an output stream representing a file will be immediately saved to disk.
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
21
Which of the following is the correct way to determine if a file stream named inFile opened correctly?

A)if inFile.open))
B)if inFile.fail))
C)if inFile.opened))
D)if inFile.failed))
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
22
Which statement correctly opens an input stream named in_file and attaches it to a file name project.txt?

A)in_file=project.txt
B)in_file="project.txt"
C)in_file.open"project.txt");
D)in_file.openproject.txt);
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
23
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?

A)char filename;
B)char filename20);
C)char filename[20];
D)char filename[21];
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
24
The command outFile.precision2);

A)truncates all floating point variables to 2 decimal places
B)sets all output streams in your program to display 2 secimal places
C)displays integers as floating point numbers.
D)displays all floating point values sent to outFile with 2 decimal places.
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
25
To open an output file and add to the end of the data already in the file you would write

A)outFile.open"project.txt");
B)outFile.append"project.txt");
C)outFile.open"project.txt",append);
D)outFile.open"project.txt",ios::app);
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
26
Which of the following is not used when using files for input and output

A)Opening the file stream
B)Ensuring that the stream opened
C)Closing the stream
D)Prompting for file data
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
27
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?

A)inFile.openfilename);
B)inFile=filename;
C)inFile="filename";
D)inFile.open"filename");
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
28
The member function eof)is true/false)when we are ready to read the end of file character.
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
29
The _______ function puts one character back into the input stream.
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
30
Which of the following is the correct way to close a file stream named outFile?

A)outFile.close);
B)outFile.close;
C)outFile.close"project.txt");
D)closeoutFile);
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
31
Which include directive is necessary for file IO

A)#include
B)#include
C)#include
D)#include
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
32
If a file did not open correctly,you should

A)continue on anyway
B)display an error message and continue on
C)display an error message and take some suitable action such as exit
D)exit the program immediately
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
33
After a stream is opened,before it is used for input and output,it should be

A)declared
B)closed
C)checked to see if it opened correctly
D)none of the above
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
34
When is the external name of the file used in the program?

A)Any time you read or write to the file
B)Never
C)Only when reading from the file
D)When opening the file stream
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
35
In the following function declaration,the istream object cin is called a ___________________.
void outputistream& in=cin);
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
36
"\n" is a ________ and '\n' is a _______________.
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
37
In order to read data from a file you

A)must know the kind of data in the file
B)do not need to know the kind of data in the file
C)should prompt the user for the data you are looking for
D)a and c
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
38
A __________ is a variable that has functions as well as data associated with it.

A)member
B)int
C)object
D)float
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
39
A function that is associated with an object is called a _________ function.

A)input
B)output
C)member
D)instantiated
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
40
The member function setf stands for

A)set the file name
B)set the flags
C)set the format
D)nothing
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
41
We have a file that has a name in it,but the name is written one character per line.We need to write this name to the screen.What is wrong with the following code?
Ifstream fileIn;
FileIn.open"file.txt");
Char ch;
FileIn.getch)
While!fileIn.eof))
{
Cout.putch);
FileIn.getch);
}

A)can not use put with cout.
B)our output has new lines in it.
C)nothing is wrong
D)eof is not a member of an ifstream object
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
42
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?

A)whileinFile >> intOne >> intTwo)
B)whileinFileintOne,intTwo))
C)whileinFile)
D)whileinFile << intOne << intTwo)
E)A and B
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
43
What is the output of the following code?
Char ch='G';
Cout << tolowerch)<< endl;

A)G
B)g
C)the integer value of 'g'
D)the integer value of 'G'
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
44
In order to use the stream manipulators,you must include the ______ library

A)manip
B)iomanip
C)cstdlib
D)fstream
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
45
If the user types in the characters 10,and your program reads them into an integer variable,what is the value stored into that integer?

A)1
B)0
C)10
D)none of the above.
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
46
What is wrong with the following code?
While ! fileIn.eof))
{
FileIn >> value;
FileOut << value;
}

A)We have read past the end of the input file and attempt to output a nonexistent value
B)We have written past the end of the output file
C)Nothing
D)A and B
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
47
Which function returns true if the character argument is a letter?

A)isdigit
B)islower
C)isalpha
D)isspace
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
48
The put function outputs

A)one character value
B)one float value
C)one integer value
D)one double value
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
49
ios::showpos is a flag that

A)always displays a + in front of positive integers
B)can be used to find the absolute value of an integer
C)always displays a + in front of all integers
D)all of the above
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
50
The command outFile.width10)is used to

A)change the number of characters in the output
B)sets the filename of outFile to 10 characters
C)always uses 10 characters to display the output
D)displays the next value in at least 10 characters
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
51
The get function reads

A)one integer value
B)one float value
C)one double value
D)one character value
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 51 flashcards in this deck.