1. If the sub-expression on the left side of the || operator is true, the expres
ID: 3620475 • Letter: 1
Question
1. If the sub-expression on the left side of the || operator is true, the expression on the right side will not be checked.True False
2. Both of the following if statements perform the same operation.
if (sales > 10000)
commissionRate = 0.15;
if (sales > 10000) commissionRate = 0.15;
True False
r
3.You should be careful when using the equality operator to compare floating point values because of potential round-off errors.
True False
4. An expression that has any value other than 0 is considered true by an if statement
True False
5. Quiz4 TF05 (Points: 0.5)
If the sub-expression on the left side of an && operator is false, the expression on the right side will not be checked
True False
6. The following code correctly determines whether x contains a value in the range of 0 through 100.
if (x >= 0 && <= 100)
True False
7.As a rule of style, when writing an if statement you should indent the conditionally-executed statements.
True False
8. Relational operators allow you to ____________ numbers.
1. add
2. multiply
3. compare
4. average
5. None of these
9. What is assigned to the variable a given the statement below with the following assumptions: x = 10, y = 7, and z, a, and b are all int variables.
a = x >= y;
1. 10
2. 7
3. The string "x >= y"
4. 1
5. 0
10. If you place a semicolon after the statement if (x < y)
1. The code will not compile.
2. The compiler will interpret the semicolon as a null statement.
3. The if statement will always evaluate to false.
4. All of the above.
5. None of these.
11. When a relational expression is false, it has the value _____.
1. one
2. zero
3. zero, one, or minus one
4. less than zero
5. None of these.
12. What will following segment of code output?
int x = 5;
if (x = 2)
cout << "This is true!" << endl;
else
cout << "This is false!" << endl;
cout << "This is all folks!" << endl;
1. This is true!
2. This is false!
3. This is true!
This is false!
4. This is true!
This is all folks!
5. None of these.
13. What will the following segment of code output? You can assume the user enters a grade of 90 from the keyboard.
cout << "Enter a test score: ";
cin >> test_score;
if (test_score < 60);
cout << "You failed the test!" << endl;
if (test_score > 60)
cout << "You passed the test!" << endl;
else
cout << "You need to study for the next test!";
1. You failed the test!
2. You passed the test!
3. You failed the test!
You passed the test!
4. You failed the test!
You did poorly on the test!
5. None of these.
14. When an if statement is placed within the conditionally-executed code of another if statement, this is known as:
1. complexity
2. overloading
3. nesting
4. validation
5. None of these.
15. After execution of the following code, what will be the value of input_value if the value 0 is entered at the keyboard at run time?
cin >> input_value;
if (input_value > 5)
input_value = input_value + 5;
else if (input_value > 2)
input_value = input_value + 10;
else
input_value = input_value + 15;
1. 15
2. 10
3. 25
4. 0
5. 5
16. Input values should always be checked for
1. Appropriate range
2. Reasonableness
3. Division by zero, if division is taking place
4. All of these
5. None of these
17. Quiz4 MC10 (Points: 0.5)
What will be the output of the following code segment after the user enters 0 at the keyboard?
int x = -1;
cout << "Enter a 0 or a 1 from the keyboard: ";
cin >> x;
if (x)
cout << "true" << endl;
else
cout << "false" << endl;
1. Nothing will be displayed
2. false
3. x
4. true
18. What will be the output of the following code segment after the user enters 0 at the keyboard?
int x = -1;
cout << "Enter a 0 or a 1 from the keyboard: ";
cin >> x;
if (x)
cout << "true" << endl;
else
cout << "false" << endl;
1. ++
2. ||
3. &&
4. @
5. None of these
19. If you intend to place a block of statements within an if statement, you must place these around the block.
1. parentheses ( )
2. square brackets [ ]
3. quotation marks " "
4. curly braces { }
5. None of these
20. Given that x = 2, y = 1, and z = 0, what will the following cout statement display?
cout << "answer = " << (x || !y && z) << endl;
1. answer = 0
2. answer = 1
3. answer = 2
4. None of these
Explanation / Answer
1. True because one or both expressions must be true for overall expression to be true. It is only necessary for one to be true, and it does not matter which. 2. True because if statements first checks the condition and if it is true then executes the following statement. 3. True 4. True 5. True because If the sub-expression on the left side of an && operator is false, the expression on the right side will not be checked since the entire expression is false if only one of the sub expression is false. 6. False 7. True 8. compare (Ans: 3) 9. 1 (Ans: 4) 10. The compiler will interpret the semicolon as a null statement. (Ans: 2) 11. zero (Ans: 2) 14. nesting (Ans: 3) 16. All of these (Ans: 4) 17. False (Ans: 2) 18. None of these (Ans: 5) 19. curly braces { } (Ans: 4) 20. answer = 1 (Ans: 2)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.