C++ Test #1

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

True/False: The amount of memory used by an array depends solely on the number of elements the array can hold

False

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

!

The C++ _________ operator represents logical AND. A) ++ B) AND C) I I D) & E) &&

&&

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

0

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

==

In a for statement, the ________ expression is executed only once. A) initialization B) test C) repeat D) validate E) update

A

The ideal type of loop to use for repeating a menu is a(n) ________ loop A) do-while B) for C) sentinel controlled D) infinite E) nested

A

The while loop has two important parts: a condition that is tested and a statement or block of statements that is executed A) as long as the condition is true. B) until the condition becomes true. C) at least once D) exactly once E) both a and c are true but b and d are not

A

For data validation, it is best to use a(n) ________. A) if statement B) while loop C) for loop D) nested loop E) switch statement

B

If nothing within a while loop ever causes the condition to become false, a(n) ________ may occur. A) null value B) infinite loop C) unexpected exit D) compiler error E) system crash

B

The ________ statement causes a loop to terminate early A) stop B) break C) quit D) terminate E) continue

B

The ideal type of loop to use if you want a user to enter exactly 20 values is a(n) _______ loop A) do-while B) for C) sentinel controlled D) infinite E) nested

B

The statements in the body of a do-while loop are executed A) exactly once B) at least once C) only if the test condition in initially true D) must be a negative number E) is all of the above

B

The statements in the body of a do-while loop are executed A) only if the test condition is initially true B) at least once C) until the test condition becomes true D) until an exit statement is encountered E) forever until the user presses the break key

B

To __________ a value means to increase it A) decrement B) increment C) add up D) accumulate E) total

B

__________ are C++ operators that change their operands by one A) + and - B) ++ and -- C) binary and unary D) arithmetic and relational E) conditional and relational

B

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

Break

A for statement contains three expressions: initialization, test, and A) repeat B) validate C) update D) quit E) increment

C

A sentinel is a special value that A) is used for data validation B) must be Boolean C) marks the end of a list of values D) must be a negative number E) is all of the above

C

A variable that keeps a running total of data values is called a(n) ________. A) total B) sum C) accumulator D) counter E) loop control variable

C

A(n) _________ is a special value that marks the end of a list of values A) counter B) accumulator C) sentinel D) total E) loop control variable

C

If a while loop has no braces around the body of the loop A) there is no loop body B) the loop body ends when the endwhile statement is encountered C) the loop body contains just one statement D) the program will not compile E) the program will compile, but not run

C

Unlike regular variables, arrays can hold multiple A) data types B) named constants C) values D) variables E) operators

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

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

Compare

If s1 and s2 are string objects, s1 == s2 is true when A) s1 = "lion" ans s2 = "lioness" B) s1 = "dog" ans s2 = "DOG" C) s1 = "cat" and s2 = " cat " D) Noe 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

The ++ operator A) is a unary operator. B) adds one to the value of its operand. C) can operate in prefix or postfix mode. D) All of the above. E) Both B and C, but not A.

D

The while loop is a(n) ________ loop, whereas the do-while loop is a(n) ________ loop. A) finite, infinite B) infinite, finite C) simple, complex D) pretest, post test E) post test, pretest

D

You may define a(n) ________ in the initialization expression of a for loop. A) new data type B) new keyword C) constant D) variable E) operator

D

The -- operator A) is a unary operator B) subtracts one from the value of its operand C) must have an Ivalue, such as a variable, as its operand D) can be used in either prefix or postfix mode E) All of the above are true

E

The do-while loop is a(n) ________ loop, whereas the while loop is a(n) _________ loop A) finite, infinite B) infinite, finite C) simple, complex D) pretest, post test E) post test, pretest

E

What will the following code print? num = 5; out << num++ << " "; cout << num-- << " "; cout << --num; A) 5 4 3 B) 5 5 4 C) 5 6 4 D) 5 6 5 E) 6 5 4

E

True/False: A while loop is somewhat limited because the counter can only be incremented or decremented by one each time through the loop

False

True/False: A while loop is somewhat limited, because the counter can only count up, not down.

False

True/False: A while loop may have a semicolon after the test expression and before the body of the loop, but it is not required.

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 <=)

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: To decrement a number means to increase its value

False

True/False: When a loop is nested inside another loop, the outer loop goes through all its iterations for each iteration of the inner loop.

False

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

Flag

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

If

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

If

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

If/else

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/else if D) if/not if E) if/endif

If/else if

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

Nested if

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

None

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

Relational

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

True

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

True

True/False: Assuming goodData is a Boolean variable, the following two tests are logically equivalent

True

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

True

True/False: Before beginning to add value to it, an accumulator should be initialized to 1

True

True/False: If the sub-expression in the left side of an I I 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 block of code in the body of a while statement can contain an unlimited number of statements, provided they are enclosed in a set of braces

True

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

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

True/False: When a loop is nested inside another loop, the inner loop goes through all its iterations for each iteration of the outer loop

True

True/False: You can nest a for loop inside another for loop, but cannot nest a while loop inside another while loop or a do-while loop inside another do-while loop

True

True/False: logical operators AND and OR have a higher precedence than the NOT operator.

True

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

True

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

input validation

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

| |

The while loop has two important parts: a condition that is tested and a statement or block of statements that is A) repeated as long as the condition is true. B) repeated until the condition becomes true. C) done once if the condition is true. D) always done at least once, then repeated if the condition is true. E) always skipped.

A

What will the following code print? num = 8; cout << --num << " "; cout << num++ << " "; cout << num; A) 7 7 8 B) 7 8 8 C) 8 7 7 D) 8 7 8 E) None of these

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

A


Kaugnay na mga set ng pag-aaral

Chapter 48: Musculoskeletal or Articular Dysfunction

View Set

Intermolecular Forces: Liquids, Solids, and Phase, Chem Ch. 12 LS, Chem 132 LearnSmart Ch. 12.3, 13.1-4, Chemistry Chapter 12, Chapter 12, Chem 102 Connect 12.5-12.6, Chapter 12 SmartBook, Chem 2 Chapter 12, Chemistry 124 Chapter 12: Molecular Nature...

View Set

Chapter 01 : General Information For Electrical Installations

View Set

Med Surg Chapter 12 Oncologic Management

View Set

The Canterbury Tales: "The Pardoner's Tales"

View Set

International Management Chapter 1

View Set

Why did the colonists fight the british?

View Set

Menstrual Cycle (SONO 123 Week 1)

View Set

N350 Project 1 Linkedin Learning Quiz

View Set