CSE 100 Chapter 4

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

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

Answer: C

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

Answer: C

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(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

Answer: 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

Answer: 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/elseif D) switch E) if/endif

Answer: 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.

Answer: A

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.

Answer: 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.

Answer: B

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

Answer: 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 or until the construct is exited without any test ever evaluating to true. A) if/then B) if/else C) if/elseif D) if/notif E) if/endif

Answer: C

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

Answer: 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.

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

Answer: C

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

Answer: D

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.

Answer: D

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

Answer: D

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

Answer: D

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

Answer: D

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

Answer: D

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: 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 to 12. if (child >= 3 || child <= 12)

FALSE

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

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: logical operators AND and OR have a higher precedence than the NOT operator.

FALSE

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

TRUE

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

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: 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: Relational expressions and logical expressions are both Boolean, which means they evaluate to true or false.

TRUE

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

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

Answer: A

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

Answer: E

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

Answer: E

True/False: The scope of a variable is the program it is defined in

FALSE

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

TRUE


Kaugnay na mga set ng pag-aaral

Conceptual Physics--Test Review Chp 2 to 9

View Set

Математика с нуля

View Set

Cognitive Psych Quiz 1: Chapter 3

View Set

Growth and Development of the School-age Child

View Set

Quiz #3- Informative Communication & Outlining Informative Speeches

View Set

024 - Chapter 24 - Praxis 5039 (Chapter Test)

View Set

ENTR 3001 : Assignment: Chapter 02

View Set

Chapter 7: Community Health Planning, Implementation, and Evaluation

View Set

HURST: FLUID AND ELECTROLYTE POST QUIZ

View Set