STRUCTURED PROGRAMMING
2. Program development design
2.2. Program design tools
Design tools help programmers visualize the logic of a solution before coding.
A. Algorithms
-
Definition: A step-by-step procedure or set of rules to be followed in calculations or other problem-solving operations.
-
Characteristics:
-
Finite: Must end after a specific number of steps.
-
Definite: Each step must be clear and unambiguous.
-
Effective: Steps must be basic enough to be carried out.
-
B. Flowcharts
-
Definition: A diagrammatic representation of an algorithm using standard symbols connected by arrows to show the flow of control.
-
Common Symbols:
-
Oval (Terminal): Start or Stop.
-
Parallelogram (Input/Output): Reading data or printing results.
-
Rectangle (Process): Calculations or assignments (e.g.,
x = a + b). -
Diamond (Decision): A condition with Yes/No branches (e.g.,
Is x > 10?). -
Arrows: Indicate the direction of flow.
-
C. Pseudocode
-
Definition: A high-level description of an algorithm that uses structural conventions of programming languages but is intended for human reading rather than machine reading.
-
Style: It looks like code (using indentation and keywords like
IF,WHILE,PRINT) but ignores strict syntax rules (like semicolons). -
Example:
PlaintextSTART READ age IF age >= 18 THEN PRINT "Eligible to vote" ELSE PRINT "Not eligible" ENDIF STOP
4. Structured Design Concepts
A. Top-Down Design (Stepwise Refinement)
-
The process of breaking a complex problem into smaller, manageable sub-problems (modules).
-
You start with the main goal and break it down level by level until you reach simple tasks that can be easily coded.
B. Modular Programming
-
Writing code in separate, independent blocks (modules/functions) rather than one massive file.
-
Advantages:
-
Reusability: A module (e.g., a "CalculateTax" function) can be used in different parts of the program.
-
Easier Debugging: You can test one module at a time.
-
Teamwork: Different programmers can work on different modules simultaneously.
-