Download as pdf or txt
Download as pdf or txt
You are on page 1of 11

Data Structures and Algorithms

Pointers for
Structuring a
Program

1. Use Modules
2. Use the four logic structures
a. Sequential Structure
b. Decision Structure
c. Loop Structure
d. Case Structure

3. Eliminate the rewriting of identical processes by


using modules
4. Use techniques to improve readability, including
the four logic structures, proper naming of
variables, internal documentation, and proper
indentation

Introduction to Programming Structure *Property of STI


Page 1 of 11
Data Structures and Algorithms

Cohesion and
Coupling

Cohesion
@ relates to the functional independence of the
module and to the performance of a single “task”
within the module

Coupling
@ allows modules to be connected by an interface,
which enables the programmer to transfer data
from one module to another.

Introduction to Programming Structure *Property of STI


Page 2 of 11
Data Structures and Algorithms

Modules

Rules in Designing Modules


1. Each module is an entity itself.
2. Each module has a single function.
3. Each module is short enough to be easily read and
modified.
4. The length of a module is governed by its function
and the number of instructions to be executed to
perform that function.
5. A module is developed to control the order of
processing.

Introduction to Programming Structure *Property of STI


Page 3 of 11
Data Structures and Algorithms

Modules

Types of Modules
1. Control Module
2. Initialization Module
3. Process Data Module
a. Calculation Modules
b. Print Modules
c. Read and Data Validation Modules
4. Wrap-up module
5. Event Modules (OO-Paradigm)

Introduction to Programming Structure *Property of STI


Page 4 of 11
Data Structures and Algorithms

Local and Global


Variables
Local Variables
@ may be used only by the module itself

Global Variables
@ they are global to the program as they can be seen by
all modules

Introduction to Programming Structure *Property of STI


Page 5 of 11
Data Structures and Algorithms

Parameters

Parameters
@ local variables that are passed or sent from one
module to another. Parameters are another way
of facilitating coupling that allows the
communication of data between modules

Calling Module
@ the module that processes another module

Called Module
@ the module being processed

Introduction to Programming Structure *Property of STI


Page 6 of 11
Data Structures and Algorithms

Parameters

Actual parameter listing


@ the list of parameters that follows the module
name being processed in the calling module

Formal Parameter Listing


@ the list of parameters that follow the module
name at the beginning of the module

Introduction to Programming Structure *Property of STI


Page 7 of 11
Data Structures and Algorithms

Parameters

Types of parameter passing


a Call by value
a Call by reference

Introduction to Programming Structure *Property of STI


Page 8 of 11
Data Structures and Algorithms

Parameters

Introduction to Programming Structure *Property of STI


Page 9 of 11
Data Structures and Algorithms

Parameters

Introduction to Programming Structure *Property of STI


Page 10 of 11
Data Structures and Algorithms

Variable Names
and Data
Dictionary

The Four Logic Structures


• Sequential
• Decision
• Loop
• Case

Introduction to Programming Structure *Property of STI


Page 11 of 11

You might also like