Programming Logic and Design, 6th Edition
Chapter 3
Exercises
1. In Figure 3-10 the process of buying and planting flowers in the spring was shown using the same structures as the generic example in Figure 3-9. Describe some other process with which you are familiar using exactly the same logic.
Answer: Student answers will vary widely. They should come up with processes that fit the generic logic shown in Figure 3-9. Some examples could include: making a dentist appointment or registering for a class. Pseudocode for each follows.
if it’s time for your annual teeth cleaning call the dentist for an appointment tomorrow while the day and time you want isn’t available if another time the same day is available make the appointment at the new time on the same day else pick a new day and time endif endwhile write appointment on your calendar endif
if you are taking a class this semester then register for a class while the class is full if another section is available enroll for the available section else select a new class endif endwhile print schedule endif
2. Each of the flowchart segments in Figure 3-35 is unstructured. Redraw each flowchart segment so that it does the same thing but is structured.
Answer:
a. [pic]
b. [pic]
c. [pic]
d. [pic]
e. [pic]
3. Write pseudocode for each example (a through e) in Exercise 2 making sure your pseudocode is structured but accomplishes the same tasks as the flowchart segment.
Answer:
a. do A while B is true do C do A endwhile
b. do D if E is true then do H do I else do F if G is true then do I endif endif
c. do k if L is true then do P while Q is true do P endwhile do R else