Previous | Next | Table of Contents | Index | Program List | Copyright

Chapter Review

In the first part of this chapter we discussed more aspects of problem solving. We reviewed the top-down approach to solving problems and showed how to use the documentation created by following the software development method as the outline of the final program. We also showed how we could extend a solution to one problem to form the basis of the solution for another problem. We discussed how structure charts are used to show relationships between different levels of subproblems or between algorithm steps and their refinements.

We discussed the importance of control structures to structured programming and introduced the three kinds of control structures: sequence, selection, and repetition.

Several guidelines for using program comments were discussed. Well-placed and carefully worded comments and a structure chart are two essential parts of the documentation necessary for a program. In the remainder of the chapter, we discussed the representation of the various steps in an algorithm and illustrated the stepwise refinement of algorithms.

In this chapter enumeration types were introduced, along with Ada's standard input/output library for reading and displaying enumeration values. Enumeration types are useful in allowing the programmer to give meaningful names to values such as days of the week, months of the year, colors of the rainbow, and command sets.

This chapter also continued the use of packages, begun in Chapter 2 with the use of the input/output libraries. We discussed Ada's standard package Calendar and a package called Screen that is provided with this book. Finally, we introduced the spider package, also provided with this book, which we will use throughout the book to illustrate a number of concepts.

New Ada Constructs in Chapter 3

Enumeration type definition:
TYPE CompassPoints IS (North, South, East, West);
defines a type whose values are enumerated as a list of identifiers

Quick-Check Exercises

  1. Does a compiler translate comments?
  2. Each statement in a program should have a comment. (True or false?)
  3. What is a structure chart?
  4. Explain how a structure chart differs from an algorithm.

Answers to Quick-Check Exercises

  1. No
  2. False
  3. A structure chart is a diagram used to show an algorithm's subproblems and their interdependence.
  4. A structure chart shows the relationship between subproblems; an algorithm lists the sequence in which subproblems are performed.

Review Questions for Chapter 3

  1. Discuss the strategy of top-down design.
  2. Provide guidelines for the use of comments.
  3. Briefly describe the steps you would take to derive an algorithm for a given problem.
  4. The diagram that shows the algorithm steps and their interdependencies is called a _____________.

Programming Projects

  1. Write a program that clears the screen, then beeps and flashes the word HELP in the center of the screen three times at 1-second intervals. (Hint: To "flash" a word, display a word, then display the same number of spaces in the same spot on the screen.)
  2. Write a program that displays today's date in the center of the screen.
  3. Find out the names of the days of the week in some other language and write a program that translates from those names to the English ones. Revise your program to do the translation in the other direction.


Previous | Next | Table of Contents | Index | Program List | Copyright

Copyright © 1996 by Addison-Wesley Publishing Company, Inc.