Send Close Add comments: (status displays here)
Got it!  This site uses cookies. You consent to this by clicking on "Got it!" or by continuing to use this website.nbsp; Note: This appears on each machine/browser from which this site is accessed.
Top-down  development of a program


1. Top-down  development of a program
Let us develop a program in a top-down manner.

That is, in a goal-directed backward chaining, top-down manner.

We will use abstraction and some knowledge of the programming language being used. In this case, C.

2. String variables for literals.
To get started, note that the following program shows how to declare a string variable that will be assigned a string literal. That is, it will not work with string input nor dynamic strings.

Here is the C code.

Here is the output of the C code.


3. Output
Let use assume we know nothing about the problem being solved.

Here are three inputs and outputs for a given program.

The customer-facing output is the place to start. This is the goal so we start with the outputs. In the following, the differences in the output are underlined.

4. Input and output #1
Input #1:
3 4 5 blue

Output #1:
Enter three sides of a triangle as positive integers and the color of the triangle. You entered sides of length 3, 4 and 5 with color blue. The blue triangle with sides 3, 4 and 5 is a right triangle.


5. Input and output #2
Input #2:
11 14 5 green

Output #2:
Enter three sides of a triangle as positive integers and the color of the triangle. You entered sides of length 11, 14 and 5 with color green. The green triangle with sides 11, 14 and 5 is not a right triangle.


6. Input and output #3
Input #3:
12 13 5 red

Output #3:
Enter three sides of a triangle as positive integers and the color of the triangle. You entered sides of length 12, 13 and 5 with color red. The red triangle with sides 12, 13 and 5 is a right triangle.


7. Start
To get started, Let use combine all three outputs into one program - not very useful as the program has exactly the same output every time it is run.

An extra print statement is between each group for visual separation in the output. Here is the C code.

Here is the output of the C code.

Here is the C code.

Here is the output of the C code.


8. Observations
Note the following observations.

9. End of page