SlideShare a Scribd company logo
Introduction ttoo PPrrooggrraammmmiinngg 
LLeeccttuurree 2299
PPrriivvaattee 
PPuubblliicc
EEnnccaappssuullaattiioonn 
Data Hiding
FFrriieenndd 
Friend Function
FFrriieenndd 
FFuunnccttiioonn ccllaassss DDaattee 
{{ 
---- 
ffrriieenndd ffuunnccttiioonnNNaammee (( AArrgguummeenntt__lliisstt )) ;; 
---- 
}} ;;
FFrriieenndd 
FFuunnccttiioonn  FFrriieenndd ffuunnccttiioonnss aarree NNOOTT tthhee mmeemmbbeerrss ooff 
tthhee ccllaassss 
 TThhee ccllaassss iittsseellff ddeeccllaarree iitt’’ss ffrriieenndd 
ffuunnccttiioonnss 
 TThhee pprroottoottyyppee ooff tthheessee ffuunnccttiioonnss aarree 
wwrriitttteenn iinnssiiddee tthhee ccllaassss aanndd tthhee kkeeyy wwoorrdd 
ffrriieenndd iiss aappppeennddeedd bbeeffoorree tthhee ffuunnccttiioonn 
nnaammee 
 FFrriieenndd ffuunnccttiioonnss hhaavvee aacccceessss ttoo pprriivvaattee 
aanndd ppuubblliicc mmeemmbbeerrss ooff tthhee ccllaassss
EExxaammppllee 11 
ccllaassss mmyyCCllaassss 
{{ 
ffrriieenndd iinnccrreemmeenntt (( mmyyCCllaassss ,, iinntt )) ;; 
pprriivvaattee:: 
iinntt ttooppSSeeccrreett ;; 
ppuubblliicc:: 
mmyyCCllaassss (( )) 
{{ ttooppSSeeccrreett == 110000 ;; }} 
vvooiidd DDiissppllaayy (( )) 
{{ ccoouutt<<<< ““TThhee vvaalluuee ooff ttooppSSeeccrreett iiss ““ 
<<<< ttooppSSeeccrreett ;; }} 
}} ;;
EExxaammppllee 11 
vvooiidd IInnccrreemmeenntt (( mmyyCCllaassss AA ,, iinntt ii )) 
{{ 
AA..ttooppSSeeccrreett ++== ii ;; 
}}
EExxaammppllee 11 
mmaaiinn (( )) 
{{ 
mmyyCCllaassss xx ;; 
xx..DDiissppllaayy (( )) ;; 
IInnccrreemmeenntt (( xx ,, 1100 )) ;; 
xx..DDiissppllaayy (( )) ;; 
}}
EExxaammppllee 11:: OOuuttppuutt 
TThhee vvaalluuee ooff ttooppSSeeccrreett iiss 110000 
TThhee vvaalluuee ooff ttooppSSeeccrreett iiss 111100
EExxaammppllee 22 
ccllaassss mmyyCCllaassssTTwwoo ;; 
ccllaassss mmyyCCllaassssOOnnee 
{{ 
pprriivvaattee :: 
iinntt ttooppSSeeccrreett ;; 
ppuubblliicc :: 
vvooiidd DDiissppllaayy (( )) ;; 
mmyyCCllaassssOOnnee (( )) 
{{ ttooppSSeeccrreett == 110000;; }} 
ffrriieenndd AAddddBBootthh (( mmyyCCllaassssOOnnee ,, mmyyCCllaassssTTwwoo )) ;; 
}} ;;
EExxaammppllee 22 
ccllaassss mmyyCCllaassssTTwwoo 
{{ 
pprriivvaattee:: 
iinntt ttooppSSeeccrreett ;; 
ppuubblliicc:: 
vvooiidd DDiissppllaayy (( )) ;; 
mmyyCCllaassssTTwwoo (( )) 
{{ ttooppSSeeccrreett == 220000 ;; }} 
ffrriieenndd AAddddBBootthh (( mmyyCCllaassssOOnnee ,, mmyyCCllaassssTTwwoo )) ;; 
}} ;;
EExxaammppllee 22 
mmaaiinn (( )) 
{{ 
mmyyCCllaassssOOnnee AA ;; 
mmyyCCllaassssTTwwoo BB ;; 
AA..DDiissppllaayy (( )) ;; 
BB..DDiissppllaayy (( )) ;; 
AAddddBBootthh (( AA ,, BB )) ;; 
}}
EExxaammppllee 22 
iinntt AAddddBBootthh (( mmyyCCllaassssOOnnee AA ,, mmyyCCllaassssTTwwoo BB )) 
{{ 
ccoouutt <<<< ““TThhee vvaalluuee ooff ttooppSSeeccrreett iinn mmyyCCllaassssOOnnee oobbjjeecctt 
iiss”” <<<< AA..ttooppSSeeccrreett ;; 
ccoouutt <<<< ““TThhee vvaalluuee ooff ttooppSSeeccrreett iinn mmyyCCllaassssTTwwoo oobbjjeecctt 
iiss””<<<< BB..ttooppSSeeccrreett ;; 
ccoouutt <<<< ““TThhee ssuumm ooff ttooppSSeeccrreett vvaalluueess iinn ““ 
<<<< ““mmyyCCllaassssOOnnee aanndd mmyyCCllaassssTTwwoo oobbjjeecctt iiss ”” 
<<<< AA..ttooppSSeeccrreett ++ BB..ttooppSSeeccrreett ;; 
}}
EExxaammppllee 33 
ccllaassss ootthheerrCCllaassss ;; 
ccllaassss ccllaassssOOnnee 
{{ 
pprriivvaattee :: 
iinntt ttooppSSeeccrreett;; 
ppuubblliicc :: 
vvooiidd DDiissppllaayy (( )) ;; 
ccllaassssOOnnee (( )) 
{{ TTooppSSeeccrreett == 110000 ;; }} 
ffrriieenndd ootthheerrCCllaassss ;; 
}} ;;
SSttrraaiigghhtt LLiinnee 
yy == mmxx ++ cc 
Slope Intercept 
on y axis
SSttrraaiigghhtt LLiinnee 
ccllaassss ssttrraaiigghhttLLiinnee 
{{ 
ddoouubbllee ssllooppee ,, iinntteerrcceepptt ;; 
//// mmeemmbbeerr ffuunnccttiioonn 
}} ;;
QQuuaaddrraattiicc 
yy == aaxx22 ++bbxx ++ cc
QQuuaaddrraattiicc 
ccllaassss qquuaaddrraattiicc 
{{ 
pprriivvaattee :: 
ddoouubbllee aa ,, bb ,, cc ;; 
//// mmeemmbbeerr ffuunnccttiioonn 
}} ;;
LLiimmiittaattiioonnss 
IItt iiss NNOOTT TTrraannssiittiivvee 
IItt iiss NNOOTT 
AAssssoocciiaattiivvee

More Related Content

PPT
CS201- Introduction to Programming- Lecture 09
PPT
CS201- Introduction to Programming- Lecture 26
PPT
CS201- Introduction to Programming- Lecture 30
PPT
CS201- Introduction to Programming- Lecture 32
PPT
CS201- Introduction to Programming- Lecture 39
PPT
CS201- Introduction to Programming- Lecture 03
PPT
Tiro parabólico
PDF
Workshop vermicompostagem
CS201- Introduction to Programming- Lecture 09
CS201- Introduction to Programming- Lecture 26
CS201- Introduction to Programming- Lecture 30
CS201- Introduction to Programming- Lecture 32
CS201- Introduction to Programming- Lecture 39
CS201- Introduction to Programming- Lecture 03
Tiro parabólico
Workshop vermicompostagem

What's hot (19)

PPT
CS201- Introduction to Programming- Lecture 07
PPT
CS201- Introduction to Programming- Lecture 23
PPT
CS201- Introduction to Programming- Lecture 10
PPT
Comparative and superlative adjectives
PPT
Comparative and superlative adjectives
PPT
Rational zero of polynomial function
PPT
CS201- Introduction to Programming- Lecture 28
PPT
CS201- Introduction to Programming- Lecture 37
PPT
CS201- Introduction to Programming- Lecture 15
PPT
CS201- Introduction to Programming- Lecture 27
PPT
CS201- Introduction to Programming- Lecture 42
PPT
Perangkat Keras Hardware
PPT
Hardware
PPT
pengenalan perangkat keras komputer
PPT
Perangkat keras komputer
PPT
CS201- Introduction to Programming- Lecture 40
PPT
CS201- Introduction to Programming- Lecture 25
PPT
Replace your lawn sprinkler controller
PPT
CS201- Introduction to Programming- Lecture 31
CS201- Introduction to Programming- Lecture 07
CS201- Introduction to Programming- Lecture 23
CS201- Introduction to Programming- Lecture 10
Comparative and superlative adjectives
Comparative and superlative adjectives
Rational zero of polynomial function
CS201- Introduction to Programming- Lecture 28
CS201- Introduction to Programming- Lecture 37
CS201- Introduction to Programming- Lecture 15
CS201- Introduction to Programming- Lecture 27
CS201- Introduction to Programming- Lecture 42
Perangkat Keras Hardware
Hardware
pengenalan perangkat keras komputer
Perangkat keras komputer
CS201- Introduction to Programming- Lecture 40
CS201- Introduction to Programming- Lecture 25
Replace your lawn sprinkler controller
CS201- Introduction to Programming- Lecture 31
Ad

Viewers also liked (20)

PDF
Yehai catalogue -tracy chow
PPT
Wall quote vinyl decal
DOCX
Bab i, ii, iii
PPT
CS201- Introduction to Programming- Lecture 05
DOCX
Shi pemahaman hukum islam
PPTX
Professionaliseer uw technische dienst en facility management
DOC
Mtm terbaru 02 06-2014 (2)
DOCX
Untuk presentasi
PPT
CS201- Introduction to Programming- Lecture 20
PDF
Kid’s party decorations ideas
PPTX
Kids Party Decoration Supplies Online
DOCX
Poto copian pemahaman studi hukum islam
PPS
ENG101- English Comprehension- Lecture 31
DOCX
Studi hukum islam
PPT
CS201- Introduction to Programming- Lecture 13
PDF
Aml catalogue 13
PDF
Aga power softcase catalog
DOCX
PPT
MGT101 - Financial Accounting- Lecture 37
PPTX
Botón de mano y volante de mano
Yehai catalogue -tracy chow
Wall quote vinyl decal
Bab i, ii, iii
CS201- Introduction to Programming- Lecture 05
Shi pemahaman hukum islam
Professionaliseer uw technische dienst en facility management
Mtm terbaru 02 06-2014 (2)
Untuk presentasi
CS201- Introduction to Programming- Lecture 20
Kid’s party decorations ideas
Kids Party Decoration Supplies Online
Poto copian pemahaman studi hukum islam
ENG101- English Comprehension- Lecture 31
Studi hukum islam
CS201- Introduction to Programming- Lecture 13
Aml catalogue 13
Aga power softcase catalog
MGT101 - Financial Accounting- Lecture 37
Botón de mano y volante de mano
Ad

Similar to CS201- Introduction to Programming- Lecture 29 (20)

PPT
CS201- Introduction to Programming- Lecture 38
PPT
CS201- Introduction to Programming- Lecture 22
PPT
Industrialisasi Media
PDF
Rajeev Sharma Resume 2017
PPT
Hardware
PPT
MODUL 1 - PERANGKAT KERAS
PPT
CS201- Introduction to Programming- Lecture 24
PPT
Strategies for representing whistleblowers in the federal government
PPT
CS201- Introduction to Programming- Lecture 35
PPT
CS201- Introduction to Programming- Lecture 44
PDF
Hafitz_Rizki 201343500823 Java_dan_Database_Mysql
PPT
Detectia prezentei Salmonella spp prin real time PCR
DOCX
PPT
Software engineering
PPT
CS201- Introduction to Programming- Lecture 08
PPT
Fluid & electrolytes & acid base
PPT
CS201- Introduction to Programming- Lecture 33
PPT
Osteo osteomalacia ricket2
PPT
Derivados biologicos
PPT
Glaucoma
CS201- Introduction to Programming- Lecture 38
CS201- Introduction to Programming- Lecture 22
Industrialisasi Media
Rajeev Sharma Resume 2017
Hardware
MODUL 1 - PERANGKAT KERAS
CS201- Introduction to Programming- Lecture 24
Strategies for representing whistleblowers in the federal government
CS201- Introduction to Programming- Lecture 35
CS201- Introduction to Programming- Lecture 44
Hafitz_Rizki 201343500823 Java_dan_Database_Mysql
Detectia prezentei Salmonella spp prin real time PCR
Software engineering
CS201- Introduction to Programming- Lecture 08
Fluid & electrolytes & acid base
CS201- Introduction to Programming- Lecture 33
Osteo osteomalacia ricket2
Derivados biologicos
Glaucoma

More from Bilal Ahmed (10)

PPT
CS201- Introduction to Programming- Lecture 45
PPT
CS201- Introduction to Programming- Lecture 43
PPT
CS201- Introduction to Programming- Lecture 41
PPT
CS201- Introduction to Programming- Lecture 36
PPT
CS201- Introduction to Programming- Lecture 34
PPT
CS201- Introduction to Programming- Lecture 21
PPT
CS201- Introduction to Programming- Lecture 19
PPT
CS201- Introduction to Programming- Lecture 18
PPT
CS201- Introduction to Programming- Lecture 17
PPT
CS201- Introduction to Programming- Lecture 16
CS201- Introduction to Programming- Lecture 45
CS201- Introduction to Programming- Lecture 43
CS201- Introduction to Programming- Lecture 41
CS201- Introduction to Programming- Lecture 36
CS201- Introduction to Programming- Lecture 34
CS201- Introduction to Programming- Lecture 21
CS201- Introduction to Programming- Lecture 19
CS201- Introduction to Programming- Lecture 18
CS201- Introduction to Programming- Lecture 17
CS201- Introduction to Programming- Lecture 16

CS201- Introduction to Programming- Lecture 29

  • 5. FFrriieenndd FFuunnccttiioonn ccllaassss DDaattee {{ ---- ffrriieenndd ffuunnccttiioonnNNaammee (( AArrgguummeenntt__lliisstt )) ;; ---- }} ;;
  • 6. FFrriieenndd FFuunnccttiioonn  FFrriieenndd ffuunnccttiioonnss aarree NNOOTT tthhee mmeemmbbeerrss ooff tthhee ccllaassss  TThhee ccllaassss iittsseellff ddeeccllaarree iitt’’ss ffrriieenndd ffuunnccttiioonnss  TThhee pprroottoottyyppee ooff tthheessee ffuunnccttiioonnss aarree wwrriitttteenn iinnssiiddee tthhee ccllaassss aanndd tthhee kkeeyy wwoorrdd ffrriieenndd iiss aappppeennddeedd bbeeffoorree tthhee ffuunnccttiioonn nnaammee  FFrriieenndd ffuunnccttiioonnss hhaavvee aacccceessss ttoo pprriivvaattee aanndd ppuubblliicc mmeemmbbeerrss ooff tthhee ccllaassss
  • 7. EExxaammppllee 11 ccllaassss mmyyCCllaassss {{ ffrriieenndd iinnccrreemmeenntt (( mmyyCCllaassss ,, iinntt )) ;; pprriivvaattee:: iinntt ttooppSSeeccrreett ;; ppuubblliicc:: mmyyCCllaassss (( )) {{ ttooppSSeeccrreett == 110000 ;; }} vvooiidd DDiissppllaayy (( )) {{ ccoouutt<<<< ““TThhee vvaalluuee ooff ttooppSSeeccrreett iiss ““ <<<< ttooppSSeeccrreett ;; }} }} ;;
  • 8. EExxaammppllee 11 vvooiidd IInnccrreemmeenntt (( mmyyCCllaassss AA ,, iinntt ii )) {{ AA..ttooppSSeeccrreett ++== ii ;; }}
  • 9. EExxaammppllee 11 mmaaiinn (( )) {{ mmyyCCllaassss xx ;; xx..DDiissppllaayy (( )) ;; IInnccrreemmeenntt (( xx ,, 1100 )) ;; xx..DDiissppllaayy (( )) ;; }}
  • 10. EExxaammppllee 11:: OOuuttppuutt TThhee vvaalluuee ooff ttooppSSeeccrreett iiss 110000 TThhee vvaalluuee ooff ttooppSSeeccrreett iiss 111100
  • 11. EExxaammppllee 22 ccllaassss mmyyCCllaassssTTwwoo ;; ccllaassss mmyyCCllaassssOOnnee {{ pprriivvaattee :: iinntt ttooppSSeeccrreett ;; ppuubblliicc :: vvooiidd DDiissppllaayy (( )) ;; mmyyCCllaassssOOnnee (( )) {{ ttooppSSeeccrreett == 110000;; }} ffrriieenndd AAddddBBootthh (( mmyyCCllaassssOOnnee ,, mmyyCCllaassssTTwwoo )) ;; }} ;;
  • 12. EExxaammppllee 22 ccllaassss mmyyCCllaassssTTwwoo {{ pprriivvaattee:: iinntt ttooppSSeeccrreett ;; ppuubblliicc:: vvooiidd DDiissppllaayy (( )) ;; mmyyCCllaassssTTwwoo (( )) {{ ttooppSSeeccrreett == 220000 ;; }} ffrriieenndd AAddddBBootthh (( mmyyCCllaassssOOnnee ,, mmyyCCllaassssTTwwoo )) ;; }} ;;
  • 13. EExxaammppllee 22 mmaaiinn (( )) {{ mmyyCCllaassssOOnnee AA ;; mmyyCCllaassssTTwwoo BB ;; AA..DDiissppllaayy (( )) ;; BB..DDiissppllaayy (( )) ;; AAddddBBootthh (( AA ,, BB )) ;; }}
  • 14. EExxaammppllee 22 iinntt AAddddBBootthh (( mmyyCCllaassssOOnnee AA ,, mmyyCCllaassssTTwwoo BB )) {{ ccoouutt <<<< ““TThhee vvaalluuee ooff ttooppSSeeccrreett iinn mmyyCCllaassssOOnnee oobbjjeecctt iiss”” <<<< AA..ttooppSSeeccrreett ;; ccoouutt <<<< ““TThhee vvaalluuee ooff ttooppSSeeccrreett iinn mmyyCCllaassssTTwwoo oobbjjeecctt iiss””<<<< BB..ttooppSSeeccrreett ;; ccoouutt <<<< ““TThhee ssuumm ooff ttooppSSeeccrreett vvaalluueess iinn ““ <<<< ““mmyyCCllaassssOOnnee aanndd mmyyCCllaassssTTwwoo oobbjjeecctt iiss ”” <<<< AA..ttooppSSeeccrreett ++ BB..ttooppSSeeccrreett ;; }}
  • 15. EExxaammppllee 33 ccllaassss ootthheerrCCllaassss ;; ccllaassss ccllaassssOOnnee {{ pprriivvaattee :: iinntt ttooppSSeeccrreett;; ppuubblliicc :: vvooiidd DDiissppllaayy (( )) ;; ccllaassssOOnnee (( )) {{ TTooppSSeeccrreett == 110000 ;; }} ffrriieenndd ootthheerrCCllaassss ;; }} ;;
  • 16. SSttrraaiigghhtt LLiinnee yy == mmxx ++ cc Slope Intercept on y axis
  • 17. SSttrraaiigghhtt LLiinnee ccllaassss ssttrraaiigghhttLLiinnee {{ ddoouubbllee ssllooppee ,, iinntteerrcceepptt ;; //// mmeemmbbeerr ffuunnccttiioonn }} ;;
  • 18. QQuuaaddrraattiicc yy == aaxx22 ++bbxx ++ cc
  • 19. QQuuaaddrraattiicc ccllaassss qquuaaddrraattiicc {{ pprriivvaattee :: ddoouubbllee aa ,, bb ,, cc ;; //// mmeemmbbeerr ffuunnccttiioonn }} ;;
  • 20. LLiimmiittaattiioonnss IItt iiss NNOOTT TTrraannssiittiivvee IItt iiss NNOOTT AAssssoocciiaattiivvee