CS1336 Ch. 4 Checkpoints – Flashcards

Unlock all answers in this set

Unlock answers
question
Assume x is 5, y is 6, and z is 8, and indicate if the relational expression is true or false x == 5
answer
true
question
Assume x is 5, y is 6, and z is 8, and indicate if the relational expression is true or false 7 <= (x + 2)
answer
true
question
Assume x is 5, y is 6, and z is 8, and indicate if the relational expression is true or false z < 4
answer
false
question
Assume x is 5, y is 6, and z is 8, and indicate if the relational expression is true or false (2 + x) != y
answer
true
question
Assume x is 5, y is 6, and z is 8, and indicate if the relational expression is true or false z != 4
answer
true
question
Assume x is 5, y is 6, and z is 8, and indicate if the relational expression is true or false x >= 9
answer
false
question
Assume x is 5, y is 6, and z is 8, and indicate if the relational expression is true or false x <= (y *2)
answer
true
question
Indicate whether the following statement about relational expressions is correct or incorrect. x <= y is the same as y > x
answer
incorrect
question
Indicate whether the following statement about relational expressions is correct or incorrect. x != y is the same as y >= x
answer
incorrect
question
Indicate whether the following statement about relational expressions is correct or incorrect. x >= y is the same as y <= x.
answer
correct
question
Answer the following question with a yes or no If it is true that x > y and it also true that x < z, does that mean y < z is true?
answer
yes
question
Answer the following question with a yes or no If it is true that x >= y and it is also true that z == x, does that mean that z == y is true?
answer
no
question
Answer the following question with a yes or no If it is true that x != y and it is also true that x != z, does that mean that z != y is true?
answer
no
question
What will the following program display? #include using namespace std; int main() { int a = 0, b = 2, x = 4, y = 0; cout << ( a == b) << endl; cout << ( a != y) << endl; cout << (b <= x) << endl; cout << (y > a) << endl; return 0; } (4.4)
answer
0 0 1 0
question
Write an if statement that performs the following logic: if the variable x is equal to 20, then assign 0 to the variable y (4.5)
answer
if (x == 20) y = 0;
question
Write an if statement that performs the following logic: if the variable price is greater than 500, then assign 0.2 to the variable discountRate . (4.6)
answer
if (price > 500) discountRate = 0.2;
question
Write an if statement that multiplies payRate by 1.5 if hours is greater than 40. (4.7)
answer
if (hours > 40) payRate *= 1.5
question
TRUE or FALSE: Both of the following if statements perform the same operation. if (sales > 10000) commissionRate = 0.15; if (sales > 10000) commissionRate = 0.15; (4.8)
answer
True
question
TRUE or FALSE: Both of the following statements perform the same operation. if (calls == 20) rate *= 0.5; if (calls = 20) rate *= 0.5; (4.9)
answer
False
question
Write an if statement that performs the following logic: if the variable sales is greater than 50,000, then assign 0.25 to the commissionRate variable, and assign 250 to the bonus variable. (4.10)
answer
if (sales > 50000) { commissionRate = 0.25; bonus = 250; }
question
The following code segment is syntactically correct, but it appears to contain a logic error. Can you find the error? if (interestRate > .07) cout << "This account earns a $10 bonus.n"; balance += 10.0; (4.11)
answer
Only the first statement after the if statement is conditionally executed. Both of the statements after the if statement should be enclosed in a set of braces.
question
TRUE or FALSE: The following if/else statements cause the same output to display. A) if (x > y) cout << "x is the greater.n"; else cout << "x is not the greater.n"; B) if (y <= x) cout << "x is not the greater.n"; else cout << "x is the greater.n"; (4.12)
answer
False
question
Write an if/else statement that assigns 1 to x if y is equal to 100. Otherwise it should assign 0 to x. (4.13)
answer
if (y == 10) x = 1; else x = 0;
question
Write an if/else statement that assigns 0.10 to commissionRate unless sales is greater than or equal to 50000.00, in which case it assigns 0.20 to commissionRate. (4.14)
answer
if (sales >= 50000.00) commissionRate = 0.20; else commissionRate = 0.10;
question
If you executed the following code, what would it display if the user enters 5? What if the user enters 15? What if the user enters 30? What if the user enters −1? int number; cout << "Enter a number: "; cin >> number; if (number > 0) { cout << "Zeron"; if (number > 10) { cout << "Tenn"; if (number > 20) { cout << "Twentyn"; } } } } (4.15)
answer
Zero Zero Ten Zero Ten Twenty
question
What will the following code display? int funny = 7, serious = 15 funny = serious % 2; if (funny != 1) { funny = 0; serious = 0; } else if (funny == 2) { funny = 10; serious = 10; } else { funny = 1; serious = 1; } cout << funny << " " << serious << endl; (4.16)
answer
1 1
question
The following code is used in a bookstore program to determine how many discount coupons a customer gets. How many coupons are given if the customer purchases 1 book? int numBooks, numCoupons; cout << "How many books are being purchased? "; cin >> numBooks; if (numBooks < 1) numCoupons = 0; else if (numBooks < 3) numCoupons = 1; else if (numBooks < 5) numCoupons = 2 else numCoupons = 3; cout << "The number of coupons to give is " << numCoupons << endl; (4.17)
answer
1
question
The following code is used in a bookstore program to determine how many discount coupons a customer gets. How many coupons are given if the customer purchases 3 books? int numBooks, numCoupons; cout << "How many books are being purchased? "; cin >> numBooks; if (numBooks < 1) numCoupons = 0; else if (numBooks < 3) numCoupons = 1; else if (numBooks < 5) numCoupons = 2 else numCoupons = 3; cout << "The number of coupons to give is " << numCoupons << endl; (4.17)
answer
2
question
The following code is used in a bookstore program to determine how many discount coupons a customer gets. How many coupons are given if the customer purchases 4 books? int numBooks, numCoupons; cout << "How many books are being purchased? "; cin >> numBooks; if (numBooks < 1) numCoupons = 0; else if (numBooks < 3) numCoupons = 1; else if (numBooks < 5) numCoupons = 2 else numCoupons = 3; cout << "The number of coupons to give is " << numCoupons << endl; (4.17)
answer
2
question
The following code is used in a bookstore program to determine how many discount coupons a customer gets. How many coupons are given if the customer purchases 5 books? int numBooks, numCoupons; cout << "How many books are being purchased? "; cin >> numBooks; if (numBooks < 1) numCoupons = 0; else if (numBooks < 3) numCoupons = 1; else if (numBooks < 5) numCoupons = 2 else numCoupons = 3; cout << "The number of coupons to give is " << numCoupons << endl; (4.17)
answer
3
question
The following code is used in a bookstore program to determine how many discount coupons a customer gets. How many coupons are given if the customer purchases 10 books? int numBooks, numCoupons; cout << "How many books are being purchased? "; cin >> numBooks; if (numBooks < 1) numCoupons = 0; else if (numBooks < 3) numCoupons = 1; else if (numBooks < 5) numCoupons = 2 else numCoupons = 3; cout << "The number of coupons to give is " << numCoupons << endl; (4.17)
answer
3
question
Indicate if the result of the following logical expression is TRUE or FALSE. true && false (4.18)
answer
false
question
Indicate if the result of the following logical expression is TRUE or FALSE. true && true (4.18)
answer
true
question
Indicate if the result of the following logical expression is TRUE or FALSE. false && true (4.18)
answer
false
question
Indicate if the result of the following logical expression is TRUE or FALSE. false && false (4.18)
answer
false
question
Indicate if the result of the following logical expression is TRUE or FALSE. true || false (4.18)
answer
true
question
Indicate if the result of the following logical expression is TRUE or FALSE. true || true (4.18)
answer
true
question
Indicate if the result of the following logical expression is TRUE or FALSE. false|| true (4.18)
answer
true
question
Indicate if the result of the following logical expression is TRUE or FALSE. false|| false (4.18)
answer
false
question
Indicate if the result of the following logical expression is TRUE or FALSE. !true (4.18)
answer
false
question
Indicate if the result of the following logical expression is TRUE or FALSE. !false (4.18)
answer
true
question
Assume the variables a = 2, b = 4, and c = 6. Indicate if the following is true or false a == 4 || b > 2 (4.19)
answer
true
question
Assume the variables a = 2, b = 4, and c = 6. Indicate if the following is true or false 6 <= c && a > 3 (4.19)
answer
false
question
Assume the variables a = 2, b = 4, and c = 6. Indicate if the following is true or false 1 != b && c != 3 (4.19)
answer
true
question
Assume the variables a = 2, b = 4, and c = 6. Indicate if the following is true or false a >= -1 || a <= b (4.19)
answer
true
question
Assume the variables a = 2, b = 4, and c = 6. Indicate if the following is true or false !(a > 2) (4.19)
answer
true
question
Write an if statement that prints the message "The number is valid" if the variable speed is within the range 0 through 200. (4.20)
answer
if (speed >= 0 && speed <= 200) cout << "The number is valid";
question
Write an if statement that prints the message "The number is not valid" if the variable speed is outside the range 0 through 200. (4.21)
answer
if (speed < 0 || speed > 200) cout << "The number is not valid";
question
Indicate whether the following relational expression is true or false. 'a' < 'z' (4.22)
answer
true
question
Indicate whether the following relational expression is true or false. 'a' == 'A' (4.22)
answer
false
question
Indicate whether the following relational expression is true or false. '5' < '7' (4.22)
answer
true
question
Indicate whether the following relational expression is true or false. 'a' < 'A' (4.22)
answer
false
question
Indicate whether the following relational expression is true or false. '1' == 1 (4.22)
answer
false
question
Indicate whether the following relational expression is true or false. '1' == 49 (4.22)
answer
true
question
Indicate whether the following relational expression is true or false. "Bill" == "BILL" (4.23)
answer
false
question
Indicate whether the following relational expression is true or false. "Bill" < "BILL" (4.23)
answer
false
question
Indicate whether the following relational expression is true or false. "Bill" < "Bob" (4.23)
answer
false
question
Indicate whether the following relational expression is true or false. "189" > "23" (4.23)
answer
true
question
Indicate whether the following relational expression is true or false. "189" > "Bill" (4.23)
answer
false
question
Indicate whether the following relational expression is true or false. "Mary" < "MaryEllen" (4.23)
answer
true
question
Indicate whether the following relational expression is true or false. "MaryEllen" < "Mary Ellen" (4.23)
answer
true
question
Rewrite the following if/else statement as conditional expression: if (x > y) z = 1; else z = 20; (4.24)
answer
z = x > y ? 1 : 20;
question
Rewrite the following if/else statement as conditional expression: if (temp > 45) population = base * 10; else population = base * 2; (4.24)
answer
population = temp > 45 ? base * 10 : base * 2;
question
Rewrite the following if/else statement as conditional expression: if (hours > 40) wages *= 1.5; else wages *= 1; (4.24)
answer
wages *= hours > 40 ? 1.5 : 1;
question
Rewrite the following if/else statement as conditional expression: if (result >= 0) cout << "The result is positiven"; else cout << "The result is negative.n"; (4.24)
answer
cout << (result >= 0 ? "The result is positiven" : "The result is negative. n");
question
The following is a conditional expression. Rewrite each with an if / else statement: j = k > 90 ? 57 : 12; (4.25)
answer
if (k > 70) j = 57; else j = 12;
question
The following is a conditional expression. Rewrite each with an if / else statement: factor = x >= 10 ? y * 22 : y * 35; (4.25)
answer
if (x >= 10) factor = y * 22; else factor = y *35;
question
The following is a conditional expression. Rewrite each with an if / else statement: total += count == 1 ? sales : count * sales; (4.25)
answer
if (count == 1) total += sales; else total += count * sales;
question
The following is a conditional expression. Rewrite each with an if / else statement: cout << (((num % 2) == 0) ? "Evenn" : "Oddn"); (4.25)
answer
if ((num % 2) == 0) cout << "Evenn"; else cout << "Oddn";
question
What will the following program display? #include using namespace std; int main() { const int UPPER = 8, LOWER = 2; int num1, num2, num3 = 12, num4 = 3; num1 = num3 < num4 ? UPPER : LOWER; num2 = num4 > UPPER ? num3 : LOWER; cout << num1 << " " << num2 << endl; return 0; } (4.26)
answer
2 2
question
Explain why you cannot convert the following if/else if statement into a switch statement. if (temp == 100) x = 0; else if (population > 1000) x = 1; else if (rate < .1) x = −1; (4.27)
answer
Because the if / else if statement test several different conditions, consisting of different variables
question
What is wrong with the following switch statement? switch (temp) { case temp < 0 : cout << "Temp is negative.n"; break; case temp == 0: cout << "Temp is zero.n"; break; case temp > 0 : cout << "Temp is positive.n"; break; } (4.28)
answer
The case statements must be followed by an integer constant, not a relational expression
question
What will the following program display? #include using namespace std; int main() { int funny = 7, serious = 15; funny = serious * 2; switch (funny) { case 0 : cout << "That is funny.n"; break; case 30: cout << "That is serious.n"; break; case 32: cout << "That is seriously funny.n"; break; default: cout << funny << endl; } return 0; } (4.29)
answer
That is serious
Get an explanation on any task
Get unstuck with the help of our AI assistant in seconds
New