Designing a Structured Program
On top of designing what data is needed how it is to be stored, you also need to design what the program will actually do with the data that is to be input in order to produce the wanted output. This is called an algorithm.
Only 3 different program constructs are needed to write a structured algorithm:
- Sequence - One statement follows another and the program executes in the sequence it is written
- Selection (if...then...else) - Next statement to be executed is dependent upon the value of an expression
- Iteration - A section of a program is repeated many times, as in a do...while loop
Programs that are written using top-down techniques, and using only the three constructs described are known as structured programs.
To design these types of programs effectively we have two main tools:
Program Flowcharts- These use diagrams to show the operation of the algorithm. - Small number of symbols to represent individual steps - Flow lines show order in which steps are carried out.
- Program flowcharts
- Psuedo-code
Program Flowcharts- These use diagrams to show the operation of the algorithm. - Small number of symbols to represent individual steps - Flow lines show order in which steps are carried out.
There are no definite rules about writing pseudo-code, but here are some guidelines:
- Describe each step of the algorithm as briefly as possible
- Use uppercase letters with keywords and other parts of the pseudo-code which are closer to a programming language
- Use lowercase letters with parts of the pseudo-code that are closer to English
- Indent code to show start and end blocks
No comments:
Post a Comment