Understanding Structure: Instructor's Manual Table of Contents
Understanding Structure: Instructor's Manual Table of Contents
Chapter 3
Understanding Structure
A Guide to this Instructor’s Manual:
We have designed this Instructor’s Manual to supplement and enhance your teaching
experience through classroom activities and a cohesive chapter summary.
This document is organized chronologically, using the same headings that you see in the
textbook. Under the headings you will find: lecture notes that summarize the section, Teacher
Tips, Classroom Activities, and Lab Activities. Pay special attention to teaching tips and
activities geared towards quizzing your students and enhancing their critical thinking skills.
In addition to this Instructor’s Manual, our Instructor’s Resources also contain PowerPoint
Presentations, Test Banks, and other supplements to aid in your teaching experience.
At a Glance
Overview
Chapter Objectives
Teaching Tips
Quick Quizzes
Additional Projects
Additional Resources
Key Terms
© 2017 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a
license distributed with a certain product or service or otherwise on a password-protected website for classroom use.
Programming Logic and Design, Ninth Edition 3-2
Lecture Notes
Overview
Chapter Objectives
Teaching Tips
The Disadvantages of Unstructured Spaghetti Code
1. Introduce the concept of spaghetti code. Point out that most programs written in the
early days of programming exhibited this style to some extent because there were no
guidelines on program design.
An excellent way to show the pitfalls of spaghetti code is to show how an old
Teaching Basic (not Visual Basic) program worked, complete with line numbers and
Tip GOTO statements. Then illustrate go the GOTO statements execute the wrong
code.
2. Define the terms unstructured programs and structured programs, and note that
structured programs follow certain rules that will be covered in this chapter.
3. Introduce the dog-washing procedure documented in Figure 3-1, but be sure to point out
that flowchart lines should never cross.
© 2017 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a
license distributed with a certain product or service or otherwise on a password-protected website for classroom use.
Programming Logic and Design, Ninth Edition 3-3
Teaching Students who are new to programming need as much exposure to flowcharting as
Tip possible to help them learn the algorithmic approach to program design.
It’s a good idea to illustrate that less is actually more. Programmers are judged
not by how many lines of code they write, but by how efficiently the program
runs and how easy it is to read. A good way to illustrate this is to take a program
Teaching
that contains a loop with five iterations. Replace the loop with the code written
Tip
five times. Students will see that less is more! Then take that same program (or
another), remove all the line breaks, and substitute single spaces. They will see
the need for structure and the need to be neat in writing their code!
1. Introduce the concept of a structure and observe that any program can be constructed
from these three types of structures: sequence, selection, and loop.
2. Introduce the sequence structure, stressing that there is no way out of the structure,
using Figure 3-2 for illustration.
3. Introduce the selection structure, or decision structure, and describe its common
implementation as the if-then-else statement. Use Figures 3-3 and 3-4 for
illustration. Note that Visual Basic requires the use of the End If statement.
Emphasize to your class that the selection structure must ask a question that can
Teaching be answered only with a Yes or No. Explain that True or False is essentially the
Tip same as Yes or No. This is known as a Boolean expression whose value can be
only one of two opposing values, usually expressed as True or False or Yes or
No.
5. Introduce the loop structure, using Figure 3-5 for illustration. Point out that the loop
structure contains the loop body and is the structure that provides the ability to perform
repetitive processing on a very large scale. Explain that looping is often referred to as
repetition or iteration.
6. Describe the use of the while…do structure, otherwise known as the while loop or a
while … do loop.
© 2017 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a
license distributed with a certain product or service or otherwise on a password-protected website for classroom use.
Programming Logic and Design, Ninth Edition 3-4
7. Point out that all programs can be written by simply combining sequences, selections,
and loops in an infinite number of ways.
8. Describe stacking structures by using the single entry and exit points on each
structure, referencing Figure 3-6 for illustration.
9. Point out the need for the end-structure statement, and discuss how these statements
help to delineate a block of code that comprises a structure.
Teaching Emphasize that structures may only be stacked end to end. Students commonly
Tip make the mistake of interweaving structures instead of stacking them.
10. Describe nesting structures, using Figures 3-7 through 3-9 for illustration.
Teaching Point out that nested structures must be totally contained within the outer
Tip structure.
Teaching Some languages have block delineation symbols. For example, Java and C++ use
Tip curly braces to identify blocks.
End this section by emphasizing again the infinite number of ways that structures
Teaching
may be combined, stacked, and nested. Give students a few minutes to write a
Tip
complex structure and ask for volunteers to share an example on the board.
Quick Quiz 1
2. When structures are attached to each other end to end, this is called ____.
Answer: stacking
3. When one structure is contained completely within another structure, this is called ____.
Answer: nesting
© 2017 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a
license distributed with a certain product or service or otherwise on a password-protected website for classroom use.
Programming Logic and Design, Ninth Edition 3-5
1. Walk through the example using Figures 3-11 through 3-17 so that students can
understand why it is necessary to read the first value before entering a loop.
2. Describe the use of a priming input or priming read, and explain when and why it is
used.
Note that most of the flowcharts in this section are examples of what not to do.
Teaching Take time to carefully explain why these flowcharts represent the incorrect way
Tip to design the number-doubling program, as it may not be obvious to students
who are new to programming.
Teaching Take time to review how pseudocode is represented with flowcharts and vice
Tip versa so that students are equally comfortable with both representations.
© 2017 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a
license distributed with a certain product or service or otherwise on a password-protected website for classroom use.
Programming Logic and Design, Ninth Edition 3-6
Note that the cost of software maintenance far exceeds the cost of the original
Teaching
development. The life span of most major software applications is five years or
Tip
more.
Recognizing Structure
1. Review the flowchart examples in Figures 3-18 through 3-20 and explain why the first
two are structured, but the third is not.
2. Walk through the steps to untangle the code represented by the flowchart in Figure 3-
21, using the flowcharts in Figures 3-22 through 3-23.
1. Remind students of the dog-washing process shown in Figure 3-1. Using the flowcharts
in Figures 3-22 and 3-23, explain how to restructure the logic.
2. Review the modularized version of the dog-washing process shown in Figure 3-23.
Quick Quiz 2
1. A(n) ____ is an added statement that gets the first input value in a program.
Answer: priming input or priming read
2. List the reasons for using the three structures discussed in the chapter.
Answer: clarity, professionalism, efficiency, maintenance, modularity
3. (True/False) When you are beginning to learn about structured program design, it is
easy to detect whether a flowchart of a program’s logic is structured.
Answer: False
4. (True/False) 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.
Answer: True
1. Discuss the importance of planning out a program on paper before writing the actual
code. What are some advantages of doing this? Answers might include the use of
© 2017 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a
license distributed with a certain product or service or otherwise on a password-protected website for classroom use.
Programming Logic and Design, Ninth Edition 3-7
flowcharts to help guarantee structure and the ability to identify redundant areas of
processing.
2. Discuss why it is important to write code with future maintainability in mind. What
kinds of maintenance might be done on an existing program? Answers might include
fixing bugs, adding new features, improving efficiency, improving the user interface,
and making the program interface with another program.
3. Develop a checklist of rules you can use to help you determine whether a flowchart or
pseudocode segment is structured.
Every structure must have only one entry point and one exit point.
In a flowchart you should be able to remove structured pieces, replacing them with a
place holder, and see that the resulting shell is structured. In a flowchart, no lines
should ever cross.
In pseudocode, every if statement should pair with an endif and every while
statement should pair with an endwhile with no intervening endif or
endwhile statements.
Additional Projects
1. It is late at night, and you decide to get a glass of milk before bed. Try to write
pseudocode describing the process of going to the kitchen and getting the milk. Be very
specific and make sure you have all actions in the correct sequence. For example,
remember you must open the refrigerator door before you reach in to retrieve the milk
container. What if there is no glass in the cupboard? Did you check whether the glass
was right side up before you started pouring? Now consider how many small decisions
you make every day, and consider how involved it would be to write a program to
instruct a robot to do the things you do in a day!
Write pseudocode with a flowchart that contains directions for how to tie your shoes.
Have another student follow the flowchart and pseudocode to tie his or her shoes. How
complete were the directions? Was the student able to tie his or her shoes correctly
based on your flowchart and pseudocode?
2. Find more information about one of the following people and explain why he or she is
important to structured programming: Edsger Dijkstra, Corrado Bohm, Giuseppe
Jacopini, and Grace Hopper.
Edsger Wybe Dijkstra was a Dutch computer scientist who lived from 1930 to 2002.
Among his contributions to computer science are the shortest path-algorithm, also
© 2017 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a
license distributed with a certain product or service or otherwise on a password-protected website for classroom use.
Programming Logic and Design, Ninth Edition 3-8
known as Dijkstra's algorithm. He received the Turing Award in 1972. He was also
known for his low opinion of the GOTO statement in computer programming,
culminating in the 1968 article Go To Statement Considered Harmful . This article was
regarded as a major step towards the widespread deprecation of the GOTO statement
and its effective replacement by control structures such as the while loop.
Bohm and Jacopini were theorists who showed in 1966 that all logical problems could
be handled using only the three control structures sequence, selection, and loop.
Rear Admiral Grace Hooper lived from 1906 to 1992. She was a U.S. Navy officer and
computer scientist. She was one of the first programmers of the Harvard Mark I
calculator and she developed the first compiler. She often has been quoted as claiming
to develop the term "bug" when a moth was found in the Mark I circuitry
2. Computer programs can contain structures within structures and stacked structures,
creating very large programs. Computers also can perform millions of arithmetic
calculations in an hour. How can we possibly know the results are correct?
Only by repeatedly testing portions of programs can you have confidence that their
results are correct. According to author Harlan Mills, "There is no foolproof way to ever
know that you have found the last error in a program. So the best way to acquire
confidence that a program has no errors is never to find the first one, no matter how
much it is tested and used".
Some people believe that software never breaks, unlike mechanical parts such as bolts,
or electronic parts such as transistors. However, there have been many incidents that
prove this theory incorrect:
Therac-25 was a radiation therapy machine. Between 1985 and 1987 at least six
patients were given massive overdoses of radiation. These accidents highlighted
the dangers of software control of safety-critical systems.
The British destroyer Sheffield was sunk because the radar system identified an
incoming missile as "friendly".
On February 25, 1991, during the Gulf War, 28 lives were lost when an error
that missed 0.000000095 second in precision in every 10th of a second made the
Patriot missile fail to intercept a scud missile.
In 1991, after changing three lines of code in a signaling program which
contains millions lines of code, the local telephone systems in California and
along the Eastern seaboard came to a stop.
In 2011, computer errors prompted California prison officials to mistakenly
release an estimated 450 inmates with "a high risk for violence" as unsupervised
parolees in a program meant to ease overcrowding.
© 2017 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a
license distributed with a certain product or service or otherwise on a password-protected website for classroom use.
Programming Logic and Design, Ninth Edition 3-9
Additional Resources
4. Article on flowcharting:
http://en.wikipedia.org/wiki/Flowchart
5. Article on pseudocode:
http://www.wikihow.com/Write-Pseudocode
Key Terms
© 2017 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a
license distributed with a certain product or service or otherwise on a password-protected website for classroom use.