Uploaded by Uzumaki Boruto

docdownloader.com-pdf-chapter-4-an-introduction-to-programming-structure-dd 37212204e9aadd487bc9a42024a43fe5

advertisement
Data Structures and Algorithms
P o in t e r s f o r
S t r u c t u r in g a
Prog ra m
1. Use Modules
2. Use the four logic structures
a.
b.
c.
d.
Sequ
Sequen
enti
tial
al Stru
Struct
ctur
ure
e
Deci
Decisi
sion
on Str
Struc
uctu
ture
re
Loop
Loop Stru
Struct
ctur
ure
e
Case
Case Stru
Struct
ctur
ure
e
3. Elimina
Eliminate
te the re
rewri
writing
ting of
of identica
identicall processe
processess by
using modules
4. Use
tfour
echniques
ques to
improv
improve
e readabi
reproper
adability,
lity,
including
including
the techni
logic
structures,
naming
of
variables, internal documentation, and proper
indentation
Introduction to Programming Structure
*Property of
of ST I
Page 1 of 11
Data Structures and Algorithms
Co h e s io
io n a n d
Co u p l i n g
Cohe
ohesion
@
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
of ST I
Page 2 of 11
Data Structures and Algorithms
M o d u le s
Rule
ules iin
n Desig
signingModul
dulees
1. Each
Each modu
module
le is
is an entity
entity itself.
itself.
2. Each
Each modul
module
e has
has a singl
single
e funct
function
ion..
3. Each module
module is short
short enough
enough to be easily
easily read
read and
and
modified.
4. The leng
length
th of a modu
module
le is govern
governed
ed by its
its functi
function
on
and the number of instructions to be executed to
perform that function.
5. A
module
module is develop
developed
ed to control
control the
the order
order of
of
processing.
Introduction to Programming Structure
*Property of
of ST I
Page 3 of 11
Data Structures and Algorithms
M o d u le s
Types of Mod
odu
ules
1. Cont
Contro
roll M
Mo
odule
dule
2. Init
Initia
iali
liza
zati
tion
on Modu
Module
le
3. Proc
Proces
esss Data
Data Mo
Modu
dule
le
a. Calculation Modules
b. Print Modules
c. Read
Read and
and Data
ata Vali
Valida
dati
tion
on Modu
Module
less
4. Wrap
Wrap-u
-up
p mod
modul
ule
e
5. Event
Event Mod
Module
uless (OO(OO-Pa
Parad
radigm
igm))
Introduction to Programming Structure
*Property of
of ST I
Page 4 of 11
Data Structures and Algorithms
Lo c a l a n d G l o b a l
Va r ia b le s
Local
cal 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
of ST I
Page 5 of 11
Data Structures and Algorithms
Pa ra m e t e rs
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
Cal
alllingModul
dule
@
the module that processes another module
Called Modu
dulle
@
the module being processed
Introduction to Programming Structure
*Property of
of ST I
Page 6 of 11
Data Structures and Algorithms
Pa ra m e t e rs
Actual par
aram
ameeter list
stiing
@
the list of parameters that follows the module
name being processed in the calling module
Formal Param
arameeter List
stiing
@
the list of parameters that follow the module
name at the beginning of the module
Introduction to Programming Structure
*Property of
of ST I
Page 7 of 11
Data Structures and Algorithms
Pa ra m e t e rs
Types of pa
parameter passing
Call by value
a Call by reference
a
Introduction to Programming Structure
*Property of
of ST I
Page 8 of 11
Data Structures and Algorithms
Pa ra m e t e rs
Introduction to Programming Structure
*Property of
of ST I
Page 9 of 11
Data Structures and Algorithms
Pa ra m e t e rs
Introduction to Programming Structure
*Property of
of ST I
Page 10 of 11
Data Structures and Algorithms
Va r ia b le N a m e s
a n dt io
D an taar y
Dic
The Fou
Four Logic Structu
ctures
•
•
•
•
Sequential
Decision
Loop
Case
Introduction to Programming Structure
*Property of
of ST I
Page 11 of 11
Download