C++ 051 Chapter 4: Making Decisions

¡Supera tus tareas y exámenes ahora con Quizwiz!

The ________ statement executes one block of statements if a test condition is true, and another block if the condition is false. A) if B) if/else C) if/else if D) switch E) trailing else

B

The ________ statement acts like a chain of if statements. Each performs its test, one after the other, until one of them is found to be true. A) if/then B) if/else C) if/else if D) if/not if E) if/endif

C

The default section of a switch statement performs a similar task as the ________ portion of an if/else if statement. A) conditional test B) break C) trailing else D) else if E) body

C

The expression x < y is called a(n) ________ expression. A) arithmetic B) logical C) relational D) comparison E) binary

C

The C++ ________ operator represents logical AND. A) ++ B) | C) || D) & E) &&

E

The ________ statement causes other program statements to execute only under certain conditions. A) logical B) relational C) cin D) cout E) if

E

True/False: All of the relational operators are binary.

True

) Which of the following correctly declares an enumerated data type named student? A) enum student { Bill, Tom, Mary }; B) enum student { "Bill", "Tom", "Mary" }; C) int Bill = 1, Tom = 2, Mary = 3; enum student { 1, 2, 3 }; D) Any of the above 3 methods will work. E) None of the above 3 methods will work.

A

The ________ statement executes one statement, or block of statements, if a condition is true and skips it, doing nothing, if the condition is false. A) if B) if/else C) if/else if D) switch E) if/endif

A

When a program lets the user know that an invalid menu choice has been made, this is an example of A) input validation. B) output validation. C) menu reselection. D) invalidation. E) being user unfriendly.

A

True/False: A switch statement branches to a particular block of code depending on the value of a numeric (i.e. integer or floating-point) variable or constant.

False

True/False: The following statement s will not print anything. x = 5; if (x < 5) cout << "Hello "; cout << "world \n";

False

True/False: The three logical operators, AND, OR, and NOT, all have the same precedence.

False

True/False: To check if a variable has a particular value, use the = relational operator, as in the statement if (s = 3) cout << "S has the value 3";

False

True/False: A pair of characters or a pair of string objects can be compared with any of the relational operators.

True

True/False: Assuming goodData is a Boolean variable, the following two tests are logically equivalent. if (goodData == false) if (!goodData)

True

True/False: Assuming moreData is a Boolean variable, the following two tests are logically equivalent. if (moreData == true) if (moreData)

True

True/False: Relational expressions and logical expressions are both Boolean, which means they evaluate to true or false.

True

True/False: The rule for matching an else with an if is that an else goes with the last if statement before it that doesn't have its own else.

True

A trailing else placed at the end of an if/else if statement provides a default action when ________ of the if conditions is/are true. A) none B) any one C) only the last one D) at least two E) all

A

A(n) ________ is a variable, usually a bool, that signals when a condition exists. A) flag B) identifier C) named constant D) condition variable E) logical variable

A

If a switch statement has no ________ statements, the program "falls through" all of the statements below the one with the matching case expression. A) break B) exit C) case D) default E) relational

A

In C++ when a relational expression is false, it has the value A) 1. B) 0. C) -1. D) "0". E) of any negative number.

B

Relational operators allow you to ________ numbers. A) add B) multiply C) compare D) average E) verify

C

What will the following statement do if x equals 17 and answer = 20? answer = x > 100 ? 0 : 1; A) Assign 0 to answer. B) Assign 0 to x. C) Assign 1 to answer. D) Assign 1 to x. E) Assign 17 to answer.

C

When an if statement is placed within the conditionally-executed code of another if statement, this is known as a(n) A) complex if B) overloaded if C) nested if D) conditional if E) double if

C

) If s1 and s2 are string objects, s1 == s2 is true when A) s1 = "lion" and s2 = "lioness". B) s1 = "dog" and s2 = "DOG". C) s1 = "cat" and s2 = "cat ". D) None of these because in each case one or more characters in the strings have different ASCII codes. E) None of these because string objects cannot be compared with relational operators.

D

A flag is a variable, usually of data type ________, that signals whether or not some condition exists. A) char B) string C) int D) bool E) logical

D

The ________ operator is known as the logical OR operator. A) ! B) & C) && D) || E) //

D

The ________ operator is used in C++ to test for equality. A) = B) <> C) && D) == E) ||

D

The ________ operator takes an operand and reverses its truth or falsehood. A) relational B) && C) || D) ! E) !=

D

Two different variables in the same program may have the same name A) if the second one is never declared. B) if the second one is initialized with a different value than the first one. C) if they always hold different values. D) if they have different scope. E) never. A program cannot have two variables with the same name.

D

What will the following expression evaluate to? !( 6 > 7 || 3 == 4) A) 0 B) -1 C) 6 D) true E) false

D

True/False: If the sub-expression on the left side of an && operator is true, the expression on the right side will not be checked.

False

True/False: Relational operators connect two or more relational expressions into one, or reverse the logic of an expression.

False

True/False: The following C++ test checks if the variable child is in the range 3-12. if (child >= 3 && <= 12)

False

True/False: The following C++ test checks if the variable child is in the range 3-12. if (child >= 3 || child <= 12)

False

) True/False: The statement pass = (score >= 7) ? true : false; does exactly the same thing as the if/else statement below: if (score >= 7) pass = true; else pass = false;

True

True/False: If the sub-expression on the left side of an || operator is true, the expression on the right side will not be checked.

True

True/False: In C++ an expression that evaluates to 5, -5, or for that matter anything other than 0, is considered true by an if statement.

True


Conjuntos de estudio relacionados

Fahrenheit 451 Study Questions, Fahrenheit Study Questions, Fahrenheit 451 Study Guide Part 2 - The Sieve and the Sand, Part 1 - The Hearth and the Salamander, Fahrenheit 451 Study Guide Part 3 - Burning Bright, Fahrenheit 451 Extra questions, Fahren...

View Set

Epidemiology chap 8-12 Quizzes for Exam

View Set

Digital Technologies Chapter 6 and Cloud Computing

View Set

M 41: Drugs for Peptic Ulcer Disease

View Set

Principles of Management, Unit 3

View Set

Chapter 25: Nursing Care of the Child With an Alteration in Immunity or Immunologic Disorder

View Set