Chapter 3
What is the value of number after the following statements execute?int number = 10; number += 5; number -= 2; number *= 3;
39
What is the value of average after the following code executes?double average; average = 1.0 + 2.0 + 3.0 / 3.0;
4.0
Which is true about the following statement? cout << setw(4) << num4 << " "; It outputs "setw(4)" before the value in the variable num4. It should use setw(10) to output the value in the variable num10. It inputs up to four characters stored in the variable num4. It prints the value in the variable num4 in a field at least 4 spaces wide. None of these
It prints the value in the variable num4 in a field at least 4 spaces wide.
Which statement is equivalent to the following? number += 1;
number = number + 1;
This manipulator is used to establish a field width for the value immediately following it.
setw
When the final value of an expression is assigned to a variable, it will be converted to:
the data type of the variable
Which statement is equivalent to the following? x = x * 2;
x *= 2;
When this operator is used with string operands it concatenates them, or joins them together.
+
Assume that x is an int variable. What value is assigned to x after the following assignment statement is executed? x = -3 + 4 % 6 / 5;
-3
What is the value stored at x, given the statements: int x; x = 3 / static_cast<int>(4.5 + 6.4);
0
What will the following program display to the console?#include<iostream> #include<string> using namespace std; int main() { string word = "play"; string word2 = word +="ground"; cout << word2.length() << endl;return 0; }
10
What will the value of x be after the following statements execute? int x = 0; int y = 5; int z = 4; x = y + z * 2;
13
What will the value of result be after the following statement executes? result = 6 - 3 * 2 + 7 - 10 / 2 ;
2
In the following C++ statement, what will be executed first according to the order of precedence? result = 6 - 3 * 2 + 7 - 10 / 2 ;
3 * 2
The function, pow(x, 5.0), requires this header file.
cmath
To use the rand( ) function, you must #include this header file in your program.
cstdlib
________ reads a line of input, including leading and embedded spaces, and stores it in a string object.
getline
Which statement will read an entire line of input into the following string object? getline(cin, address); cin address; cin.get(address); cin << address;
getline(cin, address);
Associativity is either right to left or:
left to right
Given the following code segment: string name = "Harry"; Which of the following is the correct way to call the string member function to find the length of the string that is stored in the object. length(); name.length(); size(); name.size();
name.length();