CS 150 Chapter 3

25 July 2022
4.7 (114 reviews)
50 test answers

Unlock all answers in this set

Unlock answers (46)
question
false
answer
It is a good idea to redefine cin and cout in your programs.
question
false
answer
In the statement cin >> x;, x can be a variable or an expression.
question
false
answer
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;
question
true
answer
The number of input data extracted by cin and >> depends on the number of variables appearing in the cin statement.
question
false
answer
The extraction operator >> skips only all leading blanks when searching for the next data in the input stream.
question
true
answer
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.
question
true
answer
Entering a char value into an int variable causes serious errors, called input failure.
question
false
answer
If input failure occurs in a C++ program, the program terminates immediately and displays an error message.
question
false
answer
In an output statement, each occurrence of endl advances the cursor to the end of the current line on an output device.
question
true
answer
You can use the function getline to read a string containing blanks.
question
x = 10, y = 20.7
answer
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;.
question
cin >> x >> y;
answer
Suppose that x and y are int variables. Which of the following is a valid input statement?
question
x = 15, ch = 'A', y = 73.2
answer
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: 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;
question
alpha = 17, ch = 'A'
answer
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;
question
x = 15, y = 76.3, z = 14
answer
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;
question
'C'
answer
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;
question
x = 28, y = 32, z = 0.6
answer
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;
question
ch = '276', x = '.'
answer
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;
question
This statement results in input failure
answer
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;
question
ch1 = 'A', ch2 = ' ', alpha = 18
answer
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;
question
'B'
answer
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);
question
ignore
answer
When you want to process only partial data, you can use the stream function ____ to discard a portion of the input.
question
300
answer
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;
question
W
answer
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;
question
X
answer
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;
question
member access
answer
In C++, the dot is an operator called the ____ operator.
question
25.67 356.88 7623.97
answer
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;
question
55.680 476.859 23.82
answer
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;
question
1565.683 85.7800 123.98
answer
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;
question
12345678901234567890 ***18**Happy**Sleepy
answer
What is the output of the following statements? cout << setfill('*'); cout << "12345678901234567890" << endl cout << setw(5) << "18" << setw(7) << "Happy" << setw(8) << "Sleepy" << endl;
question
123456789012345678901234567890 ####Mickey Donald*****Goofy
answer
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;
question
setfill
answer
____ is a parameterized stream manipulator.
question
iostream
answer
Manipulators without parameters are part of the ____ header file.
question
inFile.open("progdata.dat");
answer
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?
question
outFile.open("outputData.out");
answer
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?
question
predefined or pre defined or pre-defined
answer
C++ comes with a wealth of functions, called ____________________ functions, that are written by other programmers.
question
char
answer
In the C++ statement, cin.get(u); u must be a variable of type ____________________.
question
peek
answer
The function ____________________ returns the next character in the input stream; it does not remove the character from the input stream.
question
putback
answer
The stream function ____________________ lets you put the last character extracted from the input stream by the get function back into the input stream.
question
istream
answer
The functions get, ignore, and so on are members of the data type ____________________.
question
classes
answer
C++ has a special name for the data types istream and ostream. They are called ____________________.
question
istream
answer
cin is called a(n) ____________________ object.
question
member access
answer
In C++, the dot is an operator called the ____________________operator.
question
iomanip
answer
To use the manipulator setprecision, the program must include the header file ____________________.
question
cin.setf(ios::fixed);
answer
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;.
question
setw
answer
The manipulator ____________________ is used to output the value of an expression in a specific number of columns.
question
unsetf
answer
You can disable the manipulator left by using the stream function ____________________.
question
cin.setf(ios::left);
answer
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;.
question
iomanip
answer
To use a parameterized stream manipulator in a program, you must include the header file ____________________.
question
fstream
answer
C++ provides a header file called ____________________, which is used for file I/O.