Chapter 5 Study Guide

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

Two approaches to program testing are ____________________ coverage and data coverage.

code

Taking some actual values and hand-calculating what the output of a program should be is called a(n) ____________________.

execution trace

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

flow of control

In programming languages that use ____________________ evaluation of a logical expression, all subexpressions are evaluated before applying any logical operators.

full

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

When placing an If statement within an If statement, a computer programmer is creating a ___________.

nested control structure

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

postcondition

A(n) ____________________ is an assertion that must be true before a module begins executing.

precondition

The operators <, ==, >=, and != are examples of ____________________ operators. (Do not answer "binary.")

relational

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

selection

A(n) ____________________ is the process of going through the steps of an algorithm to confirm that they produce the required postcondition, given the stated precondition.

code walk-through

After the code is written in the implementation phase, you should go over it line by line. This process is known as a(n) ____________________.

code walk-through

Any statement used to alter the normally sequential flow of control is called a(n) ____________________.

control structure

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

Write a C++ logical expression that is true if the variable testScore is greater than or equal to 90 and less than or equal to 100: __________________

testScore >=90 && testScore <= 100

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; A. 0 B. 5 C. 10 D. 15 E. 25

A. 0

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. Nothing is output. B. Hello C. There D. HelloThere

A. Nothing is output.

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

A. true

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

B. an arithmetic expression followed by a logical operator followed by an arithmetic expression

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

B. data that executes every branch at least once.

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. false C. none; it causes a compile-time error D. none; it causes a run-time error

B. 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 B. myfile.dat C. !inFile D. !myfile.dat E. inFile != myfile.dat

C. !inFile

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 150 B. 120 30 90 C. 120 50 170 D. 120 50 70 E. 120 30 70

C. 120 50 170

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. Curly B. Moe Larry Curly C. Larry Curly D. no output; there is a compile-time error E. no output; there is a run-time error

C. Larry Curly

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

C. p && !p

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

D. &&

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. 5 C. 10 D. 15 E. 25

D. 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. 0 B. 5 C. 10 D. 15 E. 25

D. 15

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

D. 27

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

D. b and c above

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. false C. 20 D. true

D. true

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. 5 C. 10 D. 15 E. 25

E. 25

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 nothing unless j equals k. B. It always prints 4 .C. It prints 2 if j equals k and 4 otherwise. D. It prints 2 if j < k and 1 if k <= j. E. It prints 2 if j < k and 4 otherwise.

E. It prints 2 if j < k and 4 otherwise.

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

E. a, b, and c above

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

E. none of the above


Set pelajaran terkait

Ch. 11 - Title Closing and Costs

View Set

Unit 2, Part 1: Mobility - Bones, Exercise, and Mobility assessment

View Set

Chapter 17 Lesson 2 Geography Turkey

View Set

Pectoralis Major & Latissimus Dorsi

View Set