chapter 2

advertisement
Programming Right From the Start with Visual Basic.NET
CHAPTER 2
Making Decisions
True-False Questions
1.
The ability of a computer to make a decision is best described as an ability to make a selection
among a set of predefined actions.
Answer: True
Level: Moderate
Section: 2-1
Page: 20
2.
Selection is one of the three control flow constructs identified by Edward Dijkstra as essential to a
logical programming solution.
Answer: True
Level: Easy
Section: 2-1
Page: 21
3.
Because computers cannot truly decide the way humans can, a human operator must always give
the computer input whenever a decision must be made.
Answer: False
Level: Easy
Section: 2-1
Page: 20
4.
An IF statement begins with a block of statements and ends with a condition that is evaluated.
Answer: False
Level: Easy
Section: 2-2
Page: 21
5.
IF statements are used by a computer to make decisions.
Answer: True
Level: Easy
Section: 2-2
Page: 21
6.
There are three blocks of statements in an IF statement.
Answer: False
Level: Easy
Section: 2-2
Page: 21
7.
A condition in an IF statement can evaluate as true, false, or undetermined.
Answer: False
Level: Easy
Section: 2-2
Page: 21
8.
There are six relational operators.
Answer: True
Section: 2-2
Level: Moderate
Page: 21
9.
‘Less Than Or Equal’ cannot be tested directly because an ‘Equal’ condition and a ‘Less Than’
condition must be tested separately.
Answer: False
Level: Moderate
Section: 2-2
Page: 21
10.
The flowchart element for an IF statement is a square.
2-1
Chapter 2 – Making Decisions
Answer: False
Section: 2-2
Level: Easy
Page: 23
11.
All conditions of an IF statement can evaluate to a Boolean expression.
Answer: True
Level: Moderate
Section: 2-2
Page: 23
12.
The only decision structure available to a computer program is the IF statement.
Answer: False
Level: Hard
Section: 2-2
Page: 21
13.
14.
15.
16.
17.
18.
For questions 13 to 18 evaluate the conditions based on C = 10, D = 3, and E = 8.
C=D
Answer: False
Level: Easy
Section: 2-2
Page: 21
D <> E
Answer: True
Section: 2-2
Level: Easy
Page: 21
C>E
Answer: True
Section: 2-2
Level: Easy
Page: 21
C<D
Answer: False
Section: 2-2
Level: Easy
Page: 21
D >= E
Answer: False
Section: 2-2
Level: Easy
Page: 21
C <= E
Answer: False
Section: 2-2
Level: Easy
Page: 21
19.
A nested IF statement means that there is an IF statement in both the true and false branch of an
IF statement.
Answer: False
Level: Moderate
Section: 2-3
Page: 23
20.
A compound condition has at least three or more conditions joined by a logical operator.
Answer: False
Level: Moderate
Section: 2-4
Page: 24
21.
Every IF statement has two or more conditions.
Answer: False
Section: 2-4
2-2
Level: Moderate
Page: 24
Chapter 2 – Making Decisions
22.
The logical operator joins two conditions.
Answer: True
Section: 2-4
Level: Easy
Page: 24
23.
The logical operators are really the same as relational operators.
Answer: False
Level: Moderate
Section: 2-4
Page: 25
24.
The XOR operator is a relational operator.
Answer: False
Section: 2-4
Level: Easy
Page: 24
The OR operator is a logical operator.
Answer: True
Section: 2-4
Level: Easy
Page: 25
25.
26.
27.
28.
29.
30.
31.
For questions 26 to 31 evaluate the compound conditions based on X = 4, Y = 7, and Z = 4.
NOT (Z = 5)
Answer: True
Level: Easy
Section: 2-4
Page: 25
(X = Z) AND (X = Y)
Answer: False
Section: 2-4
Level: Easy
Page: 25
(X = Z) AND (Y = 7)
Answer: True
Section: 2-4
Level: Easy
Page: 25
(Z = 6) OR (Y=7)
Answer: True
Section: 2-4
Level: Easy
Page: 25
(X = 4) XOR (Y = 7)
Answer: False
Section: 2-4
Level: Easy
Page: 25
(X = 4) XOR (Y = 8)
Answer: True
Section: 2-4
Level: Easy
Page: 25
2-3
Chapter 2 – Making Decisions
Multiple Choice Questions
32.
Another term for a computer making a decision is:
a.) sequential.
b.) selection.
c.) repetition.
d.) iteration.
e.) None of the above.
Answer: b
Section: 2-1
33.
Level: Easy
Page: 20
How does a computer make a decision?
a.) A computers cannot make decisions.
b.) A computer can make a decision if an operator enters information as needed.
c.) A computer’s possible actions must be specified in advance.
d.) A computer can use the sequential control flow construct to make a decision.
e.) A computer can use the repetition control flow construct to make a decision.
Answer: c
Section: 2-1
34.
Level: Moderate
Page: 20
Which is not a valid relational operator?
a.) Equal
b.) Not Equal
c.) Greater Than
d.) Less Than
e.) Greater Than And Less Than
Answer: e
Section: 2-2
35.
Level: Easy
Page: 21
Which is not part of an IF statement?
a.) A condition that evaluates as a Boolean.
b.) A condition that evaluates as true or false.
c.) A true block.
d.) A false block.
e.) All of the above are part of an IF statement.
Answer: e
Section: 2-2
36.
.
Level: Moderate
Page: 21
For A = 4 and B = 8 which evaluates as true?
a.) A = B
b.) A <> B
c.) A > B
d.) A >= B
e.) None of the above.
Answer: b
Level: Easy
2-4
Chapter 2 – Making Decisions
37.
38.
Section: 2-2
For A = 4 and B = 4 which evaluates as true?
a.) A <> B
b.) A < B
c.) A > B
d.) A >= B
e.) None of the above.
Page: 21
Answer: d
Section: 2-2
Level: Easy
Page: 21
An IF statement inside the true block of another IF statement is called:
a.) a nested IF statement.
b.) a branched IF statement.
c.) a conditional operator.
d.) a relational operator.
e.) It is not possible to put an IF statement inside the block of another IF statement.
Answer: a
Section: 2-3
39.
Level: Moderate
Page: 23
Which is not a logical operator?
a.) NOT
b.) AND
c.) OR
d.) XAND
e.) XOR
Answer: d
Section: 2-4
40.
Level: Easy
Page: 25
What does a compound condition use to join two conditions?
a.) Relational Operator
b.) Logical Operator
c.) Relational Results
d.) Logical Results
e.) None of the above.
Answer: b
Section: 2-4
41.
Level: Easy
Page: 25
For A = 3 and B = 7 which evaluates as true?
a.) NOT (A < B)
b.) NOT (B < 6)
c.) (A = 3) AND (B = 5)
d.) (A = B) OR (A > B)
e.) (A < B) XOR (A <> B)
Answer: b
Section: 2-4
Level: Moderate
Page: 25
2-5
.
Chapter 2 – Making Decisions
42. For A = 5 and B = 2 which evaluates as true?
a.) NOT (A < 9)
b.) NOT (B < 6)
c.) (A = 3) AND (B = 5)
d.) (A = B) OR (A > B)
e.) (A < 1) XOR (A = B)
Answer: d
Section: 2-4
43.
Level: Moderate
Page: 25
For A = 7 and B = 14 which evaluates as true?
a.) NOT (A < B)
b.) (A = 7) AND (B = 9)
c.) (A < 6) OR (B <= 12)
d.) (A = B) OR (A > B)
e.) (A < 10) XOR (A = B)
Answer: e
Section: 2-4
Level: Moderate
Page: 25
Fill in the Blank Questions
44.
According to Edward Dijkstra the three control flow constructs required for logical programming
solution are ___sequential___, ___selection___, and ___repetition___.
Level: Hard
Section: 2-1
Page: 21
45.
Name one of the three flow constructs Edward Dijkstra stated is required for a logical
programming solution: ___sequential (selection or repetition)___.
Level: Easy
Section: 2-1
Page: 21
46.
A computer cannot really make a decision, it really makes a ___selection___.
Level: Easy
Section: 2-1
Page: 20
47.
When a computer makes a decision it selects among ___predefined___ actions.
Level: Moderate
Section: 2-1
Page: 20
48.
A condition will evaluate to a ___Boolean___ value of true or false.
Level: Moderate
Section: 2-2
Page: 23
49.
The IF statement always begins with a ___condition___.
Level: Easy
Section: 2-2
Page: 21
2-6
Chapter 2 – Making Decisions
50.
The flowchart symbol of an IF statement is the ___diamond___.
Level: Easy
Section: 2-2
Page: 23
51.
There are ___two___ blocks of statements in an IF statement.
Level: Easy
Section: 2-2
Page: 21
52.
A(n) ___nested IF___ statement is when an IF statement is inside a true or false block of an IF
statement.
Level: Moderate
Section: 2-3
Page: 23
53.
A(n) ___compound___ condition is joined by a logical operator.
Level: Moderate
Section: 2-4
Page: 24
54.
NOT, AND, and OR are examples of ___logical___ operators.
Level: Easy
Section: 2-4
Page: 24
55.
___Parentheses___ are needed to enclose conditions within a compound condition.
Level: Hard
Section: 2-4
Page: 25
Essay Questions
56.
Explain how a computer makes a decision.
A computer makes a decision based on predefined criteria set up by the programmer. In fact, the
program does not make a decision; it selects a predefined action based on the criteria. The
criteria the computer uses can only change if the program itself changes. The criteria the
computer uses to make a decision and the actions it will take must be determined before the
program is written. Only the input data that is evaluated against the criteria will change while
the program is running.
2-7
Download