Deck 3: Input/Output
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/50
Play
Full screen (f)
Deck 3: Input/Output
1
Entering a char value into an int variable causes serious errors,called input failure.
True
2
The following statements will result in input failure if the input values are not on a separate line.(Assume that x and y are int variables.)
cin >> x;
cin >> y;
cin >> x;
cin >> y;
False
3
Suppose that alpha is an int variable and ch is a char variable and the input is: 17 A
What are the values after the following statements execute?
Cin >> alpha;
Cin >> ch;
A) alpha = 17, ch = ' '
B) alpha = 1, ch = 7
C) alpha = 17, ch = 'A'
D) alpha = 17, ch = 'a'
What are the values after the following statements execute?
Cin >> alpha;
Cin >> ch;
A) alpha = 17, ch = ' '
B) alpha = 1, ch = 7
C) alpha = 17, ch = 'A'
D) alpha = 17, ch = 'a'
C
4
Suppose that ch1,ch2,and ch3 are variables of the type char and the input is: A B
C
Choose the value of ch3 after the following statement executes:
Cin >> ch1 >> ch2 >> ch3;
A) 'A'
B) 'B'
C) 'C'
D) '\n'
C
Choose the value of ch3 after the following statement executes:
Cin >> ch1 >> ch2 >> ch3;
A) 'A'
B) 'B'
C) 'C'
D) '\n'
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
5
Suppose that x is an int variable,y is a double variable and ch is a char variable and the input is: 15A 73.2
Choose the values after the following statement executes:
Cin >> x >> ch >> y;
A) x = 15, ch = 'A', y = 73.2
B) x = 15, ch = 'A', y = 73.0
C) x = 15, ch = 'a', y = 73.0
D) This statement results in an error because there is no space between 15 and A.
Choose the values after the following statement executes:
Cin >> x >> ch >> y;
A) x = 15, ch = 'A', y = 73.2
B) x = 15, ch = 'A', y = 73.0
C) x = 15, ch = 'a', y = 73.0
D) This statement results in an error because there is no space between 15 and A.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
6
You can use the function getline to read a string containing blanks.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
7
Suppose that x is an int variable,y is a double variable,z is an int variable,and the input is: 15 76.3 14
Choose the values after the following statement executes:
Cin >> x >> y >> z;
A) x = 15, y = 76, z = 14
B) x = 15, y = 76, z = 0
C) x = 15, y = 76.3, z = 14
D) x = 15.0, y = 76.3, z = 14.0
Choose the values after the following statement executes:
Cin >> x >> y >> z;
A) x = 15, y = 76, z = 14
B) x = 15, y = 76, z = 0
C) x = 15, y = 76.3, z = 14
D) x = 15.0, y = 76.3, z = 14.0
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
8
Suppose that x and y are int variables,ch is a char variable,and the input is: 4 2 A 12
Choose the values of x,y,and ch after the following statement executes:
Cin >> x >> ch >> y;
A) x = 4, ch = 2, y = 12
B) x = 4, ch = A, y = 12
C) x = 4, ch = ' ', y = 2
D) This statement results in input failure
Choose the values of x,y,and ch after the following statement executes:
Cin >> x >> ch >> y;
A) x = 4, ch = 2, y = 12
B) x = 4, ch = A, y = 12
C) x = 4, ch = ' ', y = 2
D) This statement results in input failure
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
9
Suppose that x is an int variable and y is a double variable and the input is: 10 20.7
Choose the values after the following statement executes: cin >> x >> y;.
A) x = 10, y = 20
B) x = 10, y = 20.0
C) x = 10, y = 20.7
D) x = 10, y = 21.0
Choose the values after the following statement executes: cin >> x >> y;.
A) x = 10, y = 20
B) x = 10, y = 20.0
C) x = 10, y = 20.7
D) x = 10, y = 21.0
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
10
Suppose that x and y are int variables.Which of the following is a valid input statement?
A) cin >> x >> cin >> y;
B) cin >> x >> y;
C) cin << x << y;
D) cout << x << y;
A) cin >> x >> cin >> y;
B) cin >> x >> y;
C) cin << x << y;
D) cout << x << y;
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
11
In an output statement,each occurrence of endl advances the cursor to the end of the current line on an output device.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
12
If input failure occurs in a C++ program,the program terminates immediately and displays an error message.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
13
The extraction operator >> skips only all leading blanks when searching for the next data in the input stream.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
14
Suppose that ch1 and ch2 are char variables,alpha is an int variable,and the input is: A 18
What are the values after the following statement executes?
Cin)get(ch1);
Cin)get(ch2);
Cin >> alpha;
A) ch1 = 'A', ch2 = ' ', alpha = 18
B) ch1 = 'A', ch2 = '1', alpha = 8
C) ch1 = 'A', ch2 = ' ', alpha = 1
D) ch1 = 'A', ch2 = '\n', alpha = 1
What are the values after the following statement executes?
Cin)get(ch1);
Cin)get(ch2);
Cin >> alpha;
A) ch1 = 'A', ch2 = ' ', alpha = 18
B) ch1 = 'A', ch2 = '1', alpha = 8
C) ch1 = 'A', ch2 = ' ', alpha = 1
D) ch1 = 'A', ch2 = '\n', alpha = 1
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
15
Suppose that x is an int variable,ch is a char variable,and the input is: 276.
Choose the values after the following statement executes:
Cin >> ch >> x;
A) ch = '2', x = 276
B) ch = '276', x = '.'
C) ch = ' ', x = 276
D) ch = 'b', x = 76
Choose the values after the following statement executes:
Cin >> ch >> x;
A) ch = '2', x = 276
B) ch = '276', x = '.'
C) ch = ' ', x = 276
D) ch = 'b', x = 76
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
16
The number of input data extracted by cin and >> depends on the number of variables appearing in the cin statement.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
17
When reading data into a char variable,after skipping any leading whitespace characters,the extraction operator >> finds and stores only the next character; reading stops after a single character.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
18
It is a good idea to redefine cin and cout in your programs.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
19
In the statement cin >> x;,x can be a variable or an expression.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
20
Suppose that x and y are int variables,z is a double variable,and the input is: 28 32.6 12
Choose the values of x,y,and z after the following statement executes:
Cin >> x >> y >> z;
A) x = 28, y = 32, z = 0.6
B) x = 28, y = 32, z = 12.0
C) x = 28, y = 12, z = 32.6
D) x = 28, y = 12, z = 0.6
Choose the values of x,y,and z after the following statement executes:
Cin >> x >> y >> z;
A) x = 28, y = 32, z = 0.6
B) x = 28, y = 32, z = 12.0
C) x = 28, y = 12, z = 32.6
D) x = 28, y = 12, z = 0.6
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
21
Suppose that ch1,ch2,and ch3 are variables of the type char and the input is: A B
C
What is the value of ch3 after the following statements execute?
Cin)get(ch1);
Cin)get(ch2);
Cin)get(ch3);
A) 'A'
B) 'B'
C) 'C'
D) '\n'
C
What is the value of ch3 after the following statements execute?
Cin)get(ch1);
Cin)get(ch2);
Cin)get(ch3);
A) 'A'
B) 'B'
C) 'C'
D) '\n'
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
22
Manipulators without parameters are part of the ____ header file.
A) iostream
B) iomanip
C) ifstream
D) pmanip
A) iostream
B) iomanip
C) ifstream
D) pmanip
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
23
Suppose that x = 55.68,y = 476.859,and z = 23.8216.What is the output of the following statements? cout << fixed << showpoint;
Cout << setprecision(3);
Cout << x << ' ' << y << ' ' << setprecision(2)<< z << endl;
A) 55.680 476.859 23.82
B) 55.690 476.860 23.82
C) 55.680 476.860 23.82
D) 55.680 476.859 23.821
Cout << setprecision(3);
Cout << x << ' ' << y << ' ' << setprecision(2)<< z << endl;
A) 55.680 476.859 23.82
B) 55.690 476.860 23.82
C) 55.680 476.860 23.82
D) 55.680 476.859 23.821
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
24
When you want to process only partial data,you can use the stream function ____ to discard a portion of the input.
A) clear
B) skip
C) delete
D) ignore
A) clear
B) skip
C) delete
D) ignore
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
25
In C++,the dot is an operator called the ____ operator.
A) dot access
B) member access
C) data access
D) member
A) dot access
B) member access
C) data access
D) member
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
26
____ is a parameterized stream manipulator.
A) endl
B) fixed
C) scientific
D) setfill
A) endl
B) fixed
C) scientific
D) setfill
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
27
Suppose that outFile is an ofstream variable and output is to be stored in the file outputData.out.Which of the following statements opens the file outputData.out and associates outFile to the output file?
A) outFile("outputData.out");
B) outFile.open("outputData.out");
C) open(outFile,"outputData.out");
D) open.outFile("outputData.out");
A) outFile("outputData.out");
B) outFile.open("outputData.out");
C) open(outFile,"outputData.out");
D) open.outFile("outputData.out");
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
28
Suppose that x = 25.67,y = 356.876,and z = 7623.9674.What is the output of the following statements? cout << fixed << showpoint;
Cout << setprecision(2);
Cout << x << ' ' << y << ' ' << z << endl;
A) 25.67 356.87 7623.96
B) 25.67 356.87 7623.97
C) 25.67 356.88 7623.97
D) 25.67 356.876 7623.967
Cout << setprecision(2);
Cout << x << ' ' << y << ' ' << z << endl;
A) 25.67 356.87 7623.96
B) 25.67 356.87 7623.97
C) 25.67 356.88 7623.97
D) 25.67 356.876 7623.967
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
29
In the C++ statement,
cin.get(u);
u must be a variable of type ____________________.
cin.get(u);
u must be a variable of type ____________________.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
30
What is the output of the following statements? cout << "123456789012345678901234567890" << endl
Cout << setfill('#')<< setw(10)<< "Mickey"
<< setfill(' ')<< setw(10)<< "Donald"
<< setfill('*')<< setw(10)<< "Goofy" << endl;
A) 123456789012345678901234567890
####Mickey Donald*****Goofy
B) 123456789012345678901234567890
####Mickey####Donald*****Goofy
C) 123456789012345678901234567890
####Mickey####Donald#####Goofy
D) 23456789012345678901234567890
****Mickey####Donald#####Goofy
Cout << setfill('#')<< setw(10)<< "Mickey"
<< setfill(' ')<< setw(10)<< "Donald"
<< setfill('*')<< setw(10)<< "Goofy" << endl;
A) 123456789012345678901234567890
####Mickey Donald*****Goofy
B) 123456789012345678901234567890
####Mickey####Donald*****Goofy
C) 123456789012345678901234567890
####Mickey####Donald#####Goofy
D) 23456789012345678901234567890
****Mickey####Donald#####Goofy
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
31
The stream function ____________________ lets you put the last character extracted from the input stream by the get function back into the input stream.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
32
Suppose that ch1 and ch2 are char variables and the input is: WXYZ
What is the value of ch2 after the following statements execute?
Cin >> ch1;
Ch2 = cin.peek();
Cin >> ch2;
A) W
B) X
C) Y
D) Z
What is the value of ch2 after the following statements execute?
Cin >> ch1;
Ch2 = cin.peek();
Cin >> ch2;
A) W
B) X
C) Y
D) Z
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
33
The functions get,ignore,and so on are members of the data type ____________________.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
34
Suppose that alpha,beta,and gamma are int variables and the input is: 100 110 120
200 210 220
300 310 320
What is the value of gamma after the following statements execute?
Cin >> alpha;
Cin)ignore(100,'\n');
Cin >> beta;
Cin)ignore(100,'\n');
Cin >> gamma;
A) 100
B) 200
C) 300
D) 320
200 210 220
300 310 320
What is the value of gamma after the following statements execute?
Cin >> alpha;
Cin)ignore(100,'\n');
Cin >> beta;
Cin)ignore(100,'\n');
Cin >> gamma;
A) 100
B) 200
C) 300
D) 320
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
35
C++ comes with a wealth of functions,called ____________________ functions,that are written by other programmers.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
36
Suppose that ch1 and ch2 are char variables and the input is: WXYZ
What is the value of ch2 after the following statements execute?
Cin)get(ch1);
Cin)putback(ch1);
Cin >> ch2;
A) W
B) X
C) Y
D) Z
What is the value of ch2 after the following statements execute?
Cin)get(ch1);
Cin)putback(ch1);
Cin >> ch2;
A) W
B) X
C) Y
D) Z
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
37
The function ____________________ returns the next character in the input stream; it does not remove the character from the input stream.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
38
What is the output of the following statements? cout << setfill('*');
Cout << "12345678901234567890" << endl
Cout << setw(5)<< "18" << setw(7)<< "Happy"
<< setw(8)<< "Sleepy" << endl;
A) 12345678901234567890
***18 Happy Sleepy
B) 12345678901234567890
***18**Happy**Sleepy
C) 12345678901234567890
***18**Happy Sleepy
D) 12345678901234567890
***18**Happy Sleepy**
Cout << "12345678901234567890" << endl
Cout << setw(5)<< "18" << setw(7)<< "Happy"
<< setw(8)<< "Sleepy" << endl;
A) 12345678901234567890
***18 Happy Sleepy
B) 12345678901234567890
***18**Happy**Sleepy
C) 12345678901234567890
***18**Happy Sleepy
D) 12345678901234567890
***18**Happy Sleepy**
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
39
Suppose that x = 1565.683,y = 85.78,and z = 123.982.What is the output of the following statements? cout << fixed << showpoint;
Cout << setprecision(3)<< x << ' ';
Cout << setprecision(4)<< y << ' ' << setprecision(2)<< z << endl;
A) 1565.683 85.8000 123.98
B) 1565.680 85.8000 123.98
C) 1565.683 85.7800 123.98
D) 1565.683 85.780 123.980
Cout << setprecision(3)<< x << ' ';
Cout << setprecision(4)<< y << ' ' << setprecision(2)<< z << endl;
A) 1565.683 85.8000 123.98
B) 1565.680 85.8000 123.98
C) 1565.683 85.7800 123.98
D) 1565.683 85.780 123.980
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
40
Consider the following program segment.
Ifstream inFile; //Line 1
Int x,y; //Line 2
).. //Line 3
InFile >> x >> y; //Line 4
Which of the following statements at Line 3 can be used to open the file progdata.dat and input data from this file into x and y at Line 4?
A) inFile.open("progdata.dat");
B) inFile(open,"progdata.dat");
C) open.inFile("progdata.dat");
D) open(inFile,"progdata.dat");
Ifstream inFile; //Line 1
Int x,y; //Line 2
).. //Line 3
InFile >> x >> y; //Line 4
Which of the following statements at Line 3 can be used to open the file progdata.dat and input data from this file into x and y at Line 4?
A) inFile.open("progdata.dat");
B) inFile(open,"progdata.dat");
C) open.inFile("progdata.dat");
D) open(inFile,"progdata.dat");
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
41
cin is called a(n)____________________ object.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
42
C++ has a special name for the data types istream and ostream.They are called ____________________.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
43
The manipulator ____________________ is used to output the value of an expression in a specific number of columns.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
44
To use a parameterized stream manipulator in a program,you must include the header file ____________________.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
45
To use the manipulator setprecision,the program must include the header file ____________________.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
46
On some compilers,the statements cin >> fixed; and cin >> scientific; might not work.In this case,you can use the statement ____________________ in place of cin >> fixed;.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
47
C++ provides a header file called ____________________,which is used for file I/O.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
48
On some compilers,the statements cin >> left; and cin >> right; might not work.In this case,you can use the statement ____________________ in place of cin >> left;.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
49
You can disable the manipulator left by using the stream function ____________________.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
50
In C++,the dot is an operator called the ____________________operator.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck