Name:     ID: 
 
Email: 

CH6

True/False
Indicate whether the statement is true or false.
 

 1. 

You use the selection structure when you want a program to make a decision or comparison and then select one of two paths, depending on the result of that decision or comparison.
 

 2. 

Both paths in a selection structure can include instructions that declare variables.
 

 3. 

The false path of a selection structure cannot include other selection structures.
 

 4. 

You use a nested selection structure when more than one decision must be made before the appropriate action can be taken.
 

 5. 

When using nested selection structures, the primary decision is always made by the inner selection structure.
 

 6. 

When nesting selection structures, it is better to nest the selection structure in the true path of the outer selection structure, instead of in the false path.
 

 7. 

An algorithm can be written in pseudocode or it can be depicted by a flowchart.
 

 8. 

A common source of logic errors in selection structures is using a logical operator rather than a nested selection structure.
 

 9. 

A common way of optimizing nested selection structures is to reverse the primary and secondary decisions.
 

 10. 

A common source of logic errors in selection structures is using an unnecessary nested selection structure.
 

 11. 

It is important to desk-check an algorithm several times using different test data.
 

 12. 

It is easy to detect if you have incorrectly used a logical operator in the outer selection structure’s condition when a nested selection structure was needed because the error will always appear during your first desk-check.
 

 13. 

When nesting selection structures, you can interchangeably put the secondary decision in the outer selection structure, and put the primary decision in the nested selection structure.
 

 14. 

In most cases, a selection structure that includes an unnecessary nested selection structure will produce incorrect results.
 

 15. 

Some algorithms require selection structures that are capable of choosing from several alternatives.
 

 16. 

You must use the switch form of the selection structure to create a multiple-path selection structure in C++.
 

 17. 

In a flowchart, the if/else and switch selection structures are represented in exactly the same way.
 

 18. 

In a flowchart, the switch diamond contains a condition requiring a true or false answer.
 

 19. 

In a flowchart, the switch diamond contains an expression whose value determines which path is chosen.
 

 20. 

In a flowchart, each flowline leading out of the switch symbol represents a possible path for the selection structure.
 

 21. 

It is a good programming practice to document the end of the switch statement with the //end switch comment.
 

 22. 

In the switch statement, each switch clause represents a different path that the selection structure can follow.
 

 23. 

You can include as many case clauses as necessary in a switch statement.
 

 24. 

The default clause must be the last clause in a switch statement.
 

 25. 

The statements within a case clause must be enclosed in braces.
 

Multiple Choice
Identify the choice that best completes the statement or answers the question.
 

 26. 

When one of the paths of a selection structure contains another selection structure, the inner selection structure is referred to as a ____ selection structure.
a.
child
c.
structured
b.
nested
d.
derived
 

 27. 

A nested selection structure is contained within the ____ selection structure.
a.
child
c.
inner
b.
parent
d.
outer
 

 28. 

When using nested selection structures, the secondary decision is always made by the ____ selection structure.
a.
child
c.
inner
b.
parent
d.
outer
 

 29. 

A(n) ____ is a set of step-by-step instructions that accomplish a task.
a.
algorithm
c.
flowchart
b.
pseudocode
d.
IPO
 
 
Consider the following pseudocode:

1. enter the code and sales amount
2. calculate the bonus amount by multiplying the sales amount by .08
3. if (the code is X)
      if (the sales are greater than or equal to 10000)
            add 150 to the bonus amount
      else
            add 125 to the bonus amount
      end if
    end if
4. display the bonus amount
 

 30. 

If the code is X and the sales amount is 15000, the value of the bonus amount at the end of the algorithm will be ____.
a.
720
c.
1200
b.
845
d.
1350
 

 31. 

If the code is X and the sales amount is 9000, the value of the bonus amount at the end of the algorithm will be ____.
a.
720
c.
1200
b.
845
d.
1350
 

 32. 

If the code is A and the sales amount is 13000, the value of the bonus amount at the end of the algorithm will be ____.
a.
720
c.
1165
b.
1040
d.
1190
 

 33. 

A common error made when writing selection structures is to use a ____ operator in the outer selection structure’s condition when a nested selection structure is needed.
a.
logical
c.
mathematical
b.
comparison
d.
concatenation
 

 34. 

When you use the ____ logical operator to combine two conditions in a selection structure, both conditions must be true for the compound condition to be true.
a.
and
c.
xor
b.
or
d.
not
 

 35. 

What is the problem with the following algorithm?

1. enter the code and sales amount
2. calculate the bonus amount by multiplying the sales amount by .08
3. if (the code is X)
      if (the sales are greater than or equal to 10000)
            add 150 to the bonus amount
      else
            if (the sales are less than 10000)
                  add 125 to the bonus amount
            end if
      end if
    end if
4. display the bonus amount
a.
It includes an unnecessary nested selection structure.
b.
The primary and secondary decisions are reversed.
c.
It uses a logical operator when a nested selection structure should be used.
d.
There is no problem with the algorithm.
 

 36. 

What is the problem with the following algorithm?

1. enter the code and sales amount
2. calculate the bonus amount by multiplying the sales amount by .08
3. if (the code is X)
      if (the sales are greater than or equal to 10000)
            add 150 to the bonus amount
      else
            if (the sales are less than 10000)
                  add 125 to the bonus amount
            end if
      end if
    end if
4. display the bonus amount
a.
It is hard to read.
b.
It should use a switch instead of nested selection structures.
c.
It is inefficient.
d.
There is no problem with the algorithm.
 

 37. 

Multiple-path selection structures are also referred to as ____ selection structures.
a.
nested
c.
complex
b.
switch
d.
extended
 

 38. 

A program that displays a message based on a letter grade that the user enters would require a(n) ____ selection structure.
a.
if
c.
nested
b.
multiple-path
d.
else
 

 39. 

The switch form of the selection structure is also called the ____ form.
a.
case
c.
multiple-path
b.
nested
d.
otherwise
 

 40. 

The following algorithm uses the ____ form of the selection structure.

1. enter grade
2. grade value:
      A       display “Excellent”
      B       display “Above Average”
      C       display “Average”
      D, F       display “Below Average”
      Other       display “Error”
a.
if
c.
nested if
b.
if/else
d.
switch
 

 41. 

The flowchart symbol for the switch form of the selection structure is the ____.
a.
oval
c.
diamond
b.
rectangle
d.
parallelogram
 

 42. 

In a flowchart, the switch symbol has ____ flowline(s) leading into the symbol.
a.
one
c.
three
b.
two
d.
many
 

 43. 

In a flowchart, the switch symbol has ____ flowline(s) leading out of the symbol.
a.
zero
c.
two
b.
one
d.
many
 

 44. 

In C++, you use the ____ statement to code the switch form of the selection structure.
a.
if
c.
case
b.
if/else
d.
switch
 

 45. 

In C++, the switch statement begins with the switch clause followed by an opening ____.
a.
[
c.
<
b.
{
d.
 

 46. 

Between the switch statement’s opening and closing braces are the individual ____ clauses.
a.
case
c.
if/else
b.
if
d.
else
 

 47. 

If the default clause is not the last clause in the switch statement, you will need to include a ____ statement at the end of the clause to stop the computer from processing the instructions in the next case clause.
a.
continue
c.
stop
b.
break
d.
switch
 

 48. 

Each of the individual case clauses within the switch statement contains a value followed by a ____.
a.
->
c.
:
b.
;
d.
.
 

 49. 

The ____ statement tells the computer to leave the switch statement at that point.
a.
break
c.
stop
b.
continue
d.
case
 

 50. 

In the switch statement, when the selectorExpression does not match any of the values listed in the case clauses, the computer processes the instructions contained in the ____ clause or, if this clause is not available, it skips to the instruction following the switch statement’s closing brace.
a.
break
c.
default
b.
else
d.
otherwise
 



 
         Start Over