CSC 110 Chapter 5

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

True or False? Implementing a test plan guarantees that a program is completely correct.

False

True or False? Syntactically, the only expressions that can be assigned to Boolean variables are the literal values true and false.

False

True or False? Testing is performed only in the implementation phase of a program's life cycle.

False

True or False? The expression !(n < 5) is equivalent to the expression n > 5.

False

What is the missing If condition in the following code fragment? The program is supposed to halt if the input file does not exist. ifstream inFile; inFile.open("myfile.dat"); if ( ) { cout << "Cannot open input file." << endl; return 1; A. inFile != myfile.dat B. !inFile C. myfile.dat D. !myfile.dat E. inFile

!inFile chapter 5

Which of the following is not a C++ relational operator? A. != B. >= C. < D. && E. ==

&&

If DeMorgan's Law is used to negate the expression (i < j) && (k == l) then the result is: A. (i > j) || (k != l) B. (i > j) && (k != l) C. (i < j) || (k == l) D. (i >= j) && (k != l) E. (i >= j) || (k != l)

(i >= j) || (k != l)

True or False? The statement if (grade == 'A' || grade == 'B' || grade == 'C') cout << "Fail"; else cout << "Pass"; prints Pass if grade is 'A', 'B', or 'C' and prints Fail otherwise.

False

True or False? To test whether someInt equals 25 or 30, the C++ expression someInt == 25 || 30 has the correct semantics but produces a syntax (compile-time) error.

False

If the int variables i, j, and k contain the values 10, 3, and 20, respectively, what is the value of the following logical expression: j < 4 || j == 5 && i <= k A. 3 B. 20 C. false D. true

TRue

Given a Boolean variable isEmpty, which of the following is a valid C++ assignment statement? A. isEmpty = true; B. isEmpty = !isEmpty; C. isEmpty = m > n; D. a and b above E. a, b, and c above

a, b, and c above

Which of the following does not constitute a logical (Boolean) expression? A. a Boolean variable or constant B. a unary logical operator followed by a logical expression C. a logical expression followed by a binary logical operator followed by a logical expression D. an arithmetic expression followed by a relational operator followed by an arithmetic expression E. an arithmetic expression followed by a logical operator followed by an arithmetic expression

an ARITHMETIC expression followed by a LOGICAL operator followed by an arithmetic expression

Which C++ logical expression correctly determines whether the value of beta lies between 0 and 100? A. 0 < beta < 100 B. 0 < beta && beta < 100 C. (0 < beta) && (beta < 100) D. b and c above E. a, b, and c above

b and c

The phrase "minimum complete coverage" means that we test a program with A. all possible data values. B. data that executes every branch at least once. C. at least one set of data. D. data that executes all possible combinations of branches at least once.

data that executes every branch at least once.

The operators <, ==, >=, and != are examples of ____________________ operators

relational

An If statement is an example of a(n) ____________________ control structure

selection

The act of using a C++ stream object in a logical expression as if it were a Boolean variable is called ____________________ of the stream.

testing the state

Write a C++ logical expression that is false if either x or y is equal to 5: ____________________

x != 5 && y != 5

After execution of the following code, what will be the value of angle if the input value is 0? cin >> angle; if (angle > 5) angle = angle + 5; else if (angle > 2) angle = angle + 10;

0

What is the output of the following C++ code fragment? (Be careful here.) int1 = 120; cin >> int2; // Assume user types 30 if ((int1 > 100) && (int2 = 50)) int3 = int1 + int2; else int3 = int1 - int2; cout << int1 << ' ' << int2 << ' ' << int3; A. 120 30 70 B. 120 50 70 C. 120 30 150 D. 120 50 170 E. 120 30 90

120 50 170

After execution of the following code, what will be the value of angle if the input value is 0? cin >> angle; if (angle > 5) angle = angle + 5; else if (angle > 2) angle = angle + 10; else angle = angle + 15; A. 0 B. 15 C. 10 D. 5 E. 25

15

After execution of the following code, what will be the value of angle if the input value is 10? n >> angle; if (angle > 5) angle = angle + 5; else if (angle > 2) angle = angle + 10; A. 10 B. 15 C. 5 D. 0 E. 25

15 after it tests the first if (if it is true) it skips the next else if

After execution of the following code, what will be the value of angle if the input value is 10? cin >> angle; if (angle > 5) angle = angle + 5; if (angle > 2) angle = angle + 10; A. 0 B. 10 C. 25 D. 15 E. 5

25

Consider the following If statement, which is syntactically correct but uses poor style and indentation: if (x >= y) if (y > 0) x = x * y; else if (y < 4) x = x - y; Assume that x and y are int variables containing the values 9 and 3, respectively, before execution of the above statement. After execution of the statement, what value will x contain? A. 9 B. 1 C. 6 D. 27 E. none of the above

27

Which logical operator (op) is defined by the following table? (T and F denote TRUE and FALSE.) P Q P op Q -------- T T T T F F F T F F F F A. NOT B. AND C. OR D. none of the above

AND

True or False? If P and Q are logical expressions, the expression P AND Q is TRUE if either P or Q is TRUE or both are TRUE.

F

Given the following code: string name1; string name2; name1 = "Maryanne"; name2 = "Mary"; what is the value of the relational expression string1 <= string2 ? A. true B. none; it causes a compile-time error C. none; it causes a run-time error D. false

False

True or False? According to DeMorgan's Law, the expression !(x <= y || s > t) is equivalent to x <= y && s > t

False

True or False? Boolean variables cannot store the result of a comparison of two variables

False

True or False? Given the module description PRINT AVERAGE (Level 1) Print a heading IF countOfValues isn't 0 Print sumOfValues / countOfValues ELSE Print an error message the following is an appropriate module precondition: "sumOfValues is assigned AND countOfValues does not equal 0."

False

In order to test the boundaries of the following condition, what data values would you use for the variable alpha? (alpha is of type int.) alpha >= 1 A. INT_MIN, 1, 2, and INT_MAX B. INT_MIN, 0, 1, and INT_MAX C. INT_MIN, 1, and INT_MAX D. 1, 2, and INT_MAX E. 0, 1, and INT_MAX

INT_MIN, 0, 1, and INT_MAX

This question is about short-circuit evaluation of logical expressions. Consider the following expression in some imaginary programming language (not C++): (N > 5) AND (K / N < 12) If N equals 0 when this expression is evaluated, which of the following statements about the expression is true? A. It never causes a divide-by-zero error. B. It causes a divide-by-zero error only if the language uses short-circuit evaluation. C. It causes a divide-by-zero error whether or not the language uses short-circuit evaluation. D. It causes a divide-by-zero error only if the language does not use short-circuit evaluation.

It causes a divide-by-zero ERROR ONLY if the language DOES NOT USE short-circuit evaluation.

What does the following statement print? (All variables are of type int.) if (j < k) if (k < j) cout << 1; else cout << 2; else if (j < k) cout << 3; else cout << 4; A. It prints 2 if j < k and 4 otherwise. B. It prints nothing unless j equals k. C. It prints 2 if j < k and 1 if k <= j. D. It prints 2 if j equals k and 4 otherwise. E. It always prints 4.

It prints 2 if j < k and 4 otherwise.

What is the output of the following code fragment if the input value is 20? (Be careful here.) cin >> someInt; if (someInt > 30) cout << "Moe "; cout << "Larry "; cout << "Curly"; A. no output; there is a compile-time error B. Moe Larry Curly C. Curly D. Larry Curly E. no output; there is a run-time error

Larry Curly vi ko co dung {} trong if statement nen bo qua cout moe va output Larry curly

Given the following code: string name1; string name2; name1 = "Mark"; name2 = "Mary"; what is the value of the relational expression string1 < string2 ? A. none; it causes a compile-time error B. true C. none; it causes a run-time error D. false

True

The code segment if (speed <= 40) cout << "Too slow"; if (speed > 40 && speed <= 55) cout << "Good speed"; if (speed > 55) cout << "Too fast"; could be written equivalently as if (speed <= 40) cout << "Too slow"; else if (speed <= 55) cout << "Good speed"; else cout << "Too fast";

True

True or False? An example of a logical (Boolean) expression is an arithmetic expression followed by a relational operator followed by an arithmetic expression.

True

True or False? Given the module description PRINT AVERAGE (Level 1) Print a heading Print sumOfValues / countOfValues the following is an appropriate module precondition: "sumOfValues is assigned AND countOfValues does not equal 0."

True

True or False? If a C++ If statement begins with if (age = 30) the If condition is an assignment expression, not a relational expression.

True

True or False? If ch1 contains the value 'C' and ch2 contains the value 'K', the value of the C++ expression ch1 <= ch2 is true.

True

True or False? The following represents a list showing the correct order of precedence (from highest to lowest) for the arithmetic, relational, and logical operators with the assignment operator included as well. ! Unary + Unary - ∗ / % + - < <= > >= == != && || =

True

True or False? Testing is performed only in the implementation phase of a program's life cycle

false

The order in which the computer executes statements in a program is called the ____________________.

flow of control

A(n) ____________________ expression is an expression composed of logical (Boolean) values and operations.

logical

The operators &&, ||, and ! are known as ____________________ operators

logical

An If-Then-Else-If structure represents a(n) ____________________-way branch

multi

Consider the following If statement, which is syntactically correct but uses poor style and indentation: if (x >= y) if (y > 0) x = x * y; else if (y < 4) x = x - y; Assume that x and y are int variables containing the values 3 and 9, respectively, before execution of the above statement. After execution of the statement, what value will x contain? A. 9 B. -6 C. 6 D. 27 E. none of the above

none of the above

Assuming alpha and beta are int variables, what is the output of the following code (which is indented poorly)? alpha = 3; beta = 2; if (alpha < 2) { if (beta == 3) cout << "Hello"; else cout << "There"; } A. HelloThere B. There C. Hello D. Nothing is output.

nothing is output

If p is a Boolean variable, which of the following logical expressions always has the value false? A. p && p B. p || p C. p && !p D. p || !p E. b and d above

p && !p

A(n) ____________________ is an assertion that should be true after a module has finished executing

postcondition

In programming languages that use ____________________ evaluation of a logical expression, evaluation proceeds in left-to-right order and stops as soon as the final truth value can be determined.

short-circuit


Set pelajaran terkait

Understanding Culture Society (week 1-2)

View Set