CSI chapter 3-4
This operator takes an operand and reverses its truth or falsehood:
!
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
What is the value of result after the following statement executes? result = (3 * 5) % 4 + 24 / (15 - (7 - 4));
5
The ________ operator always follows the cin object, and the ________ operator follows the cout object.
>>, <<
________ reads a line of input, including leading and embedded spaces, and stores it in a string object.
Getline
What is TRUE about the following statement? cout << setw(4) << num4 << " ";
It allows four spaces for the value in num 4.
This manipulator causes the field to be left justified with padding spaces printed to the right:
Left
When a variable is assigned a number that is too large for its data type, it
Overflows
Which statement is equivalent to the following? number += 1;
number = number + 1;
Where as < is called a relational operator, x < y is called a(n)
relational expression
Without this statement appearing in a switch construct, the program "falls through" all of the statements below the one with the matching case expression.
switch
If you place a semicolon after the statement: if (x < y)
the compiler will interpret the semicolon as a null statement
When the final value of an expression is assigned to a variable, it will be converted to
the data type of the variable
Which of the following must be included in any program that uses the cin object?
the header file iostream
The default section of a switch statement performs a similar task similar to the ________ portion of an if /else if statement.
trailing else
This operator represents the logical AND:
&&
What is the value of donuts after the following code executes? int donuts = 10; if (donuts = 1) donuts = 0; else donuts += 2;
0
When a relational expression is FALSE, it has the value
0
Given that, x = 2, y = 1, and z = 0, what will the following cout statement display?cout << "answer = " << (x || !y && z) << endl;
1
What is assigned to the variable result given the statement below with the following assumptions: x = 10, y = 7, and x , result , and y are all int variables. result = x >= y;
1
What is the output of the following code? int w = 98; int x = 99; int y = 0; int z = 1; if (x >= 99) { if (x < 99) cout << y << endl; else cout << z << endl; } else { if (x == 99) cout << x << endl; else cout << w << endl; }
1
What is the value of donuts after the following code executes? int donuts = 10; if (donuts != 10) donuts = 0; else donuts += 2;
12
What is the output of the following segment of code if the value 4 is input by the user when asked to enter a number? int num; int total = 0; cout << "Enter a number from 1 to 10: "; cin >> num; switch (num) { case 1: case 2: total = 5; case 3: total = 10; case 4: total = total + 3; case 8: total = total + 6; default: total = total + 4; } cout << total << endl;
13
What is the value of x after the following code executes? int x = 0; int y = 5; int z = 4; x = x + y + z * 2;
13
In the following statement, what will be executed first according to the order of precedence? result = 6 - 3 * 2 + 7 - 10 / 2;
3*2
Relational operators allow you to ________ numbers.
Compare
If you want to know the length of the string that is stored in a string object, you can call the object's size member function.
False
In C++, it is impossible to display the number 34.789 in a field of 9 spaces with 2 decimal places of precision.
False
The fixed manipulator causes a number to be displayed in scientific notation.
False
The following code correctly determines whether x contains a value in the range of 0 through 100, inclusive. if (x > 0 && <= 100)
False
The following statement will output $5.00 to the screen: cout << setprecision(5) << dollars << endl;
False
Both of the following if statements perform the same operation. If (sales > 10000) comissionRate = 0.15; If (sales > 10000) comissionRate = 0.15;
True
If the sub-expression on the left side of an && operator is false, the expression on the right side will not be checked.
True
If the sub-expression on the left side of the || operator is true, the expression on the right side will not be checked.
True
The cin << statement will stop reading input when it encounters a newline character.
True
The conditional operator takes two operands.
True
When C++ is working with an operator, it strives to convert the operands to the same type.
True
When the fixed manipulator is used, the value specified by the setprecision manipulator will be the number of digits to appear after the decimal point.
True
When C++ is working with an operator, it strives to convert operands to the same type. This is known as
Type conversion
Which of the following expressions will determine whether x is less than or equal to y?
X <= y
Which of the following will allow the user to input the values 15 and 20 and have them stored in variables named base and height, respectively?
cin >> base >> height;
Which of the following statements will pause the screen until the [Enter] key is pressed?
cin.get();
Which of the following statements will allow the user to enter three values to be stored in variables length, width, and height, in that order?
cin.get(length, width, height);
To use the rand()function, you must include the ________ header file?
cstdlib
A debugging process where you, the programmer, pretend you are a computer and step through each statement while recording the value of each variable at each step is known as
hand tracing
Which statement allows you to properly check the char variable code to determine whether it is equal to a C and then output This is a check?
if (code == 'C') cout << "This is a check\n";
When a user types values at the keyboard, those values are first stored
in the keyboard buffer
This operator represents the logical OR:
l l
Associativity is either right to left or
left to right