Chapter 3: Understanding Structure
TRUE/FALSE
1. Structured programs use spaghetti code logic.
Answer: False
2. In a selection structure, you perform an action or task, and then you perform the next
action in order.
Answer: False
3. Repetition and sequence are alternate names for a loop structure.
Answer: False
4. In a structured program, any structure can be nested within another structure.
Answer: True
5. A structured program must contain a sequence, selection, and loop structure.
Answer: False
6. Because you may stack and nest structures while retaining the overall structure, it might be
difficult to determine whether a flowchart as a whole is structured.
Answer: True
7. As a general rule, an eof question should always come immediately after an input
statement because the end-of-file condition will be detected at input.
Answer: True
8. Structured programming is sometimes called goto-less programming.
Answer: True
9. No matter how complicated it is, any set of steps can always be reduced to combinations of
the two basic structures of sequence and loop.
Answer: False
10. The case structure is a variation of the sequence structure and the do loop is a variation of
the while loop.
Answer: False
MULTIPLE CHOICE
1. Programs that use _____ code logic are unstructured programs that do not follow the rules
of structured logic.
a. case
b. loop
c. spaghetti
d. nested
Answer: C
2. With a(n) ____, you perform an action or task, and then you perform the next action, in
order.
a. ordered structure
b. sequence problem
c. sequence structure
d. loop sequence
Answer: C
3. The following pseudocode is an example of a ____ structure.
a. sequence
b. decision
c. loop
d. nested
Answer: A
4. The following pseudocode is an example of a ____ structure.
a. sequence
b. decision
c. loop
d. nested
Answer: B
5. Fill in the blank in the following pseudocode:
a. then
b. while
c. do
d. else
Answer: D
6. if-else examples can also be called ____ because they contain the action taken when the
tested condition is true and the action taken when it is false.
a. do loops
b. single-alternative selections
c. repetition
d. dual-alternative selections
Answer: D
7. The following pseudocode is an example of a ____ structure.
a. sequence
b. decision
c. loop
d. nested
Answer: C
8. You may hear programmers refer to looping as ____.
a. execution
b. selection
c. iteration
d. case
Answer: C
9. The action or actions that occur within a loop are known as a(n) ____.
a. loop body
b. action body
c. loop internals
d. structure body
Answer: A
10. The following pseudocode is an example of ____.
a. nesting
b. stacking
c. single alternative structures
d. a posttest
Answer: B
11. Attaching structures end to end is called ____ structures.
a. linking
b. stacking
c. nesting
d. building
Answer: B
12. The following pseudocode is an example of ____.
a. nesting
b. stacking
c. a posttest
d. a pretest
Answer: A
13. Placing a structure within another structure is called ____ structures.
a. nesting
b. stacking
c. shelling
d. selecting
Answer: A
14. You can use an ____ statement to clearly show where the actions that depend on a
decision end.
a. end
b. endstructure
c. endloop
d. endif
Answer: D
15. The maximum number of entry points that any programming structure can have is ____.
a. zero
b. one
c. three
d. five
Answer: B
16. A structured program includes only combinations of the three basic structures: ____.
a. sequence, iteration, and loop
b. iteration, selection, and loop
c. sequence, selection, and loop
d. identification, selection, and loop
Answer: C
17. Structures can be stacked or connected to one another at their ____.
a. entry points only
b. exit points only
c. entry or exit points
d. entry or combination points
Answer: C
18. A ____ read is an added statement that gets the first input value in a program.
a. nested
b. stacked
c. posttest
d. priming
Answer: D
19. The priming read is an example of a(n) ____ task.
a. declaration
b. exit
c. housekeeping
d. selection
Answer: C
20. In older languages, you could leave a selection or loop before it was complete by using a
____ statement.
a. loop
b. go next
c. next
d. go to
Answer: D
21. Structured programs can be easily broken down into routines or ____ that can be assigned
to any number of programmers.
a. segments
b. modules
c. units
d. sequences
Answer: B
22. One way to straighten out an unstructured flowchart segment is to use the ____ method.
a. spaghetti code
b. spaghetti bowl
c. restructuring
d. priming
Answer: B
23. A loop must return to the ____ question at some later point in a structure.
a. start loop
b. loop-controlling
c. master loop
d. continue loop
Answer: B
24. The do loop is a variation of the ____ loop.
a. if-then-else
b. while
c. case
d. sequence
Answer: B
25. The case structure is a variation of the ____ structure.
a. selection
b. while
c. sequence
d. do
Answer: A
COMPLETION
1. A(n) ____________________ can contain any number of tasks, but there is no option to
branch off and skip any of the tasks.
Answer: sequence
2. Some people call the selection structure a(n) ____________________ statement.
Answer: if-then-else
if then else
3. A group of statements that execute as a single unit are called a(n) ____________________.
Answer: block
4. When you ____________________ structures, the statements that start and end a structure
are always on the same level and always in pairs.
Answer: nest
5. Structured programming is sometimes called ____________________-less programming.
Answer: goto
go to
go-to
MATCHING
Match each term with a statement below.
1. Logically snarled program statements a. structure
2. A basic unit of programming logic b. priming read
3. With this, you ask a question, and, depending on the answer, you take one of two courses
of action c. module
4. Continue to repeat actions while a condition remains true d. decision structure
5. An added statement that gets the first input value in a program e. null case
6. Placing a structure within another structure f. stacking structures
7. A case in which nothing is done g. spaghetti code
8. Attaching structures end-to-end h. loop structure
9. Often can be used in multiple programs i. case structure
10. A variation of the selection structure j. nesting structures
1. Answer: G
2. Answer: A
3. Answer: D
4. Answer: H
5. Answer: B
6. Answer: J
7. Answer: E
8. Answer: F
9. Answer: C
10. Answer: I
SHORT ANSWER
1. Why does spaghetti code have a shorter shelf life than structured code?
Answer: Software developers say that spaghetti code has a shorter life than structured code.
This means that programs developed using spaghetti code exist as production programs in an
organization for less time. Such programs are so difficult to alter that when improvements are
required, developers often find it easier to abandon the existing program and start from
scratch. Obviously, this costs more money.
2. Define the term structure as it relates to programming.
Answer: In the mid-1960s, mathematicians proved that any program, no matter how
complicated, can be constructed using one or more of only three structures. A structure is a
basic unit of programming logic; each structure is a sequence, selection, or loop. With these
three structures alone, you can diagram any task, from doubling a number to performing brain
surgery. You can diagram each structure with a specific configuration of flowchart symbols.
3. Describe a loop structure.
Answer: In a loop structure, you continue to repeat actions while a condition remains true.
The action or actions that occur within the loop are known as the loop body. In the most
common type of loop, a condition is evaluated; if the answer is true, you execute the loop
body and evaluate the condition again. If the condition is still true, you execute the loop body
again and then reevaluate the original condition. This continues until the condition becomes
false, and then you exit the structure.
4. Rewrite the following as a while loop:
Answer:
5. All logic problems can be solved using only these three structures: sequence, selection, and
loop. The three structures, of course, can be combined in an infinite number of ways. What
are two general ways structures can be combined?
Answer: You can have a sequence of tasks followed by a selection, or a loop followed by a
sequence. Attaching structures end-to-end is called stacking structures. Besides stacking
structures, you can replace any individual tasks or steps in a structured flowchart diagram or
pseudocode segment with additional structures. In other words, any sequence, selection, or
loop can contain other sequences, selections, or loops. For example, you can have a sequence
of three tasks on one side of a selection. Placing a structure within another structure is called
nesting structures.
6. What are the characteristics of a structured program?
Answer: • A structured program includes only combinations of the three basic structures:
sequence, selection, and loop. Any structured program might contain one, two, or all three
types of structures.
• Each structure has a single entry point and a single exit point.
• Structures can be stacked or connected to one another only at their entry or exit points.
• Any structure can be nested within another structure.
7. Explain the difference between the representation of a decision structure and a loop in a
flowchart.
Answer: In a selection structure, the logic goes in one of two directions after the question,
and then the flow comes back together; the question is not asked a second time within the
structure. In a loop, if the answer to the question results in the loop being entered and the loop
statements executing, then the logic returns to the question that started the loop. When the
body of a loop executes, the question that controls the loop is always asked again.
8. Why is it best to use only three programming structures?
Answer: • Clarity—The number-doubling program is a small program. As programs get
bigger, they get more confusing if they’re not structured.
• Professionalism—All other programmers (and programming teachers you might encounter)
expect your programs to be structured. It’s the way things are done professionally.
• Efficiency—Most newer computer languages are structured languages with syntax that lets
you deal efficiently with sequence, selection, and looping. Older languages, such as assembly
languages, COBOL, and RPG, were developed before the principles of structured
programming were discovered. However, even programs that use those older languages can
be written in a structured form, and structured programming is expected on the job today.
Newer languages such as C#, C++, and Java enforce structure by their syntax.
• Maintenance—You, as well as other programmers, will find it easier to modify and
maintain structured programs as changes are required in the future.
• Modularity—Structured programs can be easily broken down into routines or modules that
can be assigned to any number of programmers. The routines are then pieced back together
like modular furniture at each routine’s single entry or exit point. Additionally, often a
module can be used in multiple programs, saving development time in the new project.
9. Describe how you can straighten out an unstructured flowchart segment.
Answer: One way to straighten out an unstructured flowchart segment is to use the “spaghetti
bowl” method; that is, picture the flowchart as a bowl of spaghetti that you must untangle.
Imagine you can grab one piece of pasta at the top of the bowl and start pulling. As you
“pull” each symbol out of the tangled mess, you can untangle the separate paths until the
entire segment is structured.
10. What are the three basic structures and how can they be used?
Answer: No matter how complicated it is, any set of steps can always be reduced to
combinations of the three basic structures of sequence, selection, and loop. These structures
can be nested and stacked in an infinite number of ways to describe the logic of any process
and to create the logic for every computer program written in the past, present, or future.
Test Bank for Programming Logic and Design
Joyce Farrell
9781111969752, 9788131525906, 9781111825959