SlideShare a Scribd company logo
Introduction ttoo PPrrooggrraammmmiinngg 
LLeeccttuurree 3377
OOppeerraattoorr 
OOvveerrllooaaddiinngg
OOppeerraattoorr OOvveerrllooaaddiinngg 
Stream IInnsseerrttiioonn // 
EExxttrraaccttiioonn
iinntt ii ;; 
cciinn >>>> ii ;;
iinntt aa ,, bb ,, cc ;; 
aa ++ bb ++ cc ;;
cciinn >>>> ii >>>> jj ;;
FFrriieenndd 
FFuunnccttiioonn
MMeemmbbeerr 
OOppeerraattoorr 
ss
OObbjjeecctt..ddaattaa 
OObbjjeecctt..ffuunnccttiioonn (( ))
Stream IInnsseerrttiioonn OOppeerraattoorr
int i = 5 , jj == 1100 ,, kk == 1155 ;; 
ccoouutt <<<< ii <<<< jj <<<< kk ;;
Return type: 
Reference to the output stream 
ostream & operator << ( ostream & output ,, vveehhiiccllee AA )) 
Reference to the output 
stream 
Object of the 
class 
Operator 
}}
Definition 
ostream & operator << (( oossttrreeaamm && oouuttppuutt ,, vveehhiiccllee dd )) 
{{ 
oouuttppuutt<<<< dd..sseeaattss ;; 
oouuttppuutt<<<<dd..ttiirreess ;; 
-------------- 
rreettuurrnn oouuttppuutt ;; 
}}
ccoouutt <<<< dd ;;
cout << “The description of the vehicle iiss nn”” <<<< dd ;;
EExxaammppllee 
ccllaassss MMaattrriixx 
{{ 
pprriivvaattee :: 
iinntt rroowwss ,, ccoollss ;; 
iinntt eelleemmeennttss [[ 33 ]] [[ 33 ]] ;; 
ppuubblliicc :: 
MMaattrriixx (( iinntt rroowwss == 33 ,, iinntt ccoollss == 33 )) ;; 
ffrriieenndd oossttrreeaamm && ooppeerraattoorr <<<< (( oossttrreeaamm && oouuttppuutt ,, MMaattrriixx mm )) ;; 
}} ;;
EExxaammppllee 
oossttrreeaamm&& ooppeerraattoorr <<<< (( oossttrreeaamm && oouuttppuutt ,, MMaattrriixx mm )) 
{{ 
ffoorr (( iinntt ii == 00 ;; ii << mm..rroowwss ;; ii ++++ )) 
{{ 
ffoorr (( iinntt jj == 00 ;; jj << mm..ccoollss ;; jj ++++ )) 
{{ 
oouuttppuutt <<<< mm..eelleemmeennttss [[ ii ]] [[ jj ]] ;; 
}} 
}} 
rreettuurrnn oouuttppuutt ;; 
}}
iinntt ii ;; 
cciinn >>>> ii ;;
MMaattrriixx xx ;; 
cciinn >>>> xx ;;
EExxaammppllee 
ccllaassss MMaattrriixx 
{{ 
pprriivvaattee :: 
iinntt rroowwss,, ccoollss ;; 
iinntt eelleemmeennttss [[ 33 ]] [[ 33 ]] ;; 
ppuubblliicc :: 
MMaattrriixx (( iinntt rroowwss == 33 ,, iinntt ccoollss == 33 )) ;; 
ffrriieenndd oossttrreeaamm && ooppeerraattoorr <<<< (( oossttrreeaamm && oouuttppuutt ,, MMaattrriixx mm )) ffrriieenndd iissttrreeaamm && ooppeerraattoorr >>>> (( iissttrreeaamm && iinnppuutt ,, MMaattrriixx mm )) ;; 
}};;
EExxaammppllee 
iissttrreeaamm && ooppeerraattoorr >>>> (( iissttrreeaamm && iinnppuutt ,, MMaattrriixx && mm )) 
{{ 
ccoouutt<<<< ““PPlleeaassee eenntteerr tthhee vvaalluueess ooff tthhee mmaattrriixx”” ;; 
ffoorr (( iinntt ii == 00 ;; ii << mm..rroowwss ;; ii ++++ )) 
{{ 
ffoorr (( iinntt jj == 00 ;; jj << mm..ccoollss ;; jj ++++ )) 
{{ 
ccoouutt <<<< ““PPlleeaassee eenntteerr tthhee vvaalluueess ooff eelleemmeennttss ”” <<<< ii <<<< ““,,”” <<<< jj ;; 
iinnppuutt >>>> mm..eelleemmeennttss [[ ii ]] [[ jj ]] ;; 
}} 
}} 
rreettuurrnn iinnppuutt;; 
}}
EExxaammppllee 
MMaattrriixx mm ;; 
mm..ggeettMMaattrriixx (( )) ;; 
mm..ddiissppllaayyMMaattrriixx (( )) ;;
EExxaammppllee 
MMaattrriixx mm ;; 
cciinn >>>> mm ;; 
ccoouutt <<<< mm ;;

More Related Content

PPT
CS201- Introduction to Programming- Lecture 36
PPT
CS201- Introduction to Programming- Lecture 07
PPT
CS201- Introduction to Programming- Lecture 30
PPT
CS201- Introduction to Programming- Lecture 13
PPT
CS201- Introduction to Programming- Lecture 33
PPT
CS201- Introduction to Programming- Lecture 15
PPT
CS201- Introduction to Programming- Lecture 44
PPT
CS201- Introduction to Programming- Lecture 03
CS201- Introduction to Programming- Lecture 36
CS201- Introduction to Programming- Lecture 07
CS201- Introduction to Programming- Lecture 30
CS201- Introduction to Programming- Lecture 13
CS201- Introduction to Programming- Lecture 33
CS201- Introduction to Programming- Lecture 15
CS201- Introduction to Programming- Lecture 44
CS201- Introduction to Programming- Lecture 03

What's hot (20)

PPT
CS201- Introduction to Programming- Lecture 39
PPT
CS201- Introduction to Programming- Lecture 40
PPT
CS201- Introduction to Programming- Lecture 38
PPT
19 Algorithms and complexity
PPT
CS201- Introduction to Programming- Lecture 18
PPT
CS201- Introduction to Programming- Lecture 34
PPT
CS201- Introduction to Programming- Lecture 12
PPT
Tiro parabólico
PPT
CS201- Introduction to Programming- Lecture 26
PPT
CS201- Introduction to Programming- Lecture 09
PPT
CS201- Introduction to Programming- Lecture 29
PPT
CS201- Introduction to Programming- Lecture 19
PPT
Morphemes
PPT
CS201- Introduction to Programming- Lecture 45
PPT
CS201- Introduction to Programming- Lecture 20
PPT
La exploración del sistema solar
PPT
CS201- Introduction to Programming- Lecture 28
PPT
CS201- Introduction to Programming- Lecture 31
PPT
anatomy of the larynx
PPT
Termoquímica - Setor Leste
CS201- Introduction to Programming- Lecture 39
CS201- Introduction to Programming- Lecture 40
CS201- Introduction to Programming- Lecture 38
19 Algorithms and complexity
CS201- Introduction to Programming- Lecture 18
CS201- Introduction to Programming- Lecture 34
CS201- Introduction to Programming- Lecture 12
Tiro parabólico
CS201- Introduction to Programming- Lecture 26
CS201- Introduction to Programming- Lecture 09
CS201- Introduction to Programming- Lecture 29
CS201- Introduction to Programming- Lecture 19
Morphemes
CS201- Introduction to Programming- Lecture 45
CS201- Introduction to Programming- Lecture 20
La exploración del sistema solar
CS201- Introduction to Programming- Lecture 28
CS201- Introduction to Programming- Lecture 31
anatomy of the larynx
Termoquímica - Setor Leste
Ad

Viewers also liked (20)

PPS
CS101- Introduction to Computing- Lecture 45
PPS
CS101- Introduction to Computing- Lecture 28
PPS
CS101- Introduction to Computing- Lecture 27
PPT
MGT101 - Financial Accounting- Lecture 28
PPT
CS201- Introduction to Programming- Lecture 27
PPS
ENG101- English Comprehension- Lecture 23
DOC
MTH101 - Calculus and Analytical Geometry- Lecture 41
PPS
CS101- Introduction to Computing- Lecture 23
PPS
ENG101- English Comprehension- Lecture 36
PPS
CS101- Introduction to Computing- Lecture 37
DOC
MTH101 - Calculus and Analytical Geometry- Lecture 44
PPS
CS101- Introduction to Computing- Lecture 44
PPT
MGT101 - Financial Accounting- Lecture 40
PPT
MGT101 - Financial Accounting- Lecture 45
PPS
CS101- Introduction to Computing- Lecture 31
PPT
CS201- Introduction to Programming- Lecture 43
PPT
CS201- Introduction to Programming- Lecture 06
PPT
CS201- Introduction to Programming- Lecture 11
PPT
CS201- Introduction to Programming- Lecture 08
PPT
CS201- Introduction to Programming- Lecture 10
CS101- Introduction to Computing- Lecture 45
CS101- Introduction to Computing- Lecture 28
CS101- Introduction to Computing- Lecture 27
MGT101 - Financial Accounting- Lecture 28
CS201- Introduction to Programming- Lecture 27
ENG101- English Comprehension- Lecture 23
MTH101 - Calculus and Analytical Geometry- Lecture 41
CS101- Introduction to Computing- Lecture 23
ENG101- English Comprehension- Lecture 36
CS101- Introduction to Computing- Lecture 37
MTH101 - Calculus and Analytical Geometry- Lecture 44
CS101- Introduction to Computing- Lecture 44
MGT101 - Financial Accounting- Lecture 40
MGT101 - Financial Accounting- Lecture 45
CS101- Introduction to Computing- Lecture 31
CS201- Introduction to Programming- Lecture 43
CS201- Introduction to Programming- Lecture 06
CS201- Introduction to Programming- Lecture 11
CS201- Introduction to Programming- Lecture 08
CS201- Introduction to Programming- Lecture 10
Ad

Similar to CS201- Introduction to Programming- Lecture 37 (13)

PPT
CS201- Introduction to Programming- Lecture 35
PPT
CS201- Introduction to Programming- Lecture 23
PPT
21 High-quality programming code construction part-ii
PPT
CS201- Introduction to Programming- Lecture 14
DOCX
DOCX
Resume Jignesh 2010
PDF
Contrarrazoes ro vinculo empregaticio reclamada ilovepdf-compressed
PPT
CS201- Introduction to Programming- Lecture 41
PPT
Design of the South Doña Ana Dam
PPT
CS201- Introduction to Programming- Lecture 32
PPT
Industrialisasi Media
PDF
TOP Downloaded Papers (January)--International Journal of Computer Networks &...
CS201- Introduction to Programming- Lecture 35
CS201- Introduction to Programming- Lecture 23
21 High-quality programming code construction part-ii
CS201- Introduction to Programming- Lecture 14
Resume Jignesh 2010
Contrarrazoes ro vinculo empregaticio reclamada ilovepdf-compressed
CS201- Introduction to Programming- Lecture 41
Design of the South Doña Ana Dam
CS201- Introduction to Programming- Lecture 32
Industrialisasi Media
TOP Downloaded Papers (January)--International Journal of Computer Networks &...

More from Bilal Ahmed (7)

PPT
CS201- Introduction to Programming- Lecture 42
PPT
CS201- Introduction to Programming- Lecture 25
PPT
CS201- Introduction to Programming- Lecture 24
PPT
CS201- Introduction to Programming- Lecture 22
PPT
CS201- Introduction to Programming- Lecture 21
PPT
CS201- Introduction to Programming- Lecture 17
PPT
CS201- Introduction to Programming- Lecture 16
CS201- Introduction to Programming- Lecture 42
CS201- Introduction to Programming- Lecture 25
CS201- Introduction to Programming- Lecture 24
CS201- Introduction to Programming- Lecture 22
CS201- Introduction to Programming- Lecture 21
CS201- Introduction to Programming- Lecture 17
CS201- Introduction to Programming- Lecture 16

CS201- Introduction to Programming- Lecture 37