Ch.6 Flashcards

1
Q

What is the output of the following code?
char ch = ‘G’;
cout ≤≤ tolower(ch) ≤≤ endl;

A

the integer value of ‘g’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

The command outFile.width(10) is used to

A

display the next value in at least 10 characters.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

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

A

void display( ostream& out);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

After a stream is opened, before it is used for input and output, it should be

A

checked to see if it opened correctly.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

The command outFile.precision(2);

A

displays all floating point values sent to outFile with 2 decimal places.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

If a file did not open correctly, you should

A

display an error message and take some suitable action such as exit.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Which function returns true if the character argument is a letter?

A

isalpha

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

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[21];

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Which of the following is the correct way to determine if a file stream named inFile opened correctly?

A

if( inFile.fail( ) )

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

A function that is associated with an object is called a ________ function.

A

member

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

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.open(filename);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

The ifstream class is derived from the

A

istream class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

ios::showpos is a flag that

A

always displays a + in front of positive integers.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

The member function setf stands for

A

set the flags

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

When is the external name of the file used in the program?

A

when opening the file stream

17
Q

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”, ios::app);

18
Q

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

while(inFile >> intOne >> intTwo)

19
Q

Which of the following function declarations will accept either cout or a file stream object as its argument?

A

void output( ostream &outFile);

20
Q

Which statement correctly opens an input stream named in_file and attaches it to a file name project.txt?

A

in_file.open(“project.txt”);

21
Q

A value that can be turned on or off is called a

A

flag

22
Q

A ________ is a flow of characters or other data.

A

stream

23
Q

The flag to always show the decimal point in floating numbers is ios::

A

showpoint

24
Q

The manipulator used to change the number of decimal places displayed is

A

setprecision

25
Q

The flag to display floating point numbers in non-scientific notation is ios::

A

fixed

26
Q
In the following function declaration, the istream object cin is called a \_\_\_\_\_\_\_\_.
 void output(istream& in = cin);
A

default argument

27
Q

Which command reads one character even if that character is a blank space?

A

get

28
Q

“\n” is a ________ and ‘\n’ is a ________.

A

string, character

29
Q

The member function eof( ) is (true/false) when we are ready to read the end of file character.

A

false

30
Q

A type whose variables are objects is known as a

A

class

31
Q

You may not have more than one input and one output stream open at any one time.

A

False

32
Q

Two different objects of the same class have a different set of member functions.

A

False

33
Q

You may use a read (extraction) as a boolean expression in an if or while statement.

A

True

34
Q

Streams may be passed to a function.

A

True

35
Q

You must use a width statement before each variable that you want output in a certain width

A

True

36
Q

Using directives can be placed either directly after the include directives, or at the beginning of each function definition.

A

True

37
Q

If you use the width command, it stays in effect for all values that are sent to the stream.

A

True