< previous page page_165 next page >

Page 165
(text box continued from previous page)
meaningful identifiers and comments. You can use the pseudocode from your top-down designs as comments in your programs.
This kind of documentation may be sufficient for someone reading or maintaining your programs. However, if a program is going to be used by people who are not programmers, you must provide a user's manual as well.
Be sure to keep documentation up-to-date. Indicate any changes you make in a program in all of the pertinent documentation. Use self-documenting code to make your programs more readable.
Self-Documenting Code Program code containing meaningful identifiers as well as judiciously used clarifying comments.

Now let's look at two case studies that demonstrate top-down design.
Problem-Solving Case Study Pythagorean Theorem Applied to Right Triangles
0165-01.gif
Problem: Determine the length of the hypotenuse of a right triangle given the lengths of the other two sides.
Input: Two floating point numbers, one for each known side of the triangle.
Output: Print the input data with a message that identifies each number (echo printing). Print the length of the hypotenuse with an identifying message. All numbers are to be printed to four decimal places.
Discussion: The Pythagorean Theorem states that the square of the hypotenuse of a right triangle is equal to the sum of the squares of the other two sides. To compute the length of the hypotenuse, then, you square the lengths of the other two sides, add the squares, and then find the square root of the sum. We use the same method in our programming solution.

 
< previous page page_165 next page >