0% found this document useful (0 votes)
4 views

Structured Programming

Structures 2

Uploaded by

hawkinsgray4
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Structured Programming

Structures 2

Uploaded by

hawkinsgray4
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

St

ruct
ured pr
ogr
ammi
ng al
so known as st
ruct
uresi
ntosepar
atesubsect
ions v
isual l
anguage mani
pul
ates v
isual
Modul
ar pr
ogr
ammi
ng i
s an appr
oach t
o i
nfor
mat
ion orsuppor
tvi
suali
nter
act
ion,or
Examples of st
ruct
ured pr
ogr
ammi
ng
wr
it
ing a pr
ogr
am t
hatar
e easi
ert
otest
, languagesar
e al
l
owspr
ogr
ammi
ngwi
thv
isual
expr
essi
on
debug,modi
fy,andmai
ntai
nbyenf
orci
nga
5.I
nter
netBasedPr
ogr
ammi
ng
modul
ar appr
oach whi
ch br
eaks a l
arge • C
compl
expr
obl
em i
ntosub–r
out
ines. • Pascal Thi
s i
s pr
ogr
ammi
ng or
ient
ed t
o t
he
dev
elopment of i
nter
net appl
i
cat
ions
Pr
ogr
ammi
ngpar
adi
gm i
saf
undament
alst
yle • For
tran
l
anguagesandt
ool
ssuchasPHP,ASP,Per
l,
ofcomput
erpr
ogr
ammi
ng,awayofbui
l
ding • Cobol
Jav
aScr
ipt
,HTML,
Jav
aet
c.
t
he st
ruct
ure and el
ement
s of comput
er
• ALGOL
pr
ogr
ams.Ther
ear
efourmai
npar
adi
gms CHARACTERI
STI
CSOFAGOODPROGRAM
• Ada
1.Unst
ruct
uredPr
ogr
ammi
ng 3.Obj
ectOr
ient
edPr
ogr
ammi
ng(
OOP) • Por
tabi
li
ty/
Transf
erabi
li
ty:
Mustbeabl
et owor konany
I
nunst
ruct
uredpr
ogr
ams,t
hest
atement
sar
e Thi
s i
s a pr
ogr
ammi
ng par
adi
gm t
hat comput
ermachine.
execut
edi
nsequence(
oneaf
tert
heot
her
)as r
epr
esent
s concept
s as “
Obj
ect
”thathav
e
• Rel
iabi
li
ty:I
tcan be r
eli
ed
wr
it
ten.Thi
sty
peofpr
ogr
ammi
ngusest
heGo dat
afi
elds(
att
ri
but
est
hatdescr
ibet
heobj
ect
) upontodowhati
tisexpect
ed
To st
atementwhi
ch al
l
ows cont
rolt
o be and associ
ated pr
ocedur
es known as todo

passedt
oanyot
hersect
ioni
nthepr
ogr
am. met
hods.Obj
ect
s,whi
char
eusual
l
yinst
ances • Ef
fi
ciency
/cost sav
ing: I
t
ofcl
asses,ar
e used t
oint
eractwi
th one mustnotcostmor
ethani
ts
2.St
ruct
uredPr
ogr
ammi
ng
anot
hert
odesi
gnappl
i
cat
ionsandcomput
er benef
it
sandenabl
espr
obl
em
Theappr
oachwasdev
elopedasasol
uti
ont
o pr
ogr
ams. t
o be sol
ved appr
opr
iat
ely
,
t
he chal
l
enges posed by qui
ckl
yandef
fi
ci
ent
ly.
4.Vi
sualPr
ogr
ammi
ng
unst
ruct
ured/
procedur
al pr
ogr
ammi
ng. • Cl
ari
ty and Si
mpl
ici
ty: I
t
St
ruct
uredPr
ogr
ammi
ngf
requent
lyempl
oysa shoul
d be as si mple as
Av
isualPr
ogr
ammi
ngl
anguageusesav
isual
possi
blet
ounder
stand.
t
op down desi
gn model
,in whi
ch t
he r
epr
esent
ati
on (
such as gr
aphi
cs,dr
awi
ngs,
dev
eloper
s br
eaks t
he ov
eral
lpr
ogr
am i
nto
• Under
standabi
li
ty/
Readabi
li
ty:
ani
mat
ionori
cons,par
ti
all
yorcompl
etel
y).A

1
I
t must be r
eadabl
e and 6)Test
ing/
Runni
ng and Debuggi
ng 4) Codi
ng t
he st
atement
:Thi
s
under
standabl
e by ot
her i
nvol
ves wr
it
ing t
he pr
ogr
am
t
hepr
ogr
am 7)Document
ati
on.
pr
ogr
ammer
sandenduser
s. st
atement
s.The pr
ogr
ammer uses
• Fl
exi
bil
it
y/Adapt
abi
li
ty/
Mai
nt 8)Mai
ntenance t
hepr
ogr
am f
lowchar
tasagui
def
or
ai
nabi
li
ty:A good pr
ogr
am codi
ng t
he st
eps t
he comput
erwi
l
l
1) Pr
obl
em Def
ini
ti
on/
Anal
ysi
s
f
oll
ow.
must be f
lexi
ble adapt
abl
e
St
age:Ther
eisneed t
o under
stand
andmai
ntai
nabl
einor
dert
o
t
hepr
obl
em t
hatr
equi
resasol
uti
on. 5) Compi
li
ng:Ther
eis need t
o
sui
tuser
’sneed.Modi
fi
cat
ion
Theneedt
odet
ermi
net
hedat
atobe t
ransl
atet
hepr
ogr
am f
rom t
hesour
ce
mustbe possi
ble and v
ery
pr
ocessed,f
orm ort
ypeoft
hedat
a, codet
othemachi
neorobj
ectcodei
f
easy
.
v
olumeoft
hedat
a,whatt
obedonet
o i
tisnotwr
it
teni
nmachi
nel
anguage
PHASESOFPROGRAM t
he dat
a t
o pr
oduce t
he
DEVELOPMENT(
PROGRAMMI
NG) 6) Runni
ng, Test
ing and
expect
ed/
requi
redout
put
.
Debuggi
ng:When t
he comput
er i
s
Thepr
ocessofpr
oduci
ngacomput
er
2) Sel
ect
ionordev
elopmentof act
ivat
edt
orunapr
ogr
am,i
tmayf
ind
pr
ogr
am (
sof
twar
e)maybe di
vi
ded
anal
gor
it
hm:Anal
gor
it
hm i
stheset i
tdi
ff
icul
ttor
un i
tbecause er
ror
s
i
ntoei
ghtphasesorst
ages:
ofst
epsr
equi
redt
osol
veapr
obl
em (
synt
ax,
semant
icsorl
ogi
c,orr
unt
ime)

1)Pr
obl
em def
ini
ti
on/
Anal
ysi
s wr
it
tendowni
nEngl
i
shl
anguage. mi
ghthav
ebeencommi
tt
ed.

2)Sel
ect
ion or dev
elopment of an 3) Desi
gni
ng t
he pr
ogr
am: I
n 7) Document
ati
on:Thi
sist
he
al
gor
it
hm or
dert
omi
nimi
zet
heamountoft
ime l
astst
age i
n sof
twar
e dev
elopment
.
t
obespenti
ndev
elopi
ngt
hesof
twar
e, Thi
sinv
olv
eskeepi
ngwr
it
tenr
ecor
ds
3)Desi
gni
ngt
hepr
ogr
am
t
he pr
ogr
ammer makes use of t
hatdescr
ibet
hepr
ogr
am,expl
aini
ts

4)Codi
ng t
he pr
ogr
ammi
ng f
lowchar
t.Fl
owchar
tist
he pi
ctor
ial pur
poses,def
ine t
he amount
,ty
pes
st
atement
s r
epr
esent
ati
on of t
he al
gor
it
hm andsour
cesofi
nputdat
arequi
redt
o
dev
elopedi
nst
ep2abov
e. r
uni
t
5)Compi
l
ing/
Compi
l
ati
onst
age

2
8) Mai
ntenance:Al
ltheact
ivi
ti
es Di
sadvant
agesofStr
uctur
ed "
It
erat
ion"
;ast
atementorbl
ocki
sexecut
ed
Pr
ogrammingApproach: unt
ilt
hepr
ogr
am r
eachesacer
tai
nst
ate,or
t
hatoccuraf
tert
hecompl
eti
onoft
he
pr
ogr
am come undert
he pr
ogr
am oper
ati
onshav
ebeenappl
i
edt
oev
eryel
ement
1. Si
ncei
tisMachi
ne-
Independent
,Soi
t
mai
ntenance.Pr
ogr
am mai
ntenance takesti
me t
o conv
erti
nto machi
ne ofacol
l
ect
ion.
code.
i
ncl
udes t
he f
oll
owi
ng:Fi
ndi
ng and
2. Theconver
ted machi
necodei
snot 2. Subr
out
ines:subr
out
ines ar
e
cor
rect
ing t
he er
ror
s;Modi
fyi
ng t
he
t
hesameasf
orassembl
ylanguage. cal
l
abl
e uni
ts such as pr
ocedur
es,
pr
ogr
am t
oenhancei
t–i
.e.
,adapt
ing
3. The pr
ogr
am depends upon f
unct
ions,met
hods,orsubpr
ogr
ams
t
osomenew concept
sorwhent
her
e
changeabl
efact
orsl
i
ke dat
a-t
ypes. ar
eusedt
oal
l
ow asequencet
obe
i
s a change i
n t
he har
dwar
e or
Ther
efor
e,i
tneedst
obeupdat
edwi
th r
efer
redt
obyasi
ngl
est
atement
.
oper
ati
ng sy
stem; Updat
e t
he
t
heneedont
hego.
document
ati
on;
Addnewf
eat
uresand 3. Bl
ocks:Bl
ocks ar
e used t
o
f
unct
ions; Remov
e usel
ess or St
ruct
uredPr
ogr
ammi
ngEl
ement
s enabl
e gr
oups ofst
atement
sto be
r
edundantpar
tsofcode. t
reat
edasi
ftheywer
eonest
atement
.
St
ruct
uredpr
ogr
ammi
ngel
ement
scanbe
AdvantagesofSt
ruct
uredPr
ogr
ammi
ng cat
egor
ies i
nto t
hree,namel
y;cont
rol STRUCTUREDDESI
GNPRI
NCI
PLES
Approach:
st
ruct
ures,
subr
out
ines,
andbl
ocks. St
ruct
ureddesi
gni
sasof
twar
edesi
gnmet
hod
1. Easi
ert
oreadandunder
stand t
hatemphasi
zes br
eaki
ng a pr
ogr
am down
1. Cont
rol st
ruct
ures: Fol
l
owi
ng t
he
2. UserFr
iendl
y i
nto smal
l
ermodul
es orf
unct
ions,each of
st
ruct
ured pr
ogr
am t
heor
em, al
l
whi
chper
for
msaspeci
fi
ctask.
3. Easi
ert
oMai
ntai
n
pr
ogr
amsar
eseenascomposedof
4. Mai
nly pr
obl
em based i
nst
ead of t
hreecont
rol
str
uct
ures: .Her
ear
eaf
ew:
bei
ngmachi
nebased
"Sequence"
; or dered stat
ement
s or Modul
ari
ty:Di
vi
ding apr
ogr
am i
nto smal
l
er,
5. Devel
opmenti
seasi
erasi
trequi
res subrouti
nesexecutedinsequence. i
ndependentuni
ts cal
l
ed modul
es makes i
t
l
essef
for
tandt
ime
"
Sel
ect
ion"
;oneoranumberofst
atement
sis easi
ert
ounder
stand,
modi
fy,
andt
est
.
6. Easi
ert
oDebug
execut
ed dependi
ng on t
he st
ate of t
he
7. Machi
ne-
Independent
,most
ly. Decomposi
ti
on: Thi
s pr
inci
ple i
nvol
ves
pr
ogr
am.

3
br
eaki
ngdownal
arge,compl
expr
obl
em i
nto MODULARI
TY modul
es cal
l
ed f
unct
ions or
smal
l
er,
mor
emanageabl
epi
eces. pr
ocedur
eseachofwhi
chhandl
esa
Modul
ar pr
ogr
ammi
ng i
s t
he pr
ocess of
par
ti
cul
arr
esponsi
bil
i
ty.Thepr
ogr
am
Abst
ract
ion:Thi
spr
inci
plei
nvol
vessepar
ati
ng subdi
vi
dingacomput
erpr
ogr
am i
ntosepar
ate
whi
chsol
vest
heent
ir
epr
obl
em i
sa
t
heessent
ialf
eat
uresofapr
obl
em orsol
uti
on subpr
ogr
ams.
col
l
ect
ionofsuchf
unct
ions.
f
rom t
heunnecessar
ydet
ail
s.
ADVANTAGESOFUSI
NGMODULAR
Amodul
eisbasi
cal
l
yasetofi
nter
rel
atedf
il
es
Dat
ahi
ding:Thi
spr
inci
plei
nvol
vespr
otect
ing PROGRAMMING
t
hatshar
ethei
rimpl
ement
ati
on det
ail
s but
t
hei
nter
naldat
aofamodul
efr
om acci
dent
al
EaseofUse:Thi
sappr
oachal
l
owssi
mpl
i
cit
y, hi
dei
tfr
om t
heout
sidewor
ld
orunaut
hor
izedaccess.
asl
i
nesofpr
ogr
am codecanbeaccessedi
n
Modul
ari
zat
ioni
samet
hodt
oor
gani
zel
arge
I
nfor
mat
ion hi
ding:Thi
s pr
inci
plei
nvol
ves t
hef
orm ofmodul
es,r
athert
hanf
ocusi
ngon
pr
ogr
amsi
nsmal
l
erpar
ts,
i.
e.,
themodul
es.
separ
ati
ngt
hei
nter
faceofamodul
e(t
hepar
t t
heent
ir
ethousandsandmi
l
li
onsofl
i
nescode.

t
hati
svi
si
blet
oot
herpar
tsoft
hepr
ogr
am) Modular
izat
ion has sev
eralbenef
its,
Reusabi
li
ty:I
tal
l
ows t
he usert
oreuse t
he
f
rom i
tsi
mpl
ement
ati
on(
thei
nter
naldet
ail
sof especi
all
y on l ar
ge and compl ex
f
unct
ional
i
tywi
thadi
ff
erenti
nter
facewi
thout progr
ams:
howi
tper
for
msi
tst
ask)
.
t
ypi
ngt
hewhol
epr
ogr
am agai
n.
• modul
es can be r
e-used i
n
ABSTRACTI
ON
EaseofMai
ntenance:I
thel
psi
nlesscol
l
isi
on sev
eral
proj
ect
s;

Dat
a abst
ract
ion i
s t
he r
educt
ion of a att
het
imeofwor
kingonmodul
es,hel
pinga • changi
ngt
hei
mpl
ement
ati
on
par
ti
cul
ar body of dat
a t
o a si
mpl
i
fied t
eam t
owor
kwi
thpr
opercol
l
abor
ati
onwhi
l
e det
ail
s ofa modul
es does
r
epr
esent
ati
on oft
he whol
e.Abst
ract
ion,i
n wor
kingonal
argeappl
i
cat
ion not r
equi
ret
o modi
fyt
he
gener
al,i
sthepr
ocessofr
efi
ningort
aki
ng cl
i
ent
susi
ngt
hem asf
aras
MODULARPROGRAMMI
NGI
NC
away or r
emov
ing char
act
eri
sti
cs f
rom t
he i
nter
face does not
somet
hingi
nor
dert
oreducei
ttoasetof Ci
scal
l
edast
ruct
uredpr
ogr
ammi
ng change;
essent
ial
char
act
eri
sti
cs. l
anguage because t
o sol
veal
arge • f
ast
err
e-compi
l
ati
on,asonl
y
pr
obl
em,C pr
ogr
ammi
ng l
anguage
t
hemodul
est
hathav
ebeen
di
vi
des t
he pr
obl
em i
nto smal
l
er

4
modi
fi
ed ar
e act
ual
l
y t
ri
vi
alpr
ogr
amscandef
ineaddi
ti
onal pr
ogr
ammi
ngconsi
stsofaf
unct
ion
r
ecompi
l
ed; f
unct
ions. headerandaf
unct
ionbody
.Her
ear
e
• sel
f-
document
ing, as t
he al
lthepar
tsofaf
unct
ion–
A f
unct
ion decl
arat
ion t
ell
s t
he
i
nter
facespeci
fi
esal
lthati
s
compi
l
erabouta f
unct
ion'
s name, • Ret
urnTy
pe−Af
unct
ionmayr
etur
na
r
equi
redt
oknow t
ouset
he
r
etur
n t
ype, and par
amet
ers. A v
alue.Ther
etur
nty
pei
sthedat
aty
pe
modul
e;
f
unct
iondef
ini
ti
onpr
ovi
dest
heact
ual of t
he v
alue t
he f
unct
ion r
etur
ns.
• easi
er debuggi
ng, as
bodyoft
hef
unct
ion. Somef
unct
ionsper
for
mthedesi
red
modul
es dependenci
es ar
e oper
ati
onswi
thoutr
etur
ningav
alue.
cl
ear
ly speci
fi
ed and ev
ery Afunct
ioncanalsoberef
err
edasa
method or a sub-r
outi
ne or a I
nthi
s case,t
he r
etur
nty
pe i
sthe
modul
e can be t
est
ed pr
ocedure,
etc. key
wor
dvoi
d.
separ
atel
y.
Def
ini
ngaFunct
ion • Funct
ionName−Thi
sist
heact
ual
Pr
ogr
ammi
ng by modul
es usi
ng t
he C name oft
he f
unct
ion.The f
unct
ion
l
anguagemeansspl
i
tti
ngev
erysour
cecode Thegener
alf
orm ofa
nameandt
hepar
amet
erl
i
stt
oget
her
i
ntoaheaderf
il
emodul
e1.
hthatspeci
fi
eshow const
it
utet
hef
unct
ionsi
gnat
ure.
f
unct
iondef
ini
ti
oni
nC
t
hat modul
etal
ks t
o t
he cl
i
ent
s,and a
cor
respondi
ng i
mpl
ement
ati
on sour
ce f
il
e pr
ogr
ammi
ng • Par
amet
ers−A par
amet
eri
sli
kea

modul
e1.
cwher
eal
lthecodeandt
hedet
ail
s pl
acehol
der
. When a f
unct
ion i
s
l
anguagei
sasf
oll
ows
ar
ehi
dden. i
nvoked,y
ou pass a v
alue t
othe
r
etur
nty
pef
unct
ion par
amet
er.Thi
sval
uei
sref
err
edt
oas
CFunct
ions act
ualpar
amet
erorar
gument
.The
name(
par
amet
erl
i
st)
par
amet
erl
i
str
efer
stot
het
ype,
order
,
Af
unct
ioni
sagr
oupofst
atement
s
{
bodyoft
hef
unct
ion andnumberoft
hepar
amet
ersofa
t
hatt
oget
herper
for
m at
ask.Ev
eryC
f
unct
ion. Par
amet
ers ar
e opt
ional
;
pr
ogr
am has atl
eastone f
unct
ion,
}
t
hati
s,a f
unct
ion may cont
ain no
whi
ch i
s mai
n()
,and al
lthe most
A f
unct
ion def
ini
ti
on i
n C par
amet
ers.

5
• Funct
ion Body− Thef
unct
ionbody f
unct
iondecl
arat
iononl
ythei
rty
pei
s Tocal
laf
unct
ion,y
ousi
mpl
yneedt
o
cont
ains a col
l
ect
ion ofst
atement
s r
equi
red,so t
he f
oll
owi
ng i
sal
so a passt
her
equi
red par
amet
ersal
ong
t
hatdef
inewhatt
hef
unct
iondoes. wi
tht
he f
unct
ion name,and i
fthe
v
ali
ddecl
arat
ion−i
ntmax(
int
,int
);
f
unct
ionr
etur
nsav
alue,t
heny
oucan
FUNCTI
ONDECLARATI
ON
Funct
iondecl
arat
ioni
srequi
redwhen st
oret
her
etur
nedv
alue.

Af
unct
iondecl
arat
iont
ell
sthe y
oudef
ineaf
unct
ioni
nonesour
ce
FUNCTI
ONARGUMENT
f
il
e and y
ou cal
lthat f
unct
ion i
n
compi
l
eraboutaf
unct
ionnameand
anot
herf
il
e.I
nsuchcase,y
oushoul
d I
faf
unct
ioni
stousear
gument
s,i
t
howt
ocal
lthef
unct
ion.Theact
ual decl
aret
hef
unct
ionatt
het
opoft
he mustdecl
arev
ari
abl
est
hatacceptt
he
bodyoft
hef
unct
ioncanbedef
ined f
il
ecal
l
ingt
hef
unct
ion. v
alues of t
he ar
gument
s. These
v
ari
abl
es ar
e cal
l
ed t
he f
ormal
separ
atel
y.Af
unct
iondecl
arat
ionhas CALLI
NGAFUNCTI
ON
par
amet
ersoft
hef
unct
ion.
t
hef
oll
owi
ngpar
ts−r
etur
nty
pe
Whi
l
ecr
eat
ingaCf
unct
ion,
yougi
vea
STEPWI
SEREFI
NEMENT
f
unct
ionname(
par
amet
erl
i
st)
; def
ini
ti
onofwhatt
hef
unct
ionhast
o
do.Touseaf
unct
ion,y
ouwi
l
lhav
eto St
epwi
se r
efi
nement i
s a sof
twar
e
For t
he abov
e
cal
lthat f
unct
ion t
o per
for
m t
he dev
elopmentt
echni
quet
hati
nvol
vesbr
eaki
ng
def
ined f
unct
ion def
inedt
ask. down a l
argerpr
obl
em i
nto smal
l
er,mor
e
manageabl
epr
obl
emsandt
hensol
vi
ngt
hose
max(
),t
hef
unct
ion Whenapr
ogr
am cal
l
saf
unct
ion,t
he
pr
obl
emsonebyone.Thi
spr
ocessofbr
eaki
ng
pr
ogr
am cont
roli
str
ansf
err
edt
othe
decl
arat
ion i
s as down a pr
obl
em i
nto smal
l
er,mor
e easi
l
y
cal
l
ed f
unct
ion. A cal
l
ed f
unct
ion
sol
vabl
esubpr
obl
emsi
scal
l
eddecomposi
ti
on
f
oll
ows−i
ntmax(
int per
for
msadef
inedt
askandwheni
ts
r
etur
nst
atementi
sexecut
edorwhen EXAMPLE
num1,
intnum2)
;
i
tsf
unct
ion-
endi
ng cl
osi
ng br
ace i
s
Par
amet
ernamesar
enoti
mpor
tanti
n r
eached, i
t r
etur
ns t
he pr
ogr
am Themostef
fect
ivewayt
osol
veacompl
ex

cont
rol
backt
othemai
npr
ogr
am. pr
obl
em i
stobr
eaki
tdowni
ntosuccessi
vel
y

6
si
mpl
ersubpr
obl
ems. r
eusedal
lthet
ime.I
fyourmet
hods
per
for
m gener
alt
asks,t
heyar
emuch
•Youst
artbybr
eaki
ngt
hewhol
etaskdown
easi
ert
oreuse.
i
ntosi
mpl
erpar
ts.
2.Thest
epsshoul
dmakesenseatt
he
•Someoft
hoset
asksmayt
hemsel
vesneed l
evelofabst
ract
ionatwhi
cht
heyar
e
subdi
vi
sion.
used.I
fyouhav
eamet
hodt
hatdoes
t
her
ightj
obbutwhosenamedoesn’
t
•Thi
spr
ocessi
scal
l
edst
epwi
ser
efi
nement
ordecomposi
ti
on. make sense i
nthe cont
extoft
he
pr
obl
em,i
tispr
obabl
ywor
thdef
ini
ng
anewmet
hodt
hatcal
l
stheol
done.

Crit
eri
aforChoosingaDecomposi t
ionThe
proposedstepsshoul
dbeeasyt oexpl
ain.One
i
ndicati
onthatyouhavesucceededisbeing
abletofi
ndsimplenames.

1.Thest
epsshoul
d beasgener
alas
possi
ble. Pr
ogr
ammi
ng t
ool
s get

You might also like