SlideShare a Scribd company logo
1 of 23
Introduction ttoo PPrrooggrraammmmiinngg 
LLeeccttuurree 99
PPrrooggrraammmmiinngg 
TToooollkkiitt 
 DDeecciissiioonnss 
 LLooooppss 
 SSeeqquueenncceess
LLaabboorraattoorryy SSttooooll
Constructing aa llaabboorraattoorryy 
SSttooooll
Constructing aa llaabboorraattoorryy 
SSttooooll 
 TTaasskk:: MMaakkiinngg aa ssttooooll 
– SSuubbttaasskk:: 
 MMaakkee aa sseeaatt 
 MMaakkee lleeggss ffoorr tthhee ssttooooll 
 AAsssseemmbbllee tthheemm
WWhhaatt wwee wwiillll ssttuuddyy ttooddaayy …… 
 What aarree ffuunnccttiioonnss?? 
 HHooww aarree tthheeyy ddeeffiinneedd ?? 
 HHooww aarree tthheeyy ddeeccllaarreedd ?? 
 WWhhaatt vvaalluueess aarree ppaasssseedd ttoo 
ffuunnccttiioonnss ?? 
 WWhhaatt vvaalluueess ddoo ffuunnccttiioonnss rreettuurrnn ??
FFuunnccttiioonn 
FFuunnccttiioonn nnaammee 
{{ 
BBooddyy ooff tthhee ffuunnccttiioonn 
}}
FFuunnccttiioonn 
TTwwoo ttyyppeess ooff ffuunnccttiioonnss:: 
11.. FFuunnccttiioonnss tthhaatt rreettuurrnn aa vvaalluuee 
22.. FFuunnccttiioonnss tthhaatt ddoo nnoott rreettuurrnn aa vvaalluuee
Function 
return-value-type function-name( aarrgguummeenntt--lliisstt )) 
{{ 
ddeeccllaarraattiioonnss aanndd ssttaatteemmeennttss 
}}
Declaration of 
Function 
return-value-type function-name( aarrgguummeenntt----ttyyppee--lliisstt)) ;; 
mmaaiinn (( )) 
{{ 
:: 
}}
EExxaammppllee 
iinntt ffuunnccttiioonn--nnaammee (( iinntt ,, iinntt ,, ddoouubbllee )) ;; 
vvooiidd mmaaiinn (( )) 
{{ 
…….. 
}}
iinntt ffuunnccttiioonn--nnaammee (( iinntt ii ,, ddoouubbllee jj )) 
{{ 
…… 
}} 
Definition of Function
Return Type of Function 
iinntt ssqquuaarree (( iinntt )) ;; 
iinntt ssqquuaarree (( iinntt ii )) 
{{ 
rreettuurrnn (( ii ** ii )) ;; 
}} 
Declaration 
Definition
Function Call 
iinntt xx ;; 
xx == ssqquuaarree (( ii )) ;;
Example: Function to calculate 
double raiseToPow ( double xx ,, iinntt ppoowweerr )) 
{{ 
ddoouubbllee rreessuulltt ;; 
iinntt ii ;; 
rreessuulltt == 11..00 ;; 
ffoorr (( ii == 11 ;; ii <<== ppoowweerr ;; ii ++++ )) //// bbrraacceess ffiirrsstt 
{{ 
rreessuulltt ** == xx ;; //// rreessuulltt == rreessuulltt **xx 
}} 
rreettuurrnn (( rreessuulltt )) ;; 
}} 
integer power ( Xn )
include << iioossttrreeaamm..hh >> 
vvooiidd mmaaiinn (( )) 
{{ 
ddoouubbllee xx ;; 
iinntt ii ;; 
ccoouutt <<<< ““ PPlleeaassee eenntteerr tthhee nnuummbbeerr ““ ;; 
cciinn >>>> xx ;; 
ccoouutt <<<< ““ PPlleeaassee eenntteerr tthhee iinntteeggeerr ppoowweerr tthhaatt yyoouu wwaanntt tthhiiss nnuummbbeerr rraaiisseedd ttoo ““ cciinn >>>> ii ;; 
ccoouutt <<<< xx <<<< ““ rraaiissee ttoo ppoowweerr ““ <<<< ii <<<< ““iiss eeqquuaall ttoo ““ <<<< rraaiisseeTTooPPooww (( xx ,, ii )) ;; 
}} 
Code to Call the raisetopow 
Function
CCaallll BByy VVaalluuee
CCaalllliinngg ffuunnccttiioonn 
CCaalllleedd ffuunnccttiioonn
AArreeaa ooff tthhee RRiinngg 
Inner Circle 
Outer Circle 
Area of Outer Circle ____ Area of Inner Circle = Area of the Ring
Example: Function to calculate 
the area of a circle 
double cciirrcclleeAArreeaa (( ddoouubbllee rraaddiiuuss )) 
{{ 
rreettuurrnn (( 33..11441155992266 ** rraaddiiuuss ** rraaddiiuuss )) ;; 
}}
Calculating ringArea without 
mmaaiinn (( )) 
{{ 
using Function 
:: 
rriinnggAArreeaa == (( 33..11441155992266 ** rraadd11 ** rraadd11 )) –– (( 33..11441155992266 ** rraadd22 ** rraadd22 )) ;; 
}}
EExxeerrcciisseess 
11.. MMooddiiffyy tthhee rraaiissee ttoo ppoowweerr ffuunnccttiioonn 
ssoo tthhaatt iitt ccaann hhaannddllee nneeggaattiivvee ppoowweerr 
ooff xx,, zzeerroo aanndd ppoossiittiivvee ppoowweerr ooff xx.. 
22.. FFoorr tthhee aarreeaa ooff rriinngg ffuunnccttiioonn ppuutt iinn 
eerrrroorr cchheecckkiinngg mmeecchhaanniissmm..
IInn ttooddaayy’’ss lleeccttuurree 
 We used functions for breaking ccoommpplleexx pprroobblleemmss iinnttoo 
ssmmaalllleerr ppiieecceess,, wwhhiicchh iiss aa ttoopp--ddoowwnn ssttrruuccttuurreedd aapppprrooaacchh.. 
 EEaacchh ffuunnccttiioonn sshhoouulldd bbee aa ssmmaallll mmoodduullee,, sseellff ccoonnttaaiinneedd 
aanndd iitt sshhoouulldd ssoollvvee aa wweellll ddeeffiinneedd pprroobblleemm.. 
 VVaarriiaabbllee nnaammeess aanndd ffuunnccttiioonn nnaammeess sshhoouulldd bbee sseellff 
eexxppllaannaattoorryy.. 
 AAllwwaayyss ccoommmmeenntt yyoouurr ccooddee

More Related Content

What's hot

CS201- Introduction to Programming- Lecture 31
CS201- Introduction to Programming- Lecture 31CS201- Introduction to Programming- Lecture 31
CS201- Introduction to Programming- Lecture 31Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 13
CS201- Introduction to Programming- Lecture 13CS201- Introduction to Programming- Lecture 13
CS201- Introduction to Programming- Lecture 13Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 33
CS201- Introduction to Programming- Lecture 33CS201- Introduction to Programming- Lecture 33
CS201- Introduction to Programming- Lecture 33Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 14
CS201- Introduction to Programming- Lecture 14CS201- Introduction to Programming- Lecture 14
CS201- Introduction to Programming- Lecture 14Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 34
CS201- Introduction to Programming- Lecture 34CS201- Introduction to Programming- Lecture 34
CS201- Introduction to Programming- Lecture 34Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 40
CS201- Introduction to Programming- Lecture 40CS201- Introduction to Programming- Lecture 40
CS201- Introduction to Programming- Lecture 40Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 37
CS201- Introduction to Programming- Lecture 37CS201- Introduction to Programming- Lecture 37
CS201- Introduction to Programming- Lecture 37Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 10
CS201- Introduction to Programming- Lecture 10CS201- Introduction to Programming- Lecture 10
CS201- Introduction to Programming- Lecture 10Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 44
CS201- Introduction to Programming- Lecture 44CS201- Introduction to Programming- Lecture 44
CS201- Introduction to Programming- Lecture 44Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 25
CS201- Introduction to Programming- Lecture 25CS201- Introduction to Programming- Lecture 25
CS201- Introduction to Programming- Lecture 25Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 41
CS201- Introduction to Programming- Lecture 41CS201- Introduction to Programming- Lecture 41
CS201- Introduction to Programming- Lecture 41Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 20
CS201- Introduction to Programming- Lecture 20CS201- Introduction to Programming- Lecture 20
CS201- Introduction to Programming- Lecture 20Bilal Ahmed
 
System of linear equation by Graphical Method
System of linear equation by Graphical MethodSystem of linear equation by Graphical Method
System of linear equation by Graphical MethodJoseph Nilo
 
CS201- Introduction to Programming- Lecture 27
CS201- Introduction to Programming- Lecture 27CS201- Introduction to Programming- Lecture 27
CS201- Introduction to Programming- Lecture 27Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 45
CS201- Introduction to Programming- Lecture 45CS201- Introduction to Programming- Lecture 45
CS201- Introduction to Programming- Lecture 45Bilal Ahmed
 
3r ESO: ESTRUCTURA DE LA MATÈRIA
3r ESO: ESTRUCTURA DE LA MATÈRIA3r ESO: ESTRUCTURA DE LA MATÈRIA
3r ESO: ESTRUCTURA DE LA MATÈRIArosaquima
 
CS201- Introduction to Programming- Lecture 12
CS201- Introduction to Programming- Lecture 12CS201- Introduction to Programming- Lecture 12
CS201- Introduction to Programming- Lecture 12Bilal Ahmed
 
anatomy of the larynx
anatomy of the larynxanatomy of the larynx
anatomy of the larynxPave Medicine
 
CS201- Introduction to Programming- Lecture 42
CS201- Introduction to Programming- Lecture 42CS201- Introduction to Programming- Lecture 42
CS201- Introduction to Programming- Lecture 42Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 39
CS201- Introduction to Programming- Lecture 39CS201- Introduction to Programming- Lecture 39
CS201- Introduction to Programming- Lecture 39Bilal Ahmed
 

What's hot (20)

CS201- Introduction to Programming- Lecture 31
CS201- Introduction to Programming- Lecture 31CS201- Introduction to Programming- Lecture 31
CS201- Introduction to Programming- Lecture 31
 
CS201- Introduction to Programming- Lecture 13
CS201- Introduction to Programming- Lecture 13CS201- Introduction to Programming- Lecture 13
CS201- Introduction to Programming- Lecture 13
 
CS201- Introduction to Programming- Lecture 33
CS201- Introduction to Programming- Lecture 33CS201- Introduction to Programming- Lecture 33
CS201- Introduction to Programming- Lecture 33
 
CS201- Introduction to Programming- Lecture 14
CS201- Introduction to Programming- Lecture 14CS201- Introduction to Programming- Lecture 14
CS201- Introduction to Programming- Lecture 14
 
CS201- Introduction to Programming- Lecture 34
CS201- Introduction to Programming- Lecture 34CS201- Introduction to Programming- Lecture 34
CS201- Introduction to Programming- Lecture 34
 
CS201- Introduction to Programming- Lecture 40
CS201- Introduction to Programming- Lecture 40CS201- Introduction to Programming- Lecture 40
CS201- Introduction to Programming- Lecture 40
 
CS201- Introduction to Programming- Lecture 37
CS201- Introduction to Programming- Lecture 37CS201- Introduction to Programming- Lecture 37
CS201- Introduction to Programming- Lecture 37
 
CS201- Introduction to Programming- Lecture 10
CS201- Introduction to Programming- Lecture 10CS201- Introduction to Programming- Lecture 10
CS201- Introduction to Programming- Lecture 10
 
CS201- Introduction to Programming- Lecture 44
CS201- Introduction to Programming- Lecture 44CS201- Introduction to Programming- Lecture 44
CS201- Introduction to Programming- Lecture 44
 
CS201- Introduction to Programming- Lecture 25
CS201- Introduction to Programming- Lecture 25CS201- Introduction to Programming- Lecture 25
CS201- Introduction to Programming- Lecture 25
 
CS201- Introduction to Programming- Lecture 41
CS201- Introduction to Programming- Lecture 41CS201- Introduction to Programming- Lecture 41
CS201- Introduction to Programming- Lecture 41
 
CS201- Introduction to Programming- Lecture 20
CS201- Introduction to Programming- Lecture 20CS201- Introduction to Programming- Lecture 20
CS201- Introduction to Programming- Lecture 20
 
System of linear equation by Graphical Method
System of linear equation by Graphical MethodSystem of linear equation by Graphical Method
System of linear equation by Graphical Method
 
CS201- Introduction to Programming- Lecture 27
CS201- Introduction to Programming- Lecture 27CS201- Introduction to Programming- Lecture 27
CS201- Introduction to Programming- Lecture 27
 
CS201- Introduction to Programming- Lecture 45
CS201- Introduction to Programming- Lecture 45CS201- Introduction to Programming- Lecture 45
CS201- Introduction to Programming- Lecture 45
 
3r ESO: ESTRUCTURA DE LA MATÈRIA
3r ESO: ESTRUCTURA DE LA MATÈRIA3r ESO: ESTRUCTURA DE LA MATÈRIA
3r ESO: ESTRUCTURA DE LA MATÈRIA
 
CS201- Introduction to Programming- Lecture 12
CS201- Introduction to Programming- Lecture 12CS201- Introduction to Programming- Lecture 12
CS201- Introduction to Programming- Lecture 12
 
anatomy of the larynx
anatomy of the larynxanatomy of the larynx
anatomy of the larynx
 
CS201- Introduction to Programming- Lecture 42
CS201- Introduction to Programming- Lecture 42CS201- Introduction to Programming- Lecture 42
CS201- Introduction to Programming- Lecture 42
 
CS201- Introduction to Programming- Lecture 39
CS201- Introduction to Programming- Lecture 39CS201- Introduction to Programming- Lecture 39
CS201- Introduction to Programming- Lecture 39
 

Viewers also liked

Poto copian pemahaman studi hukum islam
Poto copian pemahaman studi hukum islamPoto copian pemahaman studi hukum islam
Poto copian pemahaman studi hukum islamNur Alfiyatur Rochmah
 
ENG101- English Comprehension- Lecture 31
ENG101- English Comprehension- Lecture 31ENG101- English Comprehension- Lecture 31
ENG101- English Comprehension- Lecture 31Bilal Ahmed
 
Aga power softcase catalog
Aga power softcase catalogAga power softcase catalog
Aga power softcase catalogslideroma
 
Kids Party Decoration Supplies Online
Kids Party Decoration Supplies Online Kids Party Decoration Supplies Online
Kids Party Decoration Supplies Online JoeCavallaro
 
IT security - continuïteit van uw onderneming - Orbid
IT security - continuïteit van uw onderneming - OrbidIT security - continuïteit van uw onderneming - Orbid
IT security - continuïteit van uw onderneming - OrbidOrbid
 
CS101- Introduction to Computing- Lecture 41
CS101- Introduction to Computing- Lecture 41CS101- Introduction to Computing- Lecture 41
CS101- Introduction to Computing- Lecture 41Bilal Ahmed
 
Sejarah teknologi komputer dan internet
Sejarah teknologi  komputer dan internetSejarah teknologi  komputer dan internet
Sejarah teknologi komputer dan internetNur Alfiyatur Rochmah
 
MGT101 - Financial Accounting- Lecture 37
MGT101 - Financial Accounting- Lecture 37MGT101 - Financial Accounting- Lecture 37
MGT101 - Financial Accounting- Lecture 37Bilal Ahmed
 
CS101- Introduction to Computing- Lecture 27
CS101- Introduction to Computing- Lecture 27CS101- Introduction to Computing- Lecture 27
CS101- Introduction to Computing- Lecture 27Bilal Ahmed
 
Describing different childrens party themes
Describing different childrens party themes  Describing different childrens party themes
Describing different childrens party themes JoeCavallaro
 

Viewers also liked (19)

Poto copian pemahaman studi hukum islam
Poto copian pemahaman studi hukum islamPoto copian pemahaman studi hukum islam
Poto copian pemahaman studi hukum islam
 
ENG101- English Comprehension- Lecture 31
ENG101- English Comprehension- Lecture 31ENG101- English Comprehension- Lecture 31
ENG101- English Comprehension- Lecture 31
 
Aga power softcase catalog
Aga power softcase catalogAga power softcase catalog
Aga power softcase catalog
 
Kids Party Decoration Supplies Online
Kids Party Decoration Supplies Online Kids Party Decoration Supplies Online
Kids Party Decoration Supplies Online
 
IT security - continuïteit van uw onderneming - Orbid
IT security - continuïteit van uw onderneming - OrbidIT security - continuïteit van uw onderneming - Orbid
IT security - continuïteit van uw onderneming - Orbid
 
CS101- Introduction to Computing- Lecture 41
CS101- Introduction to Computing- Lecture 41CS101- Introduction to Computing- Lecture 41
CS101- Introduction to Computing- Lecture 41
 
Shi pemahaman hukum islam
Shi pemahaman hukum islamShi pemahaman hukum islam
Shi pemahaman hukum islam
 
Sejarah teknologi komputer dan internet
Sejarah teknologi  komputer dan internetSejarah teknologi  komputer dan internet
Sejarah teknologi komputer dan internet
 
Botón de mano y volante de mano
Botón de mano y volante de manoBotón de mano y volante de mano
Botón de mano y volante de mano
 
Mtm terbaru 02 06-2014 (2)
Mtm terbaru 02 06-2014 (2)Mtm terbaru 02 06-2014 (2)
Mtm terbaru 02 06-2014 (2)
 
Bab i, ii, iii
Bab i, ii, iiiBab i, ii, iii
Bab i, ii, iii
 
Untuk presentasi
Untuk presentasi Untuk presentasi
Untuk presentasi
 
MGT101 - Financial Accounting- Lecture 37
MGT101 - Financial Accounting- Lecture 37MGT101 - Financial Accounting- Lecture 37
MGT101 - Financial Accounting- Lecture 37
 
CS101- Introduction to Computing- Lecture 27
CS101- Introduction to Computing- Lecture 27CS101- Introduction to Computing- Lecture 27
CS101- Introduction to Computing- Lecture 27
 
K om non verbal
K om non verbalK om non verbal
K om non verbal
 
Studi hukum islam
Studi hukum islam Studi hukum islam
Studi hukum islam
 
Describing different childrens party themes
Describing different childrens party themes  Describing different childrens party themes
Describing different childrens party themes
 
Kelompok 2
Kelompok 2Kelompok 2
Kelompok 2
 
Hukum islam
Hukum islamHukum islam
Hukum islam
 

Similar to CS201- Introduction to Programming- Lecture 09

CS201- Introduction to Programming- Lecture 07
CS201- Introduction to Programming- Lecture 07CS201- Introduction to Programming- Lecture 07
CS201- Introduction to Programming- Lecture 07Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 11
CS201- Introduction to Programming- Lecture 11CS201- Introduction to Programming- Lecture 11
CS201- Introduction to Programming- Lecture 11Bilal Ahmed
 
21 High-quality programming code construction part-ii
21 High-quality programming code construction part-ii21 High-quality programming code construction part-ii
21 High-quality programming code construction part-iimaznabili
 
CS201- Introduction to Programming- Lecture 38
CS201- Introduction to Programming- Lecture 38CS201- Introduction to Programming- Lecture 38
CS201- Introduction to Programming- Lecture 38Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 06
CS201- Introduction to Programming- Lecture 06CS201- Introduction to Programming- Lecture 06
CS201- Introduction to Programming- Lecture 06Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 18
CS201- Introduction to Programming- Lecture 18CS201- Introduction to Programming- Lecture 18
CS201- Introduction to Programming- Lecture 18Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 36
CS201- Introduction to Programming- Lecture 36CS201- Introduction to Programming- Lecture 36
CS201- Introduction to Programming- Lecture 36Bilal Ahmed
 
Design of the South Doña Ana Dam
Design of the South Doña Ana DamDesign of the South Doña Ana Dam
Design of the South Doña Ana DamDesh Sonyok
 
Avaliacao de investimentos
Avaliacao de investimentosAvaliacao de investimentos
Avaliacao de investimentosdanilobotucatu
 
CS201- Introduction to Programming- Lecture 28
CS201- Introduction to Programming- Lecture 28CS201- Introduction to Programming- Lecture 28
CS201- Introduction to Programming- Lecture 28Bilal Ahmed
 
TOP Downloaded Papers (January)--International Journal of Computer Networks &...
TOP Downloaded Papers (January)--International Journal of Computer Networks &...TOP Downloaded Papers (January)--International Journal of Computer Networks &...
TOP Downloaded Papers (January)--International Journal of Computer Networks &...IJCNCJournal
 
Osteo osteomalacia ricket2
Osteo osteomalacia ricket2Osteo osteomalacia ricket2
Osteo osteomalacia ricket2padli ahmad
 
01 termoqu%e dmica
01 termoqu%e dmica01 termoqu%e dmica
01 termoqu%e dmicaIQPonce14
 
Government resources
Government resourcesGovernment resources
Government resourcesKatie Avery
 

Similar to CS201- Introduction to Programming- Lecture 09 (18)

CS201- Introduction to Programming- Lecture 07
CS201- Introduction to Programming- Lecture 07CS201- Introduction to Programming- Lecture 07
CS201- Introduction to Programming- Lecture 07
 
CS201- Introduction to Programming- Lecture 11
CS201- Introduction to Programming- Lecture 11CS201- Introduction to Programming- Lecture 11
CS201- Introduction to Programming- Lecture 11
 
21 High-quality programming code construction part-ii
21 High-quality programming code construction part-ii21 High-quality programming code construction part-ii
21 High-quality programming code construction part-ii
 
Ch07
Ch07Ch07
Ch07
 
CS201- Introduction to Programming- Lecture 38
CS201- Introduction to Programming- Lecture 38CS201- Introduction to Programming- Lecture 38
CS201- Introduction to Programming- Lecture 38
 
CS201- Introduction to Programming- Lecture 06
CS201- Introduction to Programming- Lecture 06CS201- Introduction to Programming- Lecture 06
CS201- Introduction to Programming- Lecture 06
 
CS201- Introduction to Programming- Lecture 18
CS201- Introduction to Programming- Lecture 18CS201- Introduction to Programming- Lecture 18
CS201- Introduction to Programming- Lecture 18
 
CS201- Introduction to Programming- Lecture 36
CS201- Introduction to Programming- Lecture 36CS201- Introduction to Programming- Lecture 36
CS201- Introduction to Programming- Lecture 36
 
Design of the South Doña Ana Dam
Design of the South Doña Ana DamDesign of the South Doña Ana Dam
Design of the South Doña Ana Dam
 
Avaliacao de investimentos
Avaliacao de investimentosAvaliacao de investimentos
Avaliacao de investimentos
 
Tiro parabólico
Tiro parabólicoTiro parabólico
Tiro parabólico
 
CS201- Introduction to Programming- Lecture 28
CS201- Introduction to Programming- Lecture 28CS201- Introduction to Programming- Lecture 28
CS201- Introduction to Programming- Lecture 28
 
TOP Downloaded Papers (January)--International Journal of Computer Networks &...
TOP Downloaded Papers (January)--International Journal of Computer Networks &...TOP Downloaded Papers (January)--International Journal of Computer Networks &...
TOP Downloaded Papers (January)--International Journal of Computer Networks &...
 
Resumen termoquimica1
Resumen termoquimica1Resumen termoquimica1
Resumen termoquimica1
 
Training methods
Training methodsTraining methods
Training methods
 
Osteo osteomalacia ricket2
Osteo osteomalacia ricket2Osteo osteomalacia ricket2
Osteo osteomalacia ricket2
 
01 termoqu%e dmica
01 termoqu%e dmica01 termoqu%e dmica
01 termoqu%e dmica
 
Government resources
Government resourcesGovernment resources
Government resources
 

More from Bilal Ahmed

CS201- Introduction to Programming- Lecture 43
CS201- Introduction to Programming- Lecture 43CS201- Introduction to Programming- Lecture 43
CS201- Introduction to Programming- Lecture 43Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 35
CS201- Introduction to Programming- Lecture 35CS201- Introduction to Programming- Lecture 35
CS201- Introduction to Programming- Lecture 35Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 24
CS201- Introduction to Programming- Lecture 24CS201- Introduction to Programming- Lecture 24
CS201- Introduction to Programming- Lecture 24Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 22
CS201- Introduction to Programming- Lecture 22CS201- Introduction to Programming- Lecture 22
CS201- Introduction to Programming- Lecture 22Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 21
CS201- Introduction to Programming- Lecture 21CS201- Introduction to Programming- Lecture 21
CS201- Introduction to Programming- Lecture 21Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 19
CS201- Introduction to Programming- Lecture 19CS201- Introduction to Programming- Lecture 19
CS201- Introduction to Programming- Lecture 19Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 17
CS201- Introduction to Programming- Lecture 17CS201- Introduction to Programming- Lecture 17
CS201- Introduction to Programming- Lecture 17Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 16
CS201- Introduction to Programming- Lecture 16CS201- Introduction to Programming- Lecture 16
CS201- Introduction to Programming- Lecture 16Bilal Ahmed
 

More from Bilal Ahmed (8)

CS201- Introduction to Programming- Lecture 43
CS201- Introduction to Programming- Lecture 43CS201- Introduction to Programming- Lecture 43
CS201- Introduction to Programming- Lecture 43
 
CS201- Introduction to Programming- Lecture 35
CS201- Introduction to Programming- Lecture 35CS201- Introduction to Programming- Lecture 35
CS201- Introduction to Programming- Lecture 35
 
CS201- Introduction to Programming- Lecture 24
CS201- Introduction to Programming- Lecture 24CS201- Introduction to Programming- Lecture 24
CS201- Introduction to Programming- Lecture 24
 
CS201- Introduction to Programming- Lecture 22
CS201- Introduction to Programming- Lecture 22CS201- Introduction to Programming- Lecture 22
CS201- Introduction to Programming- Lecture 22
 
CS201- Introduction to Programming- Lecture 21
CS201- Introduction to Programming- Lecture 21CS201- Introduction to Programming- Lecture 21
CS201- Introduction to Programming- Lecture 21
 
CS201- Introduction to Programming- Lecture 19
CS201- Introduction to Programming- Lecture 19CS201- Introduction to Programming- Lecture 19
CS201- Introduction to Programming- Lecture 19
 
CS201- Introduction to Programming- Lecture 17
CS201- Introduction to Programming- Lecture 17CS201- Introduction to Programming- Lecture 17
CS201- Introduction to Programming- Lecture 17
 
CS201- Introduction to Programming- Lecture 16
CS201- Introduction to Programming- Lecture 16CS201- Introduction to Programming- Lecture 16
CS201- Introduction to Programming- Lecture 16
 

Recently uploaded

Tekoäly ja oppiminen. Airut-hanke 23.4.24
Tekoäly ja oppiminen. Airut-hanke 23.4.24Tekoäly ja oppiminen. Airut-hanke 23.4.24
Tekoäly ja oppiminen. Airut-hanke 23.4.24Matleena Laakso
 
Valkohäntäpeura (Odocoileus virginianus).pptx
Valkohäntäpeura (Odocoileus virginianus).pptxValkohäntäpeura (Odocoileus virginianus).pptx
Valkohäntäpeura (Odocoileus virginianus).pptxpurmonen8
 
Tekoäly opetuksessa. Seinäjoen lyseo 24.4.24
Tekoäly opetuksessa. Seinäjoen lyseo 24.4.24Tekoäly opetuksessa. Seinäjoen lyseo 24.4.24
Tekoäly opetuksessa. Seinäjoen lyseo 24.4.24Matleena Laakso
 
Opettaja ja tekoäly. Pedaiiltapäivä 25.4.24
Opettaja ja tekoäly. Pedaiiltapäivä 25.4.24Opettaja ja tekoäly. Pedaiiltapäivä 25.4.24
Opettaja ja tekoäly. Pedaiiltapäivä 25.4.24Matleena Laakso
 
Avoimen jakamisen ylistys, ITK 19.4.2024
Avoimen jakamisen ylistys, ITK 19.4.2024Avoimen jakamisen ylistys, ITK 19.4.2024
Avoimen jakamisen ylistys, ITK 19.4.2024Matleena Laakso
 
Tekoäly ja opinto-ohjaus, webinaari 26.4.24
Tekoäly ja opinto-ohjaus, webinaari 26.4.24Tekoäly ja opinto-ohjaus, webinaari 26.4.24
Tekoäly ja opinto-ohjaus, webinaari 26.4.24Matleena Laakso
 

Recently uploaded (6)

Tekoäly ja oppiminen. Airut-hanke 23.4.24
Tekoäly ja oppiminen. Airut-hanke 23.4.24Tekoäly ja oppiminen. Airut-hanke 23.4.24
Tekoäly ja oppiminen. Airut-hanke 23.4.24
 
Valkohäntäpeura (Odocoileus virginianus).pptx
Valkohäntäpeura (Odocoileus virginianus).pptxValkohäntäpeura (Odocoileus virginianus).pptx
Valkohäntäpeura (Odocoileus virginianus).pptx
 
Tekoäly opetuksessa. Seinäjoen lyseo 24.4.24
Tekoäly opetuksessa. Seinäjoen lyseo 24.4.24Tekoäly opetuksessa. Seinäjoen lyseo 24.4.24
Tekoäly opetuksessa. Seinäjoen lyseo 24.4.24
 
Opettaja ja tekoäly. Pedaiiltapäivä 25.4.24
Opettaja ja tekoäly. Pedaiiltapäivä 25.4.24Opettaja ja tekoäly. Pedaiiltapäivä 25.4.24
Opettaja ja tekoäly. Pedaiiltapäivä 25.4.24
 
Avoimen jakamisen ylistys, ITK 19.4.2024
Avoimen jakamisen ylistys, ITK 19.4.2024Avoimen jakamisen ylistys, ITK 19.4.2024
Avoimen jakamisen ylistys, ITK 19.4.2024
 
Tekoäly ja opinto-ohjaus, webinaari 26.4.24
Tekoäly ja opinto-ohjaus, webinaari 26.4.24Tekoäly ja opinto-ohjaus, webinaari 26.4.24
Tekoäly ja opinto-ohjaus, webinaari 26.4.24
 

CS201- Introduction to Programming- Lecture 09

  • 2. PPrrooggrraammmmiinngg TToooollkkiitt  DDeecciissiioonnss  LLooooppss  SSeeqquueenncceess
  • 5. Constructing aa llaabboorraattoorryy SSttooooll  TTaasskk:: MMaakkiinngg aa ssttooooll – SSuubbttaasskk::  MMaakkee aa sseeaatt  MMaakkee lleeggss ffoorr tthhee ssttooooll  AAsssseemmbbllee tthheemm
  • 6. WWhhaatt wwee wwiillll ssttuuddyy ttooddaayy ……  What aarree ffuunnccttiioonnss??  HHooww aarree tthheeyy ddeeffiinneedd ??  HHooww aarree tthheeyy ddeeccllaarreedd ??  WWhhaatt vvaalluueess aarree ppaasssseedd ttoo ffuunnccttiioonnss ??  WWhhaatt vvaalluueess ddoo ffuunnccttiioonnss rreettuurrnn ??
  • 7. FFuunnccttiioonn FFuunnccttiioonn nnaammee {{ BBooddyy ooff tthhee ffuunnccttiioonn }}
  • 8. FFuunnccttiioonn TTwwoo ttyyppeess ooff ffuunnccttiioonnss:: 11.. FFuunnccttiioonnss tthhaatt rreettuurrnn aa vvaalluuee 22.. FFuunnccttiioonnss tthhaatt ddoo nnoott rreettuurrnn aa vvaalluuee
  • 9. Function return-value-type function-name( aarrgguummeenntt--lliisstt )) {{ ddeeccllaarraattiioonnss aanndd ssttaatteemmeennttss }}
  • 10. Declaration of Function return-value-type function-name( aarrgguummeenntt----ttyyppee--lliisstt)) ;; mmaaiinn (( )) {{ :: }}
  • 11. EExxaammppllee iinntt ffuunnccttiioonn--nnaammee (( iinntt ,, iinntt ,, ddoouubbllee )) ;; vvooiidd mmaaiinn (( )) {{ …….. }}
  • 12. iinntt ffuunnccttiioonn--nnaammee (( iinntt ii ,, ddoouubbllee jj )) {{ …… }} Definition of Function
  • 13. Return Type of Function iinntt ssqquuaarree (( iinntt )) ;; iinntt ssqquuaarree (( iinntt ii )) {{ rreettuurrnn (( ii ** ii )) ;; }} Declaration Definition
  • 14. Function Call iinntt xx ;; xx == ssqquuaarree (( ii )) ;;
  • 15. Example: Function to calculate double raiseToPow ( double xx ,, iinntt ppoowweerr )) {{ ddoouubbllee rreessuulltt ;; iinntt ii ;; rreessuulltt == 11..00 ;; ffoorr (( ii == 11 ;; ii <<== ppoowweerr ;; ii ++++ )) //// bbrraacceess ffiirrsstt {{ rreessuulltt ** == xx ;; //// rreessuulltt == rreessuulltt **xx }} rreettuurrnn (( rreessuulltt )) ;; }} integer power ( Xn )
  • 16. include << iioossttrreeaamm..hh >> vvooiidd mmaaiinn (( )) {{ ddoouubbllee xx ;; iinntt ii ;; ccoouutt <<<< ““ PPlleeaassee eenntteerr tthhee nnuummbbeerr ““ ;; cciinn >>>> xx ;; ccoouutt <<<< ““ PPlleeaassee eenntteerr tthhee iinntteeggeerr ppoowweerr tthhaatt yyoouu wwaanntt tthhiiss nnuummbbeerr rraaiisseedd ttoo ““ cciinn >>>> ii ;; ccoouutt <<<< xx <<<< ““ rraaiissee ttoo ppoowweerr ““ <<<< ii <<<< ““iiss eeqquuaall ttoo ““ <<<< rraaiisseeTTooPPooww (( xx ,, ii )) ;; }} Code to Call the raisetopow Function
  • 19. AArreeaa ooff tthhee RRiinngg Inner Circle Outer Circle Area of Outer Circle ____ Area of Inner Circle = Area of the Ring
  • 20. Example: Function to calculate the area of a circle double cciirrcclleeAArreeaa (( ddoouubbllee rraaddiiuuss )) {{ rreettuurrnn (( 33..11441155992266 ** rraaddiiuuss ** rraaddiiuuss )) ;; }}
  • 21. Calculating ringArea without mmaaiinn (( )) {{ using Function :: rriinnggAArreeaa == (( 33..11441155992266 ** rraadd11 ** rraadd11 )) –– (( 33..11441155992266 ** rraadd22 ** rraadd22 )) ;; }}
  • 22. EExxeerrcciisseess 11.. MMooddiiffyy tthhee rraaiissee ttoo ppoowweerr ffuunnccttiioonn ssoo tthhaatt iitt ccaann hhaannddllee nneeggaattiivvee ppoowweerr ooff xx,, zzeerroo aanndd ppoossiittiivvee ppoowweerr ooff xx.. 22.. FFoorr tthhee aarreeaa ooff rriinngg ffuunnccttiioonn ppuutt iinn eerrrroorr cchheecckkiinngg mmeecchhaanniissmm..
  • 23. IInn ttooddaayy’’ss lleeccttuurree  We used functions for breaking ccoommpplleexx pprroobblleemmss iinnttoo ssmmaalllleerr ppiieecceess,, wwhhiicchh iiss aa ttoopp--ddoowwnn ssttrruuccttuurreedd aapppprrooaacchh..  EEaacchh ffuunnccttiioonn sshhoouulldd bbee aa ssmmaallll mmoodduullee,, sseellff ccoonnttaaiinneedd aanndd iitt sshhoouulldd ssoollvvee aa wweellll ddeeffiinneedd pprroobblleemm..  VVaarriiaabbllee nnaammeess aanndd ffuunnccttiioonn nnaammeess sshhoouulldd bbee sseellff eexxppllaannaattoorryy..  AAllwwaayyss ccoommmmeenntt yyoouurr ccooddee