




























































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!





























































When an if statement is placed within the conditionally-executed code of another if statement, this is known as: A. nesting B. complexity C. None of these D. validation E. overloading - ANSWER A. nesting Given that x = 2, y = 1, and z = 0, what will the following cout statement display? cout << "answer = " << (x || !y && z) << endl; A. answer = 0 B. answer = 1 C. None of these D. answer = 2 - ANSWER B. answer = 1 These operators connect two or more relational expressions into one, or reverse the logic of an expression. - ANSWER logical An expression that has any value other than 0 is considered true by and if statement. (T/F) - ANSWER True
What is the value of the following expression? true && false - ANSWER false Given the if/else statement: if (a < 5) b = 12; else d = 30; Which of the following performs the same operation? A. a >= 5? d = 30 : b = 12; B. None of these C. d = 30? b = 12 : a = 5; D. b < 5? b = 12 : d = 30; E. a < 5? b = 12 : d = 30; - ANSWER E What is the output of the following code segment if the user enters 90 for the score? cout << "enter your test score: "; cin >> test_score; if (test_score < 60) cout << "You failed the test." << endl; if (test_score > 60)
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; - ANSWER 13 (Fall through adds 3, then 6, then 4) Which line in the following program will cause a compiler error? 1 #include
5 int number = 5; 6 if (number >= 0 && <= 100) 7 cout << "passed. \n"; 8 else 9 cout << "failed. \n"; 10 return 0; 11 } - ANSWER Line 6 (Missing variable "number" on the right side of the AND operator) Given the following code segment, what is the output? int x = 1, y = 1, z = 1; y = y + z; x = x + y; cout << "result = " << (x < y? y : x) << endl; A. There will be no output B. result = 3 C. result = 0 D. result = 1 E. result = 2 - ANSWER 3 What will be displayed after the following statements execute?
D. None of these E. || - ANSWER C Select all that apply. Given: x = 5, y = 6, z = 8. Which of the following are FALSE?
A. 5 B. 4 C. 1 D. 6 E. 3 F. 2 - ANSWER A and E Both of the following if statements perform the same operation. (T/F)
if (sales > 10000) commissionRate = 0.15; if (sales > 10000) commissionRate = 0.15; - ANSWER True The following code correctly determines whether x contains a value in the range of 0 through 100, inclusive. (T/F) if (x > 0 && <= 100) - ANSWER False This statement uses the value of a variable or expression to determine where the program will branch to. A. None of these B. select C. switch D. scope E. association - ANSWER C
If the expression on the left side of the following is false, the expression on the right side will not be checked. (T/F) (a >= b) && (c == d) - ANSWER True
What is the output of the following code? int w = 98; int x = 99;
This operator represents the logical OR: A. || B. None of these C. && D. -- E. # - ANSWER A
What is the value of the following expression? true || false A. None of these B. + C. false D. true E. -1 - ANSWER D
What is the value of the following expression? true && !false A. None of these
D. false E. true - ANSWER E
What is the value of result after the following code executes? int a = 60; int b = 15; int result = 10; if (a = b) result *= 2;
A. code will not execute B. 10 C. 120 D. 12 E. 20 - ANSWER E
When a program lets the user know that an invalid choice has been made, this is known as: - ANSWER input validation
cout << "Enter a number: "; cin number; if (number > 0) cout << "Hi, there!" << endl; else cout << "Good-bye." << endl;
A. Hi, there! B. Good-bye. C. "Hi, there!" D. nothing will happen E. Hi, there! Good-bye. - ANSWER A
Input values should always be checked for: A. None of these B. All of these C. division by zero, if division is taking place D. reasonableness E. an appropriate range - ANSWER B
Whereas < is called a relational operator, x < y is called a(n) ________.
A. relational expression B. arithmetic expression C. arithmetic operator D. relative operator E. None of these - ANSWER A
The ________ is an equality (or comparison) operator.
A. = B. == C. None of these D. >= E. != - ANSWER B
The value of result in the following expression will be 0 if x has the value of
B. None of these C. break D. switch E. scope - ANSWER C
After the following code executes, what is the value of my_value if the user enters 0? cin >> my_value; if (my_value > 5) my_value = my_value + 5; else if (my_value > 2) my_value - my_value + 10; else my_value = my_value + 15; - ANSWER 15
What is the value of the following expression? true && true
A. - B. None of these
C. false D. true E. +1 - ANSWER D
If the expression on the left side of the following is false, the expression on the right side will not be checked. (T/F) (a >= b) && (c == d) - ANSWER True
What is the value of donuts after the following statement executes? int donuts = 10; if (donuts != 10) donuts = 0 else donuts += 2 - ANSWER 12
If you intend to place a block of statements within an if statement, you must place ________ around the block.
A. parentheses ( ) B. curly braces { }
B. all of these C. 100 D. 99 E. 10 - ANSWER D
The increment and decrement operators can be used in mathematical expressions; however, they cannot be used in relational expressions. (T/F) - ANSWER False
A while loop's body can contain multiple statements, as long as they are enclosed in braces. (T/F) - ANSWER True
A while loop is somewhat limited because the counter can only be incremented by one each time through the loop. (T/F) - ANSWER False
What will the following code display? int x = 0; while (x < 5) { cout << x << " "; x++;
C. This is an infinite loop D. 0 1 2 3 4 - ANSWER D
To write read data from a file, you define an object of the ________ data type.
A. ofstream B. inputFile C. ifstream D. fstream - ANSWER C
If you place a semicolon after the test expression in a while loop, it is assumed to be a(n)