Chapter 4 Review (Test Prep)

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

11. AND, OR, and NOT are _______ operators. 1. relational 2. logical 3. conditional 4. ternary

logical

4.27 What values can you store in a Boolean variable?

true or false

6. When determining whether a number is inside a range, which logical operator is it best to use?

the AND operator should be used to determine whether or not a number is within a defined range.

What would be displayed if the following pseudocode was coded and executed, with salary = 400? If salary > 400 Then Set bonus = 10 Set salary = salary = bonus Else Set salary = salary + salary * .20 End If Display Salary 80 480 400 410

480

Which of the following is not a logical operator?

<>

4.3What is a single alternative decision structure?

A decision structure that provides a single alternative path of execution. If the condition that is being tested is true, the program takes the alternative path.

4.13 How does a dual alternative decision structure work?

A dual alternative decision structure has two possible paths of execution—one path is taken if a condition is true, and the other path is taken if the condition is false.

4.8 How does a dual alternative decision structure work?

A dual alternative decision structure has two possible paths of execution—one path is taken if a condition is true, and the other path is taken if the condition is false.

4.28 What is a flag variable?

A variable that signals when some condition exists in the program.

12. A compound Boolean expression created with the _______ operator is true only if both of its subexpressions are true. 1. AND 2. OR 3. NOT 4. BOTH

AND

The ________ operator requires that both subexpressions be True for the compound expression to be True.

AND

4.4 What is a Boolean expression?

An expression that can only be evaluated as either true or false.

7. What is a flag and how does it work?

Boolean variables are most commonly used as flags. A flag is a variable that signals when some condition exists in the program. When the flag variable is set to False, it indicates the condition does not exist. When the flag variable is set to True, it means the condition does exist.

4.12 If the following pseudocode were an actual program, what would it display? Declare String s1 = "New York" Declare String s2 = "Boston" If s1 > s2 Then Display s2 Display s1 Else Display s1 Display s2 End If

Boston New York

10. A(n) _____ section of a Select Case statement is branched to if none of the case values match the expression listed after the Select statement. 1. Else 2. Default 3. Case 4. Otherwise

Default

2. A program can be made of only one type of control structure. You cannot combine structures.

False (decision structures exist along side control sequence structures)

The OR operator will evaluate to True only if both subexpressions are also True.

False (only one side of the equation needs to be true)

3. A single alternative decision structure tests a condition and then takes one path if the condition is true, or another path if the condition is false.

False (the question describes a dual alternative decision structure.)

4.16 Convert the following pseudocode to an If-Then-Else If statement: If number == 1 Then Display "One" Else If number == 2 Then Display "Two" Else If number == 3 Then Display "Three" Else Display "Unknown" End If End If End If

If number == 1 Then Display "One" Else If number == 2 Then Display "Two" Else If number == 3 Then Display "Three" Else Display "Unknown" End If

4.7 Write a pseudocode If-Then statement that assigns 0.2 to commission if sales is greater than or equal to 10,000.

If sales >= 10000 Then Set commission = 0.2 End If

4.26 Write an If-Then statement that displays the message "The number is not valid" if the variable speed is outside the range 0 through 200.

If speed < 0 OR speed > 200 Then Display "The number is not valid" End If

8. You use a(n) _______ statement in pseudocode to write a dual alternative decision structure. 1. Test-Jump 2. If-Then 3. If-Then-Else 4. If-Call

If-Then-Else

14. The ______ operator takes a Boolean expression as its operand and reverses its logical value. 1. AND 2. OR 3. NOT 4. EITHER

NOT

4.19 What does the case structure test, in order to determine which set of statements to execute?

variable or an expression

2. You need to test a condition and then execute one set of statements if the condition is true. If the condition is false, you need to execute a different set of statements. What structure will you use?

you'll use a dual alternative decision structure. If the IF-Then statement is true you'll execute the related statement. If the IF-Then statement is false, the Else statements are executed.

4.11 If the following pseudocode were an actual program, what would it display? If "z" < "a" Then Display "z is less than a." Else Display "z is not less than a." End If

z is not less than a.

4.17 What is a multiple alternative decision structure?

A structure that tests the value of a variable or an expression and then uses that value to determine which statement or set of statements to execute.

4.22 The following truth table shows various combinations of the values true and false connected by a logical operator. Complete the table by circling T or F to indicate whether the result of such a combination is true or false. Check question for options

F T F F T T T F F T

4.25Write an If-Then statement that displays the message "The number is valid" if the variable speed is within the range 0 through 200.

If speed >= 0 AND speed <= 200 Then Display "The number is valid" End If

4.15 When you write an If-Then-Else statement, under what circumstances do the statements that appear between the Else clause and the End If clause execute?

If the condition is false

4.9 What statement do you use in pseudocode to write a dual alternative decision structure?

If then Else statement

4.6 Write a pseudocode If-Then statement that assigns 0 to x if y is equal to 20.

If y == 20 Then Set x = 0 End If

7. You use a(n) ______ statement in pseudocode to write a single alternative decision structure. 1. Test-Jump 2. If-Then 3. If-Then-Else 4. If-Call

If-Then

4.14 What statement do you use in pseudocode to write a dual alternative decision structure?

If-Then-Else

4.20 You need to write a multiple alternative decision structure, but the language you are using will not allow you to perform the test you need in a Select Case statement. What can you do to achieve the same results?

In such an event, you can use the If-Then-Else If statement, or a nested decision structure.

4.2 What is a decision structure?

It is a program structure that can execute a set of statements only under certain circumstances.

4.21 What is a compound Boolean expression?

It is an expression that is created by using a logical operator to combine two Boolean subexpressions.

13. A compound Boolean expression created with the ______ operator is true if either of its subexpressions is true. 1. AND 2. OR 3. NOT 4. EITHER

OR

What is another term for decision structure?

Selection structures

4. A decision structure can be nested inside another decision structure.

True (nested decision structures are an option to test multiple conditions)

4.10 When you write an If-Then-Else statement, under what circumstances do the statements that appear between Else and End If execute?

When the condition is false.

4.18 How do you write a multiple alternative decision structure in pseudocode?

With a Select Case statement. test expression with multiple case values/statements for each condition you'd like to test.

4.5 What types of relationships between values can you test with relational operators?

You can determine whether one value is greater than, less than, greater than or equal to, less than or equal to, equal to, or not equal to another value.

6. A(n) ______ structure tests a condition and then takes one path if the condition is true, or another path if the condition is false. 1. If-Then statement 2. single alternative decision 3. dual alternative decision 4. sequence

dual alternative decision

4. Briefly describe how the AND operator works.

establishes a condition in which both sides of the equation need to be true in order for a particular set of statements to execute.

5. Briefly describe how the OR operator works.

establishes a condition in which one side of the equation need to be true in order for a particular set of statements to execute.

(t or f) 1. You can write any program using only sequence structures.

false (Although the sequence structure is heavily used in programming, it cannot handle every type of task.)

15. A _____ is a Boolean variable that signals when some condition exists in the program. 1. flag 2. signal 3. sentinel 4. siren

flag

5. The symbols >, <, and == are all ______ operators. 1. relational 2. logical 3. conditional 4. ternary

relational

2. A _______ structure provides one alternative path of execution. 1. sequence 2. single alternative decision 3. one path alternative 4. single execution decision

single alternative decision

In many languages the case structure is called a _____ statement.

switch

The ________ alternative decision structure provides two paths of execution.

dual

5. A compound Boolean expression created with the AND operator is true only when both subexpressions are true.

True

A nested decision structure can be used to test more than one condition.

True

4.23 Assume the variables a = 2, b = 4, and c = 6. Circle the T or F for each of the following conditions to indicate whether its value is true or false. a == 4 OR b > 2 T F 6 <= c AND a > 3 T F 1 != b AND c != 3 T F a >= -1 OR a <= b T F NOT (a > 2) T F

T F T T T

4.24 Explain how short-circuit evaluation works with the AND and OR operators.

The AND operator: If the expression on the left side of the AND operator is false, the expression on the right side will not be checked. The OR operator: If the expression on the left side of the OR operator is true, the expression on the right side will not be checked.

(Quiz questions) In many languages the == operator determines whether one variable has the same value as another variable.

True

(short answer) 1. Explain what is meant by the term conditionally executed.

a statement that is executed only when certain conditions are met in a program.

4. A(n) _______ expression has a value of either true or false. 1. binary 2. decision 3. unconditional 4. Boolean

boolean

what's another term for the multiple alternative decision structure?

case structure

If the following pseudocode was coded and run, what would display, given that rate = 2?

check quiz for answer

(multiple choice) 1. A _____ structure can execute a set of statements only under certain circumstances. 1. sequence 2. circumstantial 3. decision 4. Boolean

decision

3. In pseudocode, the If-Then statement is an example of a ________. 1. sequence structure 2. decision structure 3. pathway structure 4. class structure

decision structure

In a flowchart, the ________ symbol indicates that some condition must be tested.

diamond

4.1 What is a control structure?

logical design that controls the order in which a set of statements executes.

A case structure is a ________ alternative decision structure.

multiple

9. A _______ structure allows you to test the value of a variable or an expression and then use that value to determine which statement or set of statements to execute. 1. variable test decision 2. single alternative decision 3. dual alternative decision 4. multiple alternative decision

multiple alternative decision

3. If you need to test the value of a variable and use that value to determine which statement or set of statements to execute, which structure would be the most straightforward to use?

multiple alternative decision structure.


Set pelajaran terkait

Social Studies Chapter 7 Section 1 Landform Regions of North America

View Set

OWare- Consumer Math 9. Job Related Services

View Set

Business English Guffey Chapter 4

View Set