Está en la página 1de 9

Chapter 3: Understanding Structure

TRUE/FALSE
1. Structured programs use spaghetti code logic.
ANS: F

PTS: 1

REF: 84

2. In a selection structure, you perform an action or task, and then you perform the next action in order.
ANS: F

PTS: 1

REF: 86

3. Repetition and sequence are alternate names for a loop structure.


ANS: F

PTS: 1

REF: 88

4. In a structured program, any structure can be nested within another structure.


ANS: T

PTS: 1

REF: 94

5. A structured program must contain a sequence, selection, and loop structure.


ANS: F

PTS: 1

REF: 94

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.
ANS: T

PTS: 1

REF: 96

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.
ANS: T

PTS: 1

REF: 100

8. Structured programming is sometimes called goto-less programming.


ANS: T

PTS: 1

REF: 101

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.
ANS: F

PTS: 1

REF: 110

10. The case structure is a variation of the sequence structure and the do loop is a variation of the while
loop.
ANS: F

PTS: 1

REF: 110

MULTIPLE CHOICE
1. Programs that use _____ code logic are unstructured programs that do not follow the rules of
structured logic.

a. case
b. loop
ANS: C

c. spaghetti
d. nested
PTS: 1

REF: 84

2. With a(n) ____, you perform an action or task, and then you perform the next action, in order.
a. ordered structure
c. sequence structure
b. sequence problem
d. loop sequence
ANS: C

PTS: 1

REF: 86

3. The following pseudocode is an example of a ____ structure.


get firstNumber
get secondNumber
add firstNumber and secondNumber
print result
a. sequence
c. loop
b. decision
d. nested
ANS: A

PTS: 1

REF: 87

4. The following pseudocode is an example of a ____ structure.


if firstNumber is bigger than secondNumber then
print firstNumber
else
print secondNumber
a. sequence
c. loop
b. decision
d. nested
ANS: B

PTS: 1

REF: 87

5. Fill in the blank in the following pseudocode:


if someCondition is true then
do oneProcess
____
do theOtherProcess
a. then
c. do
b. while
d. else
ANS: D

PTS: 1

REF: 87

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
c. repetition
b. single-alternative selections
d. dual-alternative selections
ANS: D

PTS: 1

REF: 88

7. The following pseudocode is an example of a ____ structure.


get number
while number is positive
add to sum
get number
a. sequence
c. loop
b. decision
d. nested

ANS: C

PTS: 1

REF: 88

8. You may hear programmers refer to looping as ____.


a. execution
c. iteration
b. selection
d. case
ANS: C

PTS: 1

REF: 88

9. The action or actions that occur within a loop are known as a(n) ____.
a. loop body
c. loop internals
b. action body
d. structure body
ANS: A

PTS: 1

REF: 88

10. The following pseudocode is an example of ____.


do stepA
do stepB
if conditionC is true then
do stepD
else
do stepE
endif
while conditionF is true
do stepG
endwhile
a. nesting
c. single alternative structures
b. stacking
d. a posttest
ANS: B

PTS: 1

REF: 89

11. Attaching structures end to end is called ____ structures.


a. linking
c. nesting
b. stacking
d. building
ANS: B

PTS: 1

REF: 89

12. The following pseudocode is an example of ____.


if conditionA is true then
do stepE
else
do stepB
do stepC
do stepD
endif
a. nesting
c. a posttest
b. stacking
d. a pretest
ANS: A

PTS: 1

REF: 90

13. Placing a structure within another structure is called ____ structures.


a. nesting
c. shelling
b. stacking
d. selecting
ANS: A

PTS: 1

REF: 90

14. You can use an ____ statement to clearly show where the actions that depend on a decision end.

a. end
b. endstructure
ANS: D

c. endloop
d. endif
PTS: 1

REF: 90

15. The maximum number of entry points that any programming structure can have is ____.
a. zero
c. three
b. one
d. five
ANS: B

PTS: 1

REF: 93

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
ANS: C

PTS: 1

REF: 94

17. Structures can be stacked or connected to one another at their ____.


a. entry points only
c. entry or exit points
b. exit points only
d. entry or combination points
ANS: C

PTS: 1

REF: 94

18. A ____ read is an added statement that gets the first input value in a program.
a. nested
c. posttest
b. stacked
d. priming
ANS: D

PTS: 1

REF: 98-99

19. The priming read is an example of a(n) ____ task.


a. declaration
c. housekeeping
b. exit
d. selection
ANS: C

PTS: 1

REF: 100

20. In older languages, you could leave a selection or loop before it was complete by using a ____
statement.
a. loop
c. next
b. go next
d. go to
ANS: D

PTS: 1

REF: 101

21. Structured programs can be easily broken down into routines or ____ that can be assigned to any
number of programmers.
a. segments
c. units
b. modules
d. sequences
ANS: B

PTS: 1

REF: 101

22. One way to straighten out an unstructured flowchart segment is to use the ____ method.
a. spaghetti code
c. restructuring
b. spaghetti bowl
d. priming
ANS: B

PTS: 1

REF: 102

23. A loop must return to the ____ question at some later point in a structure.
a. start loop
c. master loop
b. loop-controlling
d. continue loop
ANS: B

PTS: 1

24. The do loop is a variation of the ____ loop.


a. if-then-else
b. while
ANS: B

PTS: 1

REF: 104
c. case
d. sequence
REF: 110

25. The case structure is a variation of the ____ structure.


a. selection
c. sequence
while
b.
d. do
ANS: A

PTS: 1

REF: 110

COMPLETION
1. A(n) ____________________ can contain any number of tasks, but there is no option to branch off
and skip any of the tasks.
ANS: sequence
PTS: 1

REF: 86-87

2. Some people call the selection structure a(n) ____________________ statement.


ANS:
if-then-else
if then else
PTS: 1

REF: 87

3. A group of statements that execute as a single unit are called a(n) ____________________.
ANS: block
PTS: 1

REF: 90

4. When you ____________________ structures, the statements that start and end a structure are always
on the same level and always in pairs.
ANS: nest
PTS: 1

REF: 91

5. Structured programming is sometimes called ____________________-less programming.


ANS:
goto
go to
go-to

PTS: 1

REF: 101

MATCHING
Match each term with a statement below.
a. structure
b. priming read
c. module
d. decision structure
e. null case

f.
g.
h.
i.
j.

stacking structures
spaghetti code
loop structure
case structure
nesting structures

1.
2.
3.
4.
5.
6.
7.
8.
9.
10.

Logically snarled program statements


A basic unit of programming logic
With this, you ask a question, and, depending on the answer, you take one of two courses of action
Continue to repeat actions while a condition remains true
An added statement that gets the first input value in a program
Placing a structure within another structure
A case in which nothing is done
Attaching structures end-to-end
Often can be used in multiple programs
A variation of the selection structure

1.
2.
3.
4.
5.
6.
7.
8.
9.
10.

ANS:
ANS:
ANS:
ANS:
ANS:
ANS:
ANS:
ANS:
ANS:
ANS:

G
A
D
H
B
J
E
F
C
I

PTS:
PTS:
PTS:
PTS:
PTS:
PTS:
PTS:
PTS:
PTS:
PTS:

1
1
1
1
1
1
1
1
1
1

REF:
REF:
REF:
REF:
REF:
REF:
REF:
REF:
REF:
REF:

84
86
87
88
98
90
88
89
101
110

SHORT ANSWER
1. Why does spaghetti code have a shorter shelf life than structured code?
ANS:
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.
PTS: 1

REF: 86

TOP: Critical Thinking

2. Define the term structure as it relates to programming.


ANS:

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.
PTS: 1

REF: 86

TOP: Critical Thinking

3. Describe a loop structure.


ANS:
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.
PTS: 1

REF: 88

TOP: Critical Thinking

4. Rewrite the following as a while loop:


do
pay bills
while more bills remain to be paid
ANS:
pay bills
while there are more bills to pay
pay bills
endwhile
PTS: 1

REF: 88-89

TOP: Critical Thinking

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?
ANS:
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.
PTS: 1

REF: 89-90

TOP: Critical Thinking

6. What are the characteristics of a structured program?


ANS:
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.

PTS: 1

REF: 94

TOP: Critical Thinking

7. Explain the difference between the representation of a decision structure and a loop in a flowchart.
ANS:
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.
PTS: 1

REF: 96

TOP: Critical Thinking

8. Why is it best to use only three programming structures?


ANS:
ClarityThe number-doubling program is a small program. As programs get bigger, they get more
confusing if theyre not structured.
ProfessionalismAll other programmers (and programming teachers you might encounter) expect
your programs to be structured. Its the way things are done professionally.
EfficiencyMost 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.
MaintenanceYou, as well as other programmers, will find it easier to modify and maintain
structured programs as changes are required in the future.
ModularityStructured 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 routines single entry or exit point. Additionally, often a module can be used in
multiple programs, saving development time in the new project.
PTS: 1

REF: 101

TOP: Critical Thinking

9. Describe how you can straighten out an unstructured flowchart segment.


ANS:
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.
PTS: 1

REF: 102

TOP: Critical Thinking

10. What are the three basic structures and how can they be used?
ANS:
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.

PTS: 1

REF: 110

TOP: Critical Thinking