Chapter9 - Chapter 9 DESIGN OF PROGRAMS STEP-BY-STEP...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Chapter 9 DESIGN OF PROGRAMS STEP-BY-STEP REFINEMENT Most of the examples of programming so far have been short examples. Nevertheless we have emphasized some of the aspects of good programming. These were: 1. choosing meaningful words as identifiers, 2. placing comments in the program to increase the understandability, 3. paragraphing loops and if. ..then. ..else statements to reveal the structure of control flow, 4. choosing appropriate data structures, 5. reading programs and tracing execution by hand, to strive for correctness before machine testing. All of these are important even in small programs, but it is only when we attempt larger programs that our good habits will really start to payoff. And when we work on larger programs we will find that we have something else to structure, and that is our attack on the problem. To solve a problem we must move from a statement of what the problem to be solved is, to a solution, which is a well-structured program for a computer. The language of our program will be Fortran 77. The original statement of a problem will be in English, with perhaps some mathematical statements. The solution will be in Fortran. What we will look at first in this chapter is the way we move from one of these to the other. We will be discussing a method whereby we go step by step from one to the other. This systematic method we will refer to as step-
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 | DESIGN OF PROGRAMS by-step refinement . Sometimes we say that we are starting at the top, the English-language statement of the problem, and moving down in steps to the bottom level, which is the Fortran program for the solution. We speak of the top-down approach to program development. TREE STRUCTURE TO PROGRAM DEVELOPMENT To illustrate the technique of structuring the design of programs by the step-by-step refinement, or the top-down approach, we need a problem as an example. We need a problem that is large or difficult enough to show the technique, but not so large as to be too long to follow. If a program is too long and involved we will use another technique that divides the job into modules and does one module at a time. This is called modular programming . It is another form of structured programming. But it must wait until we have learned about subprograms. The example we choose is sorting a list of names alphabetically. We will now start the solution by drawing a diagram in the form called a tree which represents the structure of our attack. The root of the tree is the statement of the problem. In the first move we show how this is divided into three branches: At each of the three nodes that descend from the root we have an English statement. These statements are still “what-to-do” statements, not “how- to-do-it.” We will be moving down each branch of the solution tree replacing a statement of “what to do” by an algorithm for doing it. The algorithms will not necessarily be in the Fortran language. We will use a mixture of English and Fortran at each node until, in the nodes farthest from the tree
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 27

Chapter9 - Chapter 9 DESIGN OF PROGRAMS STEP-BY-STEP...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online