cse-iii-object oriented programming with c++ [10cs36]-notes_2.pdf

188
+ + C h t i w g n i m m e r g o r P d e t n e i r O t c e j b O 6 3 S C 0 1 T I B J S , E S C f o . t p e D SYLLABUS T C E J B O D E T N E I R O P G N I M M A R G O R H T I W + + C m o C ( mn o to E S C & ) E S I t c e j b u S : e d o C 0 1C 6 3 S 5 2 : s k r a M . A . I u o H r W / s ek e : 4 0 3 0 : s r u o H m a x E l a t o T u o H rs : 2 5 0 0 1 : s k r a M m a x E P T R A – A U T I N 1 t c u d o r t n I ion: w e i v r e v O f o , + + C e l p m a S + + C , m a r g o r p t n e r e f f i D a t a d t o , s e p y p , s r o t a r e ex , s n o i s s e r p d n a , s t n e m e t a t s r r a as y d n a i r t s ngs, s r e t n i o p & d e n i f e d r e s u t s e p y n o i t c n u F , s t n e n o p m o C r ag t n e m u n i s s a p g, e n i l n i , s n o i t c n u f n o i t c n u f n i d a o l r e v o g, e v i s r u c e r s n o i t c n u f U T I N 2 s e s s a l C & s t c e j b O : I s s a l C , n o i t a c i f i c e p S s s a l C , s t c e j b O e p o c S n o i t u l o s e r , r o t a r e p o s s e c c A m , s r e b m e i f e D n g n i me b m er , s n o i t c n u f a t a D , g n i d i h t c u r t s n o C o , s r r o t c u r t s e D , s d e z i r e t e m a r a P , s r o t c u r t s n o c c i t a t S a t a d me e b m r, s Fn uc s n o i t U 3 T I N s e s s a l C & s t c e j b O : I I d n e i r F , s n o i t c n u f g n i s s a P s t c e j b o s a ar , s t n e m u g g n i n r u t e R , s t c e j b o r r A as y f o , s t c e j b o D c i m a n y , s t c e j b o s r e t n i o P o t , s t c e j b o o C py o cn , s r o t c u r t s e Gn c i r e s n o i t c n u f s n o i t a c i l p p A , s e s s a l c d n a r o t a r e p O g n i d a o l r e v o g n i s u s n o i t c n u f d n e i r f h c u s , + s a - e r p , - , t n e m e r c n i t s o p - , t n e m e r c n i ] [ i d a o l r e v o , . c t e ng , < < >>.

Upload: basil

Post on 09-Dec-2015

48 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmergorP detneirO tcejbO 63SC01

TIBJS,ESCfo.tpeD

SYLLABUS TCEJBO DETNEIRO P GNIMMARGOR HTIW ++C

moC( m no to ESC & )ESI

tcejbuS :edoC 01 C 63S 52 : skraM .A.I

uoH r W/s e ke : 40 30 :sruoH maxE

latoT uoH rs : 25 001 :skraM maxE

P TRA – A

U TIN 1

tcudortnI ion: weivrevO fo ,++C elpmaS ++C ,margorp tnereffiD atad

t o,sepy p ,srotare ex ,snoisserp dna ,stnemetats rra a sy dna irts ngs, sretniop &

denifedresu t sepy noitcnuF ,stnenopmoC ra g tnemu nissap g, enilni ,snoitcnuf

noitcnuf nidaolrevo g, evisrucer snoitcnuf

U TIN 2

sessalC & stcejbO – :I ssalC ,noitacificepS ssalC ,stcejbO epocS noituloser

,rotarepo sseccA m ,srebme ifeD n gni me bm er ,snoitcnuf ataD ,gnidih

tcurtsnoC o ,sr rotcurtseD ,s deziretemaraP ,srotcurtsnoc citatS atad me ebm r ,s

F nu c snoit

U 3 TIN

sessalC & stcejbO – :II dneirF ,snoitcnuf gnissaP stcejbo sa ar ,stnemug

gninruteR ,stcejbo rrA a sy fo ,stcejbo D cimany ,stcejbo sretnioP ot ,stcejbo

oC py oc n ,srotcurts eG n cire snoitcnuf snoitacilppA ,sessalc dna rotarepO

gnidaolrevo gnisu snoitcnuf dneirf hcus ,+ sa - erp, - ,tnemercni tsop - ,tnemercni ] [

idaolrevo ,.cte ng ,<< >>.

Page 2: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmergorP detneirO tcejbO 63SC01

TIBJS,ESCfo.tpeD

U TIN 4

nI h ecnatire – :I esaB ,ssalC ecnatirehnI dna detcetorp ,srebmem rP o detcet

ab se ssalc ,ecnatirehni I gnitirehn elpitlum ba es cla sess

PART – B

U TIN 5

nI h ecnatire – :II noC s ,srotcurt srotcurtseD and hnI e atir n ,ec ssaP ni g

p sretemara ot ab se ssalc ,srotcurtsnoc gnitnarG ac ec ,ss iV r ut al base lc a sess

U TIN 6

lautriV f ,snoitcnu myloP o :msihpr Vi lautr uf n ,noitc gnillaC a lautriV cnuf it no

t hguorh a esab cl ssa erefer n ,ec iV r laut etubirtta si ,detirehni lautriV uf nc it sno

era areih r ,lacihc Pure lautriv ,snoitcnuf tcartsbA ,sessalc gnisU lautriv ,snoitcnuf

E ra yl dna la nidnib et g.

U TIN 7

O/I metsyS ,scisaB eliF :0/I ++C maerts ,sessalc dettamroF I/ ,O O/I

m na i ,srotalup maertsf dna eht F eli cla ss e ,s F eli po re snoita

U TIN 8

noitpecxE ,gnildnaH TS L: Ex noitpec gnildnah ,slatnemadnuf Ex noitpec

gnildnah snoitpo TS L: nA ,weivrevo eniatnoc r ,s v ce ,srot .stsil

txeT :skooB

1. trebreH :tdlihcS ehT etelpmoC eR f nere ce +C + ht4 , ,noitidE ataT cM G war H ,lli

.3002

ecnerefeR :skooB

1. yelnatS B.L ,nnamppi eesoJ L :eroja ++C ht4 ,remirP ,noitidE nosraeP dE uca ,noit

.5002

2. ,letieD J luaP yevraH M :letieD ++C rof orP g ,sremmar nosraeP udE ac ,noit .9002

3. K R neV u ,lapog jaR k ramu Bu ,ayy T ivaR :raknahS M iretsa ng C+ .+

Page 3: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmergorP detneirO tcejbO 63SC01

TIBJS,ESCfo.tpeD

I DN EX

U TIN 1 udortnI c noit 1- 42 U TIN 2 ssalC es & bO j ce ts – I 52 - 43 U TIN 3 ssalC es & bO j ce ts – II 53 - 95 U TIN 4 natirehnI ce – I 06 - 76 U TIN 5 cnatirehnI es – II 86 - 58 U TIN 6 lautriV ,snoitcnuf P ylo m sihpro m 68 - 301 U TIN 7 metsyS O/I ,scisaB F 0/I eli 401 - 031 U TIN 8 noitpecxE dnaH l ,gni ST L 131 - 581

Page 4: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 1

I TINU

NOITCUDORTNI

derevoc scipoT

:noitcudortnI ,sepyt atad tnereffiD ,margorp ++C elpmaS ,++C fo weivrevO

sepyt denifed resu & sretniop ,sgnirts dna syarra ,stnemetats dna ,snoisserpxe ,srotarepo

noitcnuf enilni ,gnissap tnemugra ,stnenopmoC noitcnuF evisrucer ,gnidaolrevo noitcnuf ,s

snoitcnuf

TINU - yrammuS 1 taht saedi eht ,noitaerc sti evord taht secrof eht dnatsrednu ot si ++C dnatsrednu oT

retpahc sihT .C htiw snigeb ++C fo yrots eht ,suhT .stirehni ti ycagel eht dna ,ti depahs

vrevo na stneserp sti dna ,sesu sti ,snigiro sti ,egaugnal gnimmargorp C eht fo wei

tnatropmi na sedivorp retpahc siht ,C nopu tliub si ++C esuaceB .yhposolihp gniylrednu

sti dah ”++C ,++C sekam“ tahw fo hcuM .++C fo stoor eht no evitcepsrep lacirotsih

gnal C eht ni siseneg egau

Page 5: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 2

.1 ++C fo weivrevO

detnevni tsrif erew snoisnetxe ++C ehT .C fo noisrev dednapxe na sa nageb ++C .yesreJ weN ,lliH yarruM ni seirotarobaL lleB ta 9791 ni purtsuortS enrajB yb

,revewoH ".sessalC htiw C" egaugnal wen eht dellac yllaitini eH eht 3891 ni ylediw dna dekil tsom eht fo eno saw C hguohtlA .++C ot degnahc saw eman ++C fo noitnevni eht ,dlrow eht ni segaugnal gnimmargorp lanoisseforp desu

.ytixelpmoc gnisaercni :rotcaf gnimmargorp rojam eno yb detatissecen saw

.2 margorp ++C elpmaS

A margorP ++C elpmaS .ereh nwohs margorp ++C elpmas trohs eht htiw trats s'teL

>maertsoi< edulcni# )(niam tni

{ ;i tni

.tuptuo si sihT" << tuoc \ tnemmoc enil elgnis a si siht // ;"n /* stnemmoc elyts C esu llits nac uoy */

>> gnisu rebmun a tupni // << tuoc ;" :rebmun a retnE" ;i >> nic

<< gnisu rebmun a tuptuo ,won // " << i*i << " si derauqs " << i << tuoc \ ;"n

;0 nruter } .3 sepyt atad tnereffiD

Page 6: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 3

.4 ,stnemetats dna ,snoisserpxe ,srotarepO

++C/C si r ci h in tliub -in srotarepo . nI ,tcaf ti secalp om re cnacifingis e no arepo rot s naht od tsom rehto retupmoc segaugnal . erehT era ruof niam

sessalc fo :srotarepo ,citemhtira re tal i ano l, acigol l, na d ib twise. In noitidda , eht re a er mos e aiceps l rotarepo s of r ralucitrap .sksat

ehT 1.4 tnemngissA rotarepO

uoY nac esu eht tnemngissa rotarepo nihtiw yna dilav noisserpxe . sihT si ton eht esac htiw ynam retupmoc segaugnal gnidulcni( ,lacsaP ,CISAB dna

,)NARTROF hcihw taert eht gissa nemn t otarepo r as a aiceps l sac e tnemetats . ehT lareneg mrof of ht e tnemngissa rotarepo si

irav eman_elba = ;noisserpxe ehw re na expr noisse yam eb sa elpmis sa a elgnis noc nats t or as elpmoc x as

oy u req iu r .e ++C/C sesu a elgnis lauqe ngis ot etacidni tnemngissa ekilnu( lacsaP ro aludoM - ,2 hcihw esu eht =: )tcurtsnoc . ehT at r teg , ro tfel ,trap fo

eht tnemngissa tsum eb a elbairav etniop a ro r .tnatsnoc a ro noitcnuf a ton ,yltneuqerF ni erutaretil no ++C/C dna ni relipmoc rorre segassem uoy lliw

ees eseht owt :smret eulavl dna eulavr . ylpmiS ,tup na eulavl si yna tcejbo taht nac rucco no eht tfel edis fo na tnemngissa tnemetats . roF lla lacitcarp

,sesoprup "eulavl" snaem ".elbairav" ehT mret eulavr srefer ot snoisserpxe no eht thgir edis fo na tnemngissa ylpmis dna fo eulav eht snaem na .noisserpxe

epyT 2.4 noisrevnoC ni stnemngissA nehW selbairav of eno epyt era dexim htiw selbairav fo rehtona ,epyt a epyt

noisrevnoc ucco lliw r. nI na tnemngissa ,tnemetats eht epyt noisrevnoc elur si :ysae ehT eulav fo eht thgir edis noisserpxe( )edis fo eht tnemngissa si

Page 7: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 4

detrevnoc ot eht epyt fo eht tfel edis grat( te ,)elbairav sa detartsulli :ereh

2 elbaT - noisrevnoc eht taht rebmemeR .snoisrevnoc epyt tnemngissa eht sezirammus 3 na fo tni a ot taolf a ro , taolf a ot elbuod ro noisicerp yna dda ton seod ,no os dna ,

t egnahc ylno snoisrevnoc fo sdnik esehT .ycarucca si eulav eht hcihw ni mrof eh a taert syawla srelipmoc emos ,noitidda nI .detneserper rahc on ,evitisop sa elbairav

na ot ti gnitrevnoc nehw ,sah ti eulav tahw rettam tni ro taolf taert srelipmoc rehtO . rahcmun evitagen sa 721 naht retaerg seulav elbairav yllareneG .gnitrevnoc nehw sreb

T tegra T epy noisserpxE epyT elbissoP ofnI ssoL

dengis rahc rahc fI eulav > ,721 tegrat si evitagen rahc trohs tni hgiH - stib 8 redro rahc tni 61( )stib hgiH - stib 8 redro rahc tni 23( )stib hgiH - redro 42 stib rahc gnol tni hgiH - redro 42 stib trohs tni tni 61( )stib enoN trohs tni tni 23( )stib hgiH - redro 61 stib

tni 61( )stib gnol tni hgiH - redro 61 stib tni 23( )stib gnol tni enoN

ni t taolf lanoitcarF trap dna ylbissop erom taolf lbuod e ,noisicerP dednuor tluser

od lbu e gnol elbuod ,noisicerP dednuor tluser

elbaT 2- .3 ehT emoctuO fo nommoC epyT noisrevnoC

stnemngissA elpitluM 3.4 elpitlum gnisu yb eulav emas eht selbairav ynam ngissa ot uoy swolla ++C/C

margorp siht ,elpmaxe roF .tnemetats elgnis a ni stnemngissa sngissa tnemgarf x , y dna , z:0 eulav eht

seulav nommoc dengissa yltneuqerf era selbairav ,smargorp lanoisseforp nI ;0 = z = y = x.dohtem siht gnisu

srotarepO citemhtirA 4.4 2 elbaT - .srotarepo citemhtira s'++C/C stsil 4

Page 8: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 5

tnemerceD dna tnemercnI 5.4

C/C .segaugnal retupmoc rehto emos ni dnuof ton srotarepo lufesu owt sedulcni ++ ,srotarepo tnemerced dna tnemercni eht era esehT ++ dna - - rotarepo ehT . ++ ot 1 sdda

dna ,dnarepo sti - - :sdrow rehto nI .1 stcartbus

si eht emas sa

dna

lanoitaleR 6.4 na d lacigoL srotarepO

esiwtiB 7.4 srotarepO

Page 9: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 6

.5 sgnirts dna syarrA

nA yarra si a noitcelloc fo selbairav fo eht emas epyt taht era derrefer ot hguorht a ommoc n eman . A ificeps c nemele t in an arra y is essecca d by an

xedni . nI ,++C/C lla syarra tsisnoc fo oc suougitn yromem snoitacol . ehT tsewol sserdda sdnopserroc ot eht tsrif tnemele dna eht tsehgih sserdda ot eht

tsal .tnemele syarrA yam evah morf eno ot lareves snoisnemid . ehT tsom nommoc yarra si

eht llun - detanimret gnirts , hcihw si ylpmis na yarra fo ahc sretcar detanimret yb a .llun

elgniS 1.5 - noisnemiD syarrA ehT lareneg mrof rof gniralced a elgnis - noisnemid yarra si

epyt ]ezis[eman_rav ;

ekiL rehto ,selbairav syarra um st be lticilpxe y alced red so aht t ht e elipmoc r am y etacolla romem ni meht rof ecaps y. Her ,e epyt seralced eht esab epyt fo eht ,yarra

hcihw si eht arra eht ni tnemele hcae fo epyt y dna , ezis senifed woh ynam stnemele eht yarra lliw loh d. roF ,elpmaxe ot eralced a 001 - tnemele yarra dellac

ecnalab fo epyt lbuod e, esu siht :tnemetats elbuod lab ;]001[ecna

nA tnemele si dessecca yb gnixedni eht yarra eman . sihT si enod yb gnicalp ehtarra eht fo eman eht retfa stekcarb erauqs nihtiw tnemele eht fo xedni y. roF

,elpmaxe ]3[ecnalab = ;32.21

lluN -T sgnirtS detanimre yB raf eht tsom nommoc esu fo eht no e- lanoisnemid yarra si sa a retcarahc

.gnirts ++C stroppus owt sepyt fo sgnirts . ehT tsrif si eht llun - detanimret gnirts , hcihw

si a llun - arra retcarahc detanimret y. A( llun si ).orez suhT a llun - detanimret gnirts sniatnoc eht sretcarahc taht esirpmoc eht gnirts dewollof yb a llun . sihT

si eht ylno epyt fo gnirts denifed yb ,C dna ti si llits eht tsom ylediw desu . semitemoS llun - detanimret sgnirts era dellac C- gnirts s. ++C osla senifed a

gnirts ,ssalc dellac nirts g p hcihw , r na sedivo tcejbo - detneiro caorppa gnirts ot hgnildnah . tI si debircsed retal ni siht koob . eH r ,e llun - detanimret sgnirts era

.denimaxe nehW gniralced a retcarahc yarra taht lliw dloh a llun - detanimret ,gnirts uoy deen ot ed alc er it to be no e etcarahc r egnol r aht n ht e al r seg t nirts g aht t it is to

Page 10: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 7

dloh . oF r ,elpmaxe ot eralced na yarra rts taht nac dloh a 01 - retcarahc ,gnirts uoy dluow etirw sihT sekam moor rof eht llun ta eht dne fo eht .gnirts

nehW uoy esu a detouq gnirts tnatsnoc ni ruoy ,margorp uoy era osla gnitaerc a llun - detanimret ts gnir . A gnirts tnatsnoc si a tsil fo sretcarahc desolcne ni

elbuod .setouq roF ,elpmaxe olleh" "ereht uoY od ton deen ot dda eht llun ot eht dne fo gnirts stnatsnoc

yllaunam — eht llacitamotua uoy rof siht seod relipmoc y. ++C/C stroppus a ediw egnar fo tcnuf snoi taht etalupinam llun - detanimret

.sgnirts ehT tsom nommoc era

emaN noitcnuF

ts r (ypc s1, s2) seipoC 2s otni 1s .

ts r (tac s1, 2s ) setanetacnoC 2s otno eht dne fo 1s .

nelrts ( 1s ) snruteR eht htgnel fo 1s .

ts r (pmc s1, s2) snruteR 0 fi 1s dna 2s era eht ;emas el ss naht 0 fi s1<s2 ; fi 0 naht retaerg 1s > 2s . ts r (rhc s1, hc ) snruteR a retniop ot eht tsrif ecnerrucco fo

hc ni 1s .

rtsrts (s1, s2) snruteR a retniop ot eht tsrif ecnerrucco fo 2s ni 1s .

esehT snoitcnuf esu eht dradnats redaeh elif h.gnirts . ++C( margorp s nac osla esu

++C eht - elyts redaeh >gnirtsc< .) ehT gniwollof margorp setartsulli eht esu fo eseht gnirts :snoitcnuf owT 2.5 - lanoisnemiD syarrA

++C/C stroppus lanoisnemiditlum syarra . ehT tselpmis mrof fo eht lanoisnemiditlum owt eht si yarra - a lanoisnemid arr y. A owt - lanoisnemid yarra

,si fo yarra na ,yllaitnesse eno - lanoisnemid syarra . T owt a eralced o - yarra regetni lanoisnemid d fo ezis ,02,01 uoy dluow etirw

tni ;]02[]01[d yaP luferac noitnetta ot eht noitaralced . emoS rehto retupmoc segaugnal esu

sammoc ot etarapes eht yarra ;snoisnemid ,++C/C ni ,tsartnoc secalp hcae noisnemid ni sti nwo tes fo .stekcarb lralimiS y yarra fo 2,1 tniop ssecca ot , d,

uoy dluow esu

Page 11: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 8

owT - lanoisnemid syarra era derots ni wor a - nmuloc tsrif eht erehw ,xirtam

setacidni xedni eht wor dna eht dnoces setacidni eht nmuloc . sihT snaem taht eht xedni tsomthgir segnahc retsaf naht eht tsomtfel nehw gnissecca eht

stnemele ni eht yarra eht ni redro ni hcihw yeht era yllautca derots ni yromem . In eht esac fo a owt - lanoisnemid ,yarra eht gniwollof alumrof sdleiy eht

rebmun fo setyb fo yromem dedeen ot dloh :ti setyb = ezis fo ts1 xedni x ezis fo dn2 xedni x esab(foezis )epyt

,eroferehT gnimussa 4- etyb ,sregetni na regetni yarra htiw snoisnemid ,01 5 dluow evah

01 x 5 x 4 ro 002 setyb .detacolla

lanoisnemiditluM 3.5 syarrA

++C/C swolla syarra fo erom naht owt snoisnemid . na fi ,timil tcaxe ehT y si ,denimreted relipmoc ruoy yb . ehT lareneg mrof fo a lanoisnemiditlum yarra noitaralced si

epyt eman [ ziS e1][ eziS 2][ eziS 3 .] . .[ eziS N ;] syarrA fo erom naht eerht snoisnemid era ton netfo desu esuaceb fo eht

fo tnuoma yromem yeht eriuqer . roF ,elpmaxe a ruof - lanoisnemid retcarahc yarra htiw snoisnemid 4,9,6,01 seriuqer

01 * 6 * 9 * 4

ro 061,2 setyb . fI eht ra yar dleh 2- etyb ,sregetni 023,4 setyb dluow eb dedeen . fI eht yarra dleh lbuod es gnimussa( 8 setyb rep lbuod e eb dluow setyb 082,71 ,)

iuqer r .de ehT egarots deriuqer sesaercni yllaitnenopxe htiw eht rebmun fo snoisnemid . roF fo noisnemid htfif a fi ,elpmaxe arra gnidecerp eht ot dedda saw 01 ezis y ,

,271 neht 008 setyb dluow eb .deriuqer In anoisnemiditlum l syarra , it ekat s ht e etupmoc r mit e to tupmoc e cae h xedni .

sihT snaem taht gnissecca na tnemele ni a lanoisnemiditlum yarra nac eb rewols naht gnissecca na tnemele ni a elgnis - noisnemid .yarra

.6 sepyt denifed resu & sretnioP

ehT tcerroc gnidnatsrednu dna esu fo sretniop si lacitirc ot lufsseccus ++C/C nimmargorp g. erehT era eerht snosaer rof :siht ,tsriF sretniop edivorp eht yb snaem hcihw snoitcnuf nac idom yf rieht gnillac stnemugra . ,dnoceS sretniop troppus cimanyd noitacolla . ,drihT sretniop nac evorpmi

eht ycneiciffe fo niatrec senituor . ,oslA sa uoy lliw ees ni traP ,owT sretniop ekat no lanoitidda selor ni .++C retnioP s a er no e of ht e ts r segno t ub t sla o

no e of ht e som t egnad r uo s utaef res in +C/C +. oF r elpmaxe , ezilaitininu d retniop s o( r retniop s niniatnoc g ilavni d seulav ) ac n suac e uoy r etsys m to hsarc . eP r pah s esrow , it is ae sy to

su e retniop s rocni r ltce ,y gnisuac sgub taht .dnif ot tluciffid yrev era B esuace

Page 12: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 9

fo htob rieht ecnatropmi dna rieht laitnetop rof ,esuba siht etpahc r senimaxe eht tcejbus fo sretniop ni .liated

.7 stnenopmoC noitcnuF

A noitcnuf si yleuqinu detneserper yb a eman dna a tes fo dnarepo .sepyt stI ,sdnarepo ot derrefer sa retemarap s, ra e deificeps ni a ammoc - detarapes tsil desolcne ni

.sesehtnerap snoitca ehT taht eht noitcnuf smrofrep era deificeps ni a ,kcolb derrefer ot sa eht noitcnuf ydob yrevE . noitcnuf sah na detaicossa nruter pyt e . sA na ,elpmaxe ew dluoc etirw eht gniwollof nuf noitc ot dnif eht tsetaerg nommoc

rosivid fo ni owt t :s // nruter eht tsetaerg nommoc rosivid tni tni(dcg ,1v tni )2v

{ elihw )2v( {

tni pmet = ;2v 2v = 1v % ;2v 1v = ;pmet

} nruter ;1v

}

ereH ew enifed a noitcnuf deman cg d taht snruter na ni t dna sah owt ni t oT .sretemarap llaccg d , ew tsum ylppus ni owt t seulav dna ew teg na ni t ni .nruter

gnillaC 1.7 a noitcnuF

oT ekovni a noitcnuf ew esu eht llac otarepo r , hcihw si a riap fo .sesehtnerap sA htiw ,rotarepo yna eht llac rotarepo sekat sdnarepo dna eiy sdl a .tluser ehT sdnarepo ot eht

llac era rotarepo eht eman fo eht noitcnuf dna a ylbissop( )ytpme ammoc - detarapes tsil fo tnemugra s . tluser ehT epyt fo a llac si eht nruter epyt fo eht dellac ,noitcnuf dna eht

tluser flesti si eht denruter eulav yb eht :noitcnuf // teg seulav morf dradnats tupni

tuoc << retnE" owt :seulav \ ;"n tni ,i ;j nic >> i >> ;j

// lac l cg d no stnemugra i na d j // dna tnirp rieht tsetaerg nommoc rosivid

tuoc << :dcg" " << ,i(dcg )j << ;ldne fI ew evag siht margorp 51 dna 321 sa pni ,tu eht tuptuo dluow eb gnillaC .3 a noitcnuf

seod owt :sgniht tI sezilaitini eht noitcnuf sretemarap morf eht stnemugra gnidnopserroc dna srefsnart lortnoc ot eht noitcnuf gnieb noitucexE .dekovni fo eht nillac g si noitcnuf

dednepsus dna noitucexe fo eht ellac d noitcnuf snigeb . noitucexE fo a noitcnuf snigeb htiw )ticilpmi( eht noitinifed dna noitazilaitini fo sti tahT .sretemarap ,si nehw ew ekovni

cg d , eht srif gniht t taht sneppah si taht selbairav fo epyt ni t deman v1 dna v2 era .detaerc esehT airav era selb dezilaitini htiw eht seulav dessap ni eht llac ot cg d . nI siht ,esac v1

Page 13: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 01

si dezilaitini yb eht eulav fo i dna v2 yb eulav eht fo j .

noitcnuF 2.7 ydoB sI a epocS

ehT ydob fo a noitcnuf si a tnemetats ,kcolb hcihw senifed eht s'noitcnuf .noitarepo sA ,lausu kcolb eht si desolcne yb a riap fo ylruc secarb dna ecneh smrof a wen .epocs sA

htiw yna ,kcolb ydob eht fo a noitcnuf nac enifed semaN .selbairav denifed edisni a noitcnuf ydob era ylno elbissecca nihtiw eht noitcnuf .flesti hcuS selbairav era derrefer ot

sa lacol selbairav . yehT "lacol" era ot taht ;noitcnuf rieht seman era elbisiv ylno ni eht epocs fo eht yehT .noitcnuf tsixe elihw ylno eht noitcnuf si .gnitucexe noitucexE

setelpmoc nehw a ruter n tnemetats si .deretnuocne nehW eht dellac cnuf noit ti ,sehsinif sdleiy sa sti tluser eht eulav deificeps ni eht ruter n .tnemetats retfA eht nruter si ,detucexe

eht ,dednepsus gnillac noitcnuf semuser noitucexe ta eht tniop fo eht tI .llac sesu eht eulav nruter sa eht tluser fo gnitaulave eht llac repo rota dna seunitnoc gnissecorp

revetahw sniamer eht fo tnemetats ni hcihw eht llac saw .demrofrep

sretemaraP 3.7 dna stnemugrA

ekiL lacol ,selbairav eht sretemarap fo a noitcnuf edivorp ,deman lacol egarots rof esu yb oitcnuf eht n. ehT ecnereffid si taht sretemarap era denifed edisni eht s'noitcnuf retemarap

tsil era dna dezilaitini yb stnemugra dessap ot eht noitcnuf nehw eht noitcnuf si .dellacnA tnemugra si na .noisserpxe tI thgim eb a ,elbairav a laretil tnatsnoc ro na noisserpxe

gnivlovni eno ro erom eW .srotarepo tsum ssap yltcaxe eht emas rebmun fo stnemugra sa noitcnuf eht sah .sretemarap ehT epyt fo hcae tnemugra tsum hctam eht gnidnopserroc ni retemarap eht emas yaw taht eht epyt fo na rezilaitini tsum hctam eht epyt fo eht tcejbo

ti :sezilaitini ehT tnemugra tsum evah eht emas epyt ro evah a epyt taht nac eb ylticilpmi detrevnoc

noitcnuF 3.7 nruteR epyT

ehT nruter epyt fo a noitcnuf nac eb a tliub - ni ,epyt hcus sa ni t ro lbuod e , a ssalc ,epyt ro dnuopmoc a ,epyt hcus sa tni & ro *gnirts . A er nrut epyt osla nac eb iov d , hcihw

snaem taht noitcnuf eht seod ton nruter a .eulav ehT gniwollof era elpmaxe snoitinifed fo elbissop ter noitcnuf u nr ty ep s:

loob tni(tneserp_si ,* ;)tni // nruter s loob tni tsnoc(tnuoc gnirts ,& ;)rahc // nruter s int

etaD & tsnoc(radnelac ;)*rahc // snruter ecnerefer ot etaD diov ;)(ssecorp // secorp s seod ton nruter a eulav

A noitcnuf yam ton nruter rehtona noitcnuf ro a tliub - ni yarra .epyt ,daetsnI eht noitcnuf nruter yam a retniop ot eht noitcnuf ro ot a retniop ot na ele tnem ni eht :yarra

// :ko retniop ot tsrif tnemele fo eht yarra tni )(rab_oof* { */ ... /* }

sihT noitcnuf snruter a retniop ot ni t dna taht retniop dluoc tniop ot na tnemele ni na .yarra

Page 14: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 11

snoitcnuF 4.7 tsuM yficepS a nruteR epyT

tI si lagelli ot enifed ro eralced a noitcnuf tuohtiw na ticilpxe nruter :epyt

// :rorre gnissim nruter epyt

elbuod(tset ,1v elbuod )2v { */ ... /* }

reliraE snoisrev fo ++C dluow tpecca siht margorp dna ylticilpmi enifed eht nruter epyt fo tset sa na ni t . rednU dradnatS ,++C siht margorp si na .rorre

noitcnuF 5.7 retemaraP tsiL

ehT retemarap tsil fo a noitcnuf nac eb ytpme tub tonnac eb A .dettimo noitcnuf htiw onsretemarap nac eb nettirw rehtie htiw na ytpme retemarap tsil ro a retemarap tsil

gniniatnoc elgnis eht drowyek iov d. roF ,elpmaxe eht gniwollof snoitaralced fo ssecorp era :tnelaviuqe

diov )(ssecorp { */ ... /* } // ticilpmi diov retemarap tsil diov {)diov(ssecorp */ ... /* } // tnelaviuqe noitaralced

A retemarap tsil stsisnoc fo a ammoc - detarapes tsil fo etemarap r sepyt dna )lanoitpo( retemarap nevE .seman nehw eht sepyt fo owt sretemarap era eht ,emas eht epyt tsum eb

:detaeper tni tni(pinam ,1v )2v { */ ... /* } // rorre tni tni(pinam ,1v tni )2v { */ ... /* } // ko oN owt sretemarap nac evah eht emas .eman ,ylralimiS a elbairav lacol ot a noitcnuf yam

esu ton eht emas eman sa eht eman fo yna fo eht s'noitcnuf semaN .sretemarap era ,lanoitpo tub ni a noitcnuf ,noitinifed yllamron lla sretemarap era .deman A retemarap

tsum eb deman ot eb .desu

retemaraP 6.7 T epy - gnikcehC

nehW ew llac a ,noitcnuf eht epyt fo hcae tnemugra tsum eb rehtie eht emas epyt sa ehtgnidnopserroc retemarap ro a epyt taht nac eb detrevnoc ot taht .epyt

ehT s'noitcnuf retemarap tsil sedivorp eht relipmoc htiw eht epyt noitamrofni dedeen to eht kcehc .stnemugra roF ,elpmaxe eht noitcnuf cg d , hcihw ew denifed no egap 22 6 ,

sekat sretemarap owt fo epyt ni t : ,"olleh"(dcg ;)"dlrow" // :rorre gnorw tnemugra sepyt

)21342(dcg ; // :rorre oot wef stnemugra ,24(dcg ,01 ;)0 // :rorre oot ynam emugra stn

hcaE fo eseht sllac si a elipmoc - emit .rorre nI eht tsrif ,llac eht stnemugra era fo epyt rahc tsnoc * . erehT si on noisrevnoc morf tsnoc ot *rahc ni t , os eht llac si .lagelli nI eht

dnoces dna driht ,sllac cg d si dessap eht gnorw rebmun fo .stnemugra ehT noitcnuf tsum eb dellac htiw owt ;stnemugra ti si na rorre ot llac ti htiw yna rehto .rebmun

tuB tahw sneppah fi eht llac seilppus owt stnemugra fo epyt lbuod e ? sI siht llac ?lagel

Page 15: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 21

,41.3(dcg ;)92.6 // :ko stnemugra era detrevnoc ot ni t

nI ,++C eht a rewsn si ;sey eht llac si lagel . sihT llac sevlovni hcus a tnaw ew noisrevnoc ot esu lbuod e seulav ot ezilaitini ni t .stcejbo ,eroferehT gniggalf eht llac sa na rorre

eb dluow oot .ereves ,rehtaR eht stnemugra era ylticilpmi detrevnoc ot ni t esuaceB siht c noisrevno thgim esol ,noisicerp tsom srelipmoc lliw eussi a .gninraw nI siht eht ,esac

llac semoceb ,3(dcg ;)6

dna snruter a eulav fo .3 A llac taht sessap oot ynam ,stnemugra stimo na ,tnemugra ro

sessap na tnemugra fo gnorw eht epyt tsomla ylniatrec w dluo tluser ni suoires nur - emit .srorre gnihctaC eseht os - ecafretni dellac srorre ta elipmoc emit yltaerg secuder eht elipmoc - gubed - tset elcyc rof egral smargorp .

.8 gnissap tnemugrA

hcaE retemarap si detaerc wena no hcae llac ot eht .noitcnuf ehT eulav desu ot ezilaitini retemarap a si eht gnidnopserroc tnemugra dessap ni eht .llac

ecnerefernoN 1.8 sretemaraP

sretemaraP taht era ,nialp ecnerefernon sepyt era dezilaitini yb gniypoc eht nemugra gnidnopserroc t nehW . a retemarap si dezilaitini htiw a ,ypoc eht noitcnuf sah

on ssecca ot eht stnemugra lautca fo eht tI .llac tonnac egnahc eht s'teL .stnemugra kool niaga ta eht noitinifed fo cg d :

// nruter eht tsetaerg nommoc rosivid tni tni(dcg ,1v tni )2v

{ elihw )2v( {

tni pmet = ;2v 2v = 1v % ;2v 1v = ;pmet

} nruter ;1v

} edisnI eht ydob fo eht lihw e , ew egnahc eht seulav fo htob v1 dna v2 ,revewoH .

eseht era segnahc edam ot eht lacol sretemarap dna era ton detcelfer ni eht stnemugra desu ot llac cg d . nehw ,suhT ew llac

,i(dcg )j eht seulav i dna j era ffanu detce yb eht stnemngissa demrofrep edisni cg d .

retnioP 2.8 sretemaraP

A retemarap nac eb a retniop ni hcihw esac eht tnemugra retniop eipoc si d. sA htiw yna

Page 16: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 31

ecnerefernon epyt ,retemarap segnahc edam ot eht retemarap era edam eht ot lacol .ypoc fI eht uf noitcn sngissa a wen retniop eulav ot eht ,retemarap eht gnillac eulav retniop si

.degnahcnu

diov tni(teser )pi* pi* = ;0 // segnahc eht eulav fo eht tcejbo ot hcihw ip stniop

pi = ;0 // segnahc ylno eht lacol eulav fo ip; eht tnemugra si degnahcnu } A retf a llac ot eser t , eht tnemugra si degnahcnu tub eht tcejbo ot hcihw eht tnemugra

lliw stniop eb :0

tni i = ;24 tni p* = ;i&

tuoc << :i" " << p* << '\ ;'n // tnirp s :i 24 )p(teser ; // egnahc s *p tub ton p

tuoc << :i" " << p* << ;ldne // stnirp :ko :i 0 fI ew tnaw ot tneverp segnahc ot eht eulav ot hcihw eht retniop ,stniop neht eht

dluohs retemarap eb denifed sa a retniop ot snoc t :

diov tsnoc(rtp_esu tni )p* { // tp_esu r yam daer tub ton etirw to p*

} rehtehW a retniop retemarap stniop ot a snoc t ro on n snoc t epyt stceffa eht stnemugra

taht nac ew esu ot llac eht .noitcnuf eW nac llac rtp_esu no rehtie na tni * a ro tsnoc *tni ; ew nac ylno ssap no na tni * ot eser t sihT . noitcnitsid swollof morf eht

noitazilaitini selur rof eW .sretniop yam ezilaitini a retniop ot snoc t ot tniop ot a on n snoc t tcejbo yam tub ton esu a retniop ot non snoc t ot tniop a ot snoc t o .tcejb

snoc 3.8 t sretemaraP

eW nac llac a noitcnuf taht sekat a ,ecnerefernon non snoc t retemarap gnissap rehtie a snoc t on ro n snoc t .tnemugra roF ,elpmaxe ew dluoc ssap owt tsnoc ni t s ot ruo cg d

:noitcnuf

tsnoc tni i = ,3 j = ;6 tni k = ,3(dcgr ;)6 // ko : k dezilaitini ot 3

sihT roivaheb swollof morf eht lamron noitazilaitini selur rof snoc t .stcejbo esuaceB eht noitazilaitini seipoc eht eulav of eht ,rezilaitini ew nac ezilaitini a non snoc t tcejbomorf a snoc t ,tcejbo ro eciv fI .asrev ew ekam eht retemarap a snoc t ecnerefernon

:epyt diov tsnoc(ncf tni )i { */ fcn nac daer tub ton etirw to i /* neht eht noitcnuf tonnac

egnahc sti lacol ypoc of eht ehT .tnemugra tnemugra si llits dessap sa

Page 17: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 41

a ypoc os ew nac ssap cf n rehtie a snoc t ro on n snoc t jbo e .tc

tahW yam eb ,gnisirprus si taht hguohtla eht retemarap si a snoc t edisni eht ,noitcnuf relipmoc eht esiwrehto staert eht noitinifed fo cf n sa fi ew dah denifed eht retemarap

sa a nialp tni : diov tsnoc(ncf tni )i { */ fcn nac daer tub ton etirw to i /* } diov tni(ncf )i { */ ... /* } // :rorre enifeder s f tni(nc )

sihT egasu stsixe ot troppus ytilibitapmoc htiw eht C ,egaugnal hcihw sekam on

oitcnitsid neewteb n snoitcnuf gnikat snoc t ro on n snoc t .sretemarap

snoitatimiL fo gniypoC stnemugrA

gniypoC na tnemugra si ton elbatius rof yreve .noitautis sesaC erehw gniypoc t'nseod krow :edulcni

nehW ew tnaw eht noitcnuf ot eb elba ot egnahc eht eulav fo na a .tnemugr

nehW ew tnaw ot ssap a egral tcejbo sa na .tnemugra ehT emit dna ecaps stsoc ot ypoc eht tcejbo era netfo oot hgih rof laer - dlrow .snoitacilppa

nehW ereht si on yaw ot ypoc eht .tcejbo nI eseht sesac ew nac daetsni enifed eht sretemarap sa efer secner ro .sretniop

ecnerefeR 4.8 sretemaraP

sA na elpmaxe fo a noitautis erehw gniypoc eht tnemugra t'nseod ,krow redisnoc a noitcnuf ot

paws eht seulav fo sti owt :stnemugra // tcerrocni noisrev of paws : ehT stnemugra era ton !degnahc

diov tni(paws v ,1 tni )2v {

tni pmt = ;2v 2v = ;1v // sngissa wen eulav ot lacol ypoc fo eht tnemugra 1v = ;pmt

} // lacol stcejbo v1 na d v2 on regnol tsixe nI siht ,esac ew tnaw ot egnahc eht stnemugra .sevlesmeht sA ,denifed ,hguoht aws p

tceffa tonnac esoht tnemugra .s nehW ti ,setucexe aws p segnahcxe eht lacol seipoc fo sti stnemugra . stnemugra ehT dessap ot aws p era :degnahcnu

tni )(niam

Page 18: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 51

{ tni i = ;01 tni j = ;02

tuoc << erofeB" :)(paws \ :it " << i << "\ :jt " << j << ;ldne

,i(paws ;)j tuoc << retfA" :)(paws \ :it "

<< i << "\ :jt " << j << ;ldne nruter ;0

} gnilipmoC dna gnitucexe siht margorp stluser ni eht gniwollof :tuptuo

erofeB :)(paws :i 01 :j 02 retfA :)(paws :i 01 :j 02

roF aws p ot krow sa dednetni dna paws eht seulav fo sti ,stnemugra ew deen ot ekam ehtemarap sret :secnerefer

// ko : aws p stca no secnerefer ot sti stnemugra diov tni(paws ,1v& tni )2v&

{ tni pmt = ;2v

2v = ;1v 1v = ;pmt

} ekiL lla ,secnerefer ecnerefer sretemarap refer yltcerid ot eht stcejbo ot hcihw yeht era

rehtar dnuob naht ot seipoc fo esoht nehW .stcejbo ew enifed a ,ecnerefer ew tsum ezilaitini ti htiw tcejbo eht ot hcihw eht ecnerefer lliw eb ecnerefeR .dnuob sretemarap

krow yltcaxe eht emas hcaE .yaw emit eht noitcnuf si ,dellac eht ecnerefer retemarap si detaerc dna dnuob ot opserroc sti gnidn .tnemugra ,woN nehw ew llac paws ,i(paws ;)j

eht retemarap v1 si tsuj rehtona eman rof eht tcejbo i dna v2 si rehtona eman rof j . ynAegnahc ot v1 si yllautca a egnahc ot eht tnemugra i . ,ylralimiS segnahc ot v2 era yllautca ot edam j . fI ew er elipmoc iam n gnisu siht desiver noisrev fo aws p , ew nac

ees taht eht tuptuo si won c ro r tce : erofeB :)(paws :i 01 :j 02

retfA :)(paws :i 02 :j 01

gnisU 5.8 ecnerefeR sretemaraP ot nruteR lanoitiddA noitamrofnI

ev'eW nees eno ,elpmaxe aws p , ni hcihw efer ecner sretemarap erew desu ot wolla eht

ot noitcnuf egnahc eht eulav fo sti rehtonA .stnemugra esu fo ecnerefer sretemarap si ot nruter lanoitidda na tluser ot eht gnillac .noitcnuf

snoitcnuF nac nruter ylno a elgnis ,eulav tub semitemos a noitcnuf sah rom e naht eno gniht ruter ot n. roF ,elpmaxe s'tel enifed a noitcnuf deman av_dnif l taht sehcraes rof a

ralucitrap ni eulav eht stnemele fo a otcev r fo tI .sregetni snruter na rotareti taht srefer ot eht ,tnemele fi tnemele eht saw ,dnuof ro ot eht ne d eulav if eht tnemele t'nsi .dnuof

Page 19: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 61

d'eW osla ekil eht noitcnuf nruter ot na ecnerrucco tnuoc fi eht eulav srucco erom naht .ecno nI siht esac eht rotareti dluohs denruter eb ot eht tsrif tnemele taht sah eht eulav

rof hcihw er'ew woH .gnikool nac ew enifed a tcnuf noi taht snruter htob na rotareti dna na ecnerrucco ?tnuoc eW enifed dluoc a wen epyt taht sniatnoc na rotareti dna a .tnuocnA reisae noitulos si ot ssap lanoitidda na ecnerefer tnemugra taht av_dnif l nac esu ot

nruter a tnuoc fo eht rebmun secnerrucco fo :

// snruter na rotareti taht srefer ot eht tsrif ecnerrucco of eulav // eht ecnerefer etemarap r rucco s sniatnoc a dnoces nruter eulav

rotareti_tsnoc::>tni<rotcev (lav_dnif rotareti_tsnoc::>tni<rotcev ,geb // tsrif tnemele rotareti_tsnoc::>tni<rotcev ,dne // eno tsap tsal tnemele

tni ,eulav // eht eulav ew tnaw epyt_ezis::>tni<rotcev )srucco& // rebmun fo semit ti srucco

{ // r eti_se r lliw dloh tsrif ,ecnerrucco fi yna

rotareti_tsnoc::>tni<rotcev reti_ser = ;dne srucco = ;0 // tes ecnerrucco tnuoc etemarap r

rof ( ; geb =! ;dne )geb++ fi geb*( == )eulav { // rebmemer tsrif ecnerrucco fo eulav fi reti_ser( == )dne reti_ser = ;geb

;srucco++ // tnemercni ecnerrucco tnuoc }

nruter ;reti_ser // tnuoc denruter ylticilpmi in srucco }

nehW ew llac av_dnif l , ew ah ev ot ssap ruof :stnemugra a riap fo srotareti taht etoned egnar eht fo stnemele ni eht otcev r ni hcihw ot ,kool eht eulav ot kool dna ,rof a

pyt_ezis e) tcejbo ot dloh eht ecnerrucco tnuoc . gnimussA evi c si ,>tni<rotcev a ti si na rotareti fo eht thgir pyt ,e dna tc r si a pyt_ezis e , ew dluoc llac lav_dnif sa :swollof

ti = ,)(nigeb.cevi(lav_dnif ,)(dne.cevi ,24 ;)rtc

retfA eht ,llac eht eulav fo tc r lliw eb eht rebmun fo semit 24 ,srucco dna it lliw refer ot tsrif eht ecnerrucco fi ereht si eno . ,esiwrehtO it lliw eb lauqe ot )(dne.cevi dna tc r lliw eb .orez

gnisU 6.8 ( snoc t ) secnerefeR ot diovA seipoC

ehT rehto ecnatsmucric ni hcihw ecnerefer sretemarap era lufesu si nehw gnissap a egral ot tcejbo a hguohtlA .noitcnuf gniypoc na tnemugra si yako rof ejbo stc fo tliub - ni

atad sepyt dna stcejbo rof fo ssalc sepyt taht era llams ni ,ezis ti si )netfo( oot tneiciffeni rof stcejbo fo tsom sepyt ssalc ro egral .syarra yB gnisu a ecnerefer ,retemarap eht

noitcnuf nac ssecca eht tcejbo yltcerid poc tuohtiw y gni .ti sA na ,elpmaxe ll'ew etirw a noitcnuf taht serapmoc eht htgnel fo owt nirts g .s hcuS a sdeen noitcnuf ot ssecca eht

zis e fo hcae nirts g tub sah on deen ot etirw ot eht nirts g s . esuaceB nirts g s nac eb ,gnol

Page 20: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 71

d'ew ekil ot diova gniypoc gnisU .meht snoc t er secneref ew nac diova :ypoc eht // erapmoc eht htgnel fo owt sgnirts

loob tsnoc(retrohSsi gnirts ,1s& tsnoc gnirts )2s& {

nruter )(ezis.1s < ;)(ezis.2s } hcaE retemarap si a ecnerefer ot tsnoc gnirts . esuaceB eht sretemarap era secnerefer eht

stnemugra ra e ton .deipoc esuaceB eht sretemarap era snoc t si ,secnerefer retrohS yam esu ton eht secnerefer ot egnahc eht .stnemugra

7.8 gnissaP a ecnerefeR ot a retnioP

esoppuS ew tnaw ot etirw a noitcnuf taht spaws owt ,sretniop ralimis ot eht margorp ew lrae etorw rei taht spaws owt .sregetni eW wonk taht ew esu * ot enifed a etniop r dna &

ot enifed cnerefer a e ehT . noitseuq ereh si woh ot enibmoc eseht srotarepo ot niatbo a ecnerefer ot etniop a r . ereH si na :elpmaxe

// paws seulav fo owt sretniop to int

diov srtp tni(paw ,1v&* tni )2v&* {

tni pmt* = ;2v 2v = ;1v 1v = ;pmt

} ehT retemarap tni 1v&* dluohs eb daer morf thgir ot :tfel v1 si a ecnerefer ot a retniop ot

na tcejbo fo epyt ni t . tahT ,si v1 si tsuj rehtona eman rof revetahw retniop si dessap ot awsrtp p . eW dluoc etirwer eht iam n noitcnuf morf egap 32 3 ot esu awsrtp p dna paws

sretniop ot eht seulav 01 dna :02

tni )(niam {

tni i = ;01 tni j = ;02 tni ip* = ;i& // ip stniop ot i tni jp* = ;j& // jp stniop ot j

tuoc << erofeB" :)(pawsrtp \ :ip*t " << ip* << "\ :jp*t " << jp* << ;ldne

,ip(pawsrtp ;)jp // on w pi ot stniop ;j jp ot stniop i tuoc << retfA" :)(pawsrtp \ :ip*t "

<< ip* << "\ :jp*t " << jp* << ;ldne nruter ;0

} nehW delipmoc dna ,detucexe eht margorp setareneg eht gniwollof :tuptuo erofeB :)(pawsrtp ip* : 01 :jp* 02

retfA :)(pawsrtp :ip* 02 :jp* 01

Page 21: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 81

tahW sneppah si taht eht retniop seulav era .deppaws nehW ew llac ,pawsrtp ip stniop ot i p dna j stniop ot j . edisnI awsrtp p eht sretniop era deppaws os taht retfa ,pawsrtp ip stniop ot tcejbo eht pj dah erdda .dess nI rehto ,sdrow pi won stniop ot j . ,ylralimiS pj stniop ot i . nI redro ot diova gniypoc eht otcev r , ew thgim kniht taht d'ew ekam eht

retemarap cnerefer a e .

8.8 yarrA sretemaraP syarrA evah owt laiceps seitreporp taht tceffa woh ew nifed e dna esu snoitcnuf taht etarepo no

:syarra eW tonnac ypoc na yarra dna nehw ew esu eht eman fo na yarra ti si yllacitamotua detrevnoc ot a retniop ot eht tsrif .tnemele esuaceB ew tonnac ypoc na

,yarra ew tonnac etirw a noitcnuf taht sekat na yarra p epyt etemara r. esuaceB syarra era yllacitamotua detrevnoc ot ,sretniop snoitcnuf taht laed syarra htiw yllausu od os yltceridni

yb gnitalupinam sretniop ot stnemele ni eht .yarra

gninifeD na yarrA retemaraP s'teL emussa taht ew tnaw ot etirw a noitcnuf taht iw ll tnirp eht stnetnoc fo na yarra fo ni t .s

eW dluoc yficeps eht yarra retemarap ni eno fo eerht :syaw // eerht tnelaviuqe snoitinifed fo seulaVtnirp

diov )*tni(seulaVtnirp { */ ... /* } diov )][tni(seulaVtnirp { */ ... /* } diov )]01[tni(seulaVtnirp { */ ... /* }

nevE hguoht ew tonnac ssap na yarra ,yltcerid ew nac etirw a noitcnuf retemarap taht skool

na ekil .yarra etipseD ,secnaraeppa a retemarap taht sesu yarra xatnys si detaert sa fi ew nettirw dah a retniop ot eht yarra tnemele .epyt esehT eerht ed snoitinif era ;tnelaviuqe hcae

deterpretni si sa gnikat a retemarap fo epyt tni * .

retemaraP 9.8 snoisnemiD naC eB gnidaelsiM

ehT relipmoc serongi yna noisnemid ew thgim yficeps rof na yarra .retemarap ,gniyleR,yltcerrocni no eht ,noisnemid ew thgim irw et eulaVtnirp s sa

// retemarap detaert sa tsnoc ,*tni ezis fo yarra si derongi

diov tsnoc(seulaVtnirp tni )]01[ai { // siht edoc semussa yarra sah 01 ;stnemele // retsasid fi tnemugra sah rewef naht 01 !stnemele

rof t_ezis( i = ;0 i =! ;01 )i++ {

tuoc << ]i[ai << ;ldne } }

hguohtlA siht edoc emussa s taht eht yarra ti si dessap sah ta tsael 01 ,stnemele gnihton ni ehtegaugnal secrofne taht .noitpmussa ehT gniwollof sllac era lla :lagel

Page 22: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 91

tni )(niam {

tni i = ,0 ]2[j = ,0{ ;}1 )i&(seulaVtnirp ; // ko : &i is tni *; elbaborp nur - emit rorre

)j(seulaVtnirp ; // ko : j si detrevnoc ot retniop ot ht0 // ;tnemele tnemugra sah epyt ;*tni // elbaborp nur - emit rorre

nruter ;0 }

nevE hguoht eht relipmoc seussi on ,stnialpmoc htob sllac era ni ,rorre dna ylbaborp lliw liaf nur ta nI .emit hcae ,esac yromem dnoyeb eht yarra lliw eb dessecca esuaceb seulaVtnirp

semussa taht eht yarra ti si dessap sah ta tsael 01 gnidnepeD .stnemele no eht seulav tahtneppah ot eb ni taht ,yromem eht margorp lliw rehtie ecudorp suoirups tuptuo ro .hsarc

gnissaP 01.8 na yarrA yb ecnerefeR

sA htiw yna ,epyt ew nac enifed na yarra retemarap sa a ecnerefer ot eht fI .yarra eht

retemarap si a ecnerefer ot eht ,yarra neht eht relipmoc seod ton trevnoc na yarra tnemugraotni a ,daetsnI .retniop a r ecnerefe ot eht yarra flesti si nI .dessap siht ,esac eht yarra ezis sitrap fo eht retemarap dna tnemugra .sepyt ehT relipmoc lliw kcehc taht eht ezis fo eht yarra

tnemugra sehctam eht ezis fo eht :retemarap // :ko retemarap si a ecnerefer ot na ;yarra s ezi fo yarra si dexif

diov tni(seulaVtnirp )]01[)rra&( { */ ... /* } tni )(niam

{ tni i = ,0 ]2[j = ,0{ ;}1 tni ]01[k = ;}9,8,7,6,5,4,3,2,1,0{

;)i&(seulaVtnirp // :rorre tnemugra si ton na yarra fo 10 stni ;)j(seulaVtnirp // :rorre tnemugra si ton na yarra fo 10 stni ;)k(seulaVtnirp // :ko tnemugra si na yarra fo 10 stni

nruter ;0 }

sihT noisrev fo eulaVtnirp s yam eb dellac ylno rof syarra fo yltcaxe 01 ni t ,s gnitimil hcihwsyarra nac eb ,revewoH .dessap esuaceb eht retemarap si a ,ecnerefer ti si efas ot yler no eht

ezis ni eht ydob fo eht :noitcnuf // :ko retemarap si a ecnerefer ot na ;yarra ezis fo yarra si dexif

diov tni(seulaVtnirp )]01[)rra&( {

rof t_ezis( i = ;0 i =! ;01 )i++ { tuoc << ]i[rra << ;ldne

}

Page 23: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 02

}

gnissaP 11.8 a denoisnemiditluM yarrA

llaceR taht ereht era on denoisnemiditlum syarra ni ++C ,daetsnI sraeppa tahw ot eb a denoisnemiditlum yarra si na yarra fo sA .syarra htiw yna ,yarra a denoisnemiditlum yarra

si dessap sa a retniop ot sti htorez .tnemele tnemele nA ni a denoinemiditlum ra yar si na .yarra ehT ezis fo eht dnoces dna( yna )snoisnemid tneuqesbus si trap fo eht tnemele epyt

dna tsum eb :deificeps // tsrif retemarap si na yarra esohw stnemele era syarra fo 10 ni ts

diov tni(seulaVtnirp ,]01[)*xirtam( tni ;)eziSwor seralced irtam x sa a retniop ot na yarra fo net ni t eW .s dluoc osla eralced a denoisnemiditlum yarra gnisu yarra .xatnys sA htiw a elgnis - denoisnemid ,yarra eht relipmoc serongi eht tsrif

noisnemid dna os ti si tseb ton ot edulcni :ti

// tsrif retemarap si na yarra ohw es stnemele era syarra fo 10 ni ts diov tni(seulaVtnirp ,]01[][xirtam tni ;)eziSwor

seralced irtam x ot eb tahw skool ekil a owt - denoisnemid .yarra nI ,tcaf eht retemarap si aretniop ot na tnemele ni na yarra fo hcaE .syarra tnemele ni eht yarra si flesti an yarra fo net

ni t .s .9 snoitcnuf enilnI

htiw desu ylnommoc si taht noitcnuf enilni na dellac ,++C ni erutaef tnatropmi na si erehT rieht ,rehtar ;dellac yllautca ton era taht snoitcnuf trohs etaerc nac uoy ,++C nI .sessalc

eht ta enil ni dednapxe si edoc a gnisu ot ralimis si ssecorp sihT .noitacovni hcae fo tniopnoitcnuf - ,dellac naht rehtar enil ni dednapxe eb ot noitcnuf a esuac oT .orcam ekil

noitcnuf eht ,margorp siht ni ,elpmaxe roF .drowyek enilni eht htiw noitinifed sti edecerpni dednapxe si )(xam :dellac fo daetsni enil

>maertsoi< edulcni#

;dts ecapseman gnisu )b tni ,a tni(xam tni enilni

{ ;b : a ? b>a nruter

} )(niam tni

{ ;)02 ,01(xam << tuoc

;)88 ,99(xam << " " << tuoc ;0 nruter

}

si margorp gnidecerp eht ,denrecnoc si relipmoc eht sa raf sA :eno siht ot tnelaviuqe >maertsoi< edulcni#

;dts ecapseman gnisu )(niam tni

Page 24: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 12

{ ;)02 : 01 ? 02>01( << tuoc

;)88 :99 ? 88>99( << " " << tuoc ;0 nruter

}

ot uoy wolla yeht taht si ++C ot noitidda tnatropmi na era snoitcnuf enilni taht nosaer ehT yrev etaerc detucexe yltneuqerf lareves eriuqer yllacipyt sessalc ecniS .edoc tneiciffe

eseht fo ycneiciffe eht ,)atad etavirp ot ssecca edivorp hcihw( snoitcnuf ecafretni a ,dellac si noitcnuf a emit hcae ,wonk ylbaborp uoy sA .nrecnoc lacitirc fo si snoitcnuf

fingis .msinahcem nruter dna gnillac eht yb detareneg si daehrevo fo tnuoma tnaci a nehw devas era sretsiger suoirav dna kcats eht otno dehsup era stnemugra ,yllacipyT eseht taht si elbuort ehT .snruter noitcnuf eht nehw derotser neht dna ,dellac si noitcnuf

tsni esoht fo enon ,enil ni dednapxe si noitcnuf a nehw ,revewoH .emit ekat snoitcur ,semit nur retsaf ecudorp nac enil ni sllac noitcnuf gnidnapxe hguohtlA .rucco snoitarepo

ti ,nosaer siht roF .edoc detacilpud fo esuaceb ezis edoc regral ni tluser osla nac ti tseb si esoht ylno enilni ot aedi doog a osla si ti ,rehtruF .snoitcnuf llams yrev ylno enilni ot

.margorp ruoy fo ecnamrofrep eht no tcapmi tnacifingis evah lliw taht snoitcnuf

.01 gnidaolrevo noitcnuF

n emas eht gnisu fo ssecorp eht si gnidaolrevo noitcnuF ehT .snoitcnuf erom ro owt rof ema tnereffid rehtie esu tsum noitcnuf eht fo noitinifeder hcae taht si gnidaolrevo ot terces eseht hguorht ylno si tI .sretemarap fo rebmun tnereffid a ro sretemarap fo sepyt

oitcnuf hcihw swonk relipmoc eht taht secnereffid roF .noitautis nevig yna ni llac ot n.sretemarap fo sepyt tnereffid gnisu yb )(cnufym sdaolrevo margorp siht ,elpmaxe

>maertsoi< edulcni# sretemarap fo sepyt ni reffid eseht // ;)i tni(cnufym tni

;)i elbuod(cnufym elbuod )(niam tni

{ << )01(cnufym << tuoc )i tni(cnufym sllac // ;" "

)i elbuod(cnufym sllac // ;)4.5(cnufym << tuoc ;0 nruter

} )i elbuod(cnufym elbuod

{ ;i nruter

} )i tni(cnufym tni

{ ;i nruter

} :sretemarap fo rebmun tnereffid a gnisu )(cnufym sdaolrevo margorp txen ehT

>maertsoi< edulcni# su ;dts ecapseman gni

Page 25: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 22

sretemarap fo rebmun ni reffid eseht // ;)i tni(cnufym tni ;)j tni ,i tni(cnufym tni

)(niam tni {

)i tni(cnufym sllac // ;" " << )01(cnufym << tuoc )j tni ,i tni(cnufym sllac // ;)5 ,4(cnufym << tuoc

;0 nruter }

)i tni(cnufym tni {

ruter ;i n }

)j tni ,i tni(cnufym tni {

} ;j*i nruter drager ni reffid tsum snoitcnuf eht taht si gnidaolrevo noitcnuf tuoba tniop yek eht ,denoitnem sA sepyt nruter rieht ni ylno gnireffid snoitcnuf owT .sretemarap fo rebmun ro/dna sepyt eht ot

olrevo eb tonnac :)(cnufym daolrevo ot tpmetta dilavni na si siht ,elpmaxe roF .deda era sepyt nruter gnireffid :rorrE // ;)i tni(cnufym tni .gnidaolrevo nehw tneiciffusni // ;)i tni(cnufym taolf

ht tcaf ni nehw ,reffid ot raeppa lliw snoitaralced noitcnuf owt ,semitemoS ,elpmaxe roF .ton od ye.snoitaralced gniwollof eht redisnoc

;)p* tni(f diov ][p sa emas si p* ,rorre // ;)][p tni(f diov

raeppa sepytotorp owt eht hguohtla ,eroferehT .] [p sa emas eht si p* relipmoc eht ot ,rebmemeRmarap rieht fo sepyt eht ni reffid ot .ton od yeht ytilautca ni ,rete

.11 snoitcnuf evisruceR

nI ,++C/C a noitcnuf nac llac flesti . A noitcnuf si dias eb ot evisrucer fi a tnemetats ni ht e dob y of ht e oitcnuf n llac s flesti . ceR oisru n is ht e pr seco s of

ninifed g nihtemos g ni smret fo ,flesti dna si semitemos dellac ralucric noitinifed . A elpmis elpmaxe fo a evisrucer noitcnuf si (rtcaf ), hcihw setupmoc eht

lairotcaf of an egetni r. hT e airotcaf l of a ebmun r n is ht e pr cudo t of la l ht e lohw e rebmun s neewteb 1 dna n. roF ,elpmaxe 3 lairotcaf si 1 x 2 x ,3 ro 6.

htoB (rtcaf ) dna sti evitareti tnelaviuqe era nwohs :ereh ehT evisrucer non noisrev fo (tcaf ) aelc eb dluohs r. tI sesu a pool taht snur morf 1 ot n dna

ylevissergorp seilpitlum hcae rebmun yb eht gnivom .tcudorp ehT noitarepo fo eht evisrucer f (rtca ) si a elttil erom xelpmoc . nehW (rtcaf ) si

dellac htiw na tnemugra fo ,1 eht snruter noitcnuf 1. eht snruter ti ,esiwrehtOpr tcudo fo (rtcaf n- n*)1 . T pxe siht etaulave o r ,noisse (rtcaf ) si dellac htiw n-1.

sihT sneppah litnu n slauqe 1 dna eht llac s ot eht noitcnuf nigeb .gninruter gnitupmoC eht lairotcaf fo ,2 eht tsrif llac ot (rtcaf ) sesuac a ,dnoces evisrucer

llac htiw eht tnemugra fo 1. sihT llac snruter ,1 hcihw si neht deilpitlum yb 2 eht( lanigiro n eulav ). ehT rewsna si neht 2. T gnikrow yr eht hguorht

no lairotcaf 3 fo noitatupmoc ruoy nwo . (Y tresni ot tnaw thgim uo (ftnirp )

Page 26: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 32

stnemetats otni (rtcaf ) ot ees eht level fo hcae llac dna tahw eht etaidemretni srewsna ).era

nehW a oitcnuf n llac s flesti , a en w es t of acol l elbairav s na d retemarap s are detacolla egarots no eht ,kcats dna eht noitcnuf edoc si detucexe morf eht pot

htiw eseht wen elbairav s. A evisrucer llac seod ton ekam a wen eht fo ypocnoitcnuf . ylnO eht seulav gnieb detarepo nopu era new. sA hcae r visruce e

lac l r snrute , ht e lo d l aco l elbairav s dna sretemarap era devomer morf eht kcats dna noitucexe semuser ta eht tniop fo eht noitcnuf llac edisni eht

noitcnuf . evisruceR snoitcnuf dluoc eb dias ot "epocselet" tuo dna .kcab ,netfO evisrucer senituor od ton yltnacifingis ecuder edoc evorpmi ro ezis

azilitu yromem oit n evo r ieht r vitareti e strapretnuoc . ,oslA eht r evisruce noisrev s of som t r senituo yam etucexe a tib rewols naht rieht evitareti

stnelaviuqe esuaceb fo eht daehrevo fo eht detaeper noitcnuf sllac . nI ,tcaf ynam evisrucer ac sll ot a noitcnuf dluoc esuac a kcats nurrevo . esuaceB

egarots rof noitcnuf sretemarap dna lacol selbairav si no eht kcats dna hcae wen llac setaerc a wen ypoc fo eseht ,selbairav eht kcats dluoc eb .detsuahxe

,revewoH uoy ylbaborp lliw ton evah ot yrrow a tuob siht sselnu a evisrucer noitcnuf snur .dliw

ehT niam egatnavda nac uoy taht si snoitcnuf evisrucer ot esu meht ot etaerc

reraelc na d elpmis r noisrev s of areves l smhtirogla . oF r elpmaxe , ht e roskciuQ t htirogla m i areti na ni tnemelpmi ot tluciffid s aw evit y. ,oslA emos ,smelborp

yllaicepse seno detaler ot laicifitra ,ecnegilletni dnel sevlesmeht ot evisrucer snoitulos . llaniF y elpoep emos , mees ot kniht ylevisrucer erom ylisae naht

.ylevitareti nehW gnitirw evisrucer ,snoitcnuf uoy tsum evah a tidnoc lanoi

Page 27: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 42

,tnemetats hcus as an fi , erehwemos ot of rce ht e oitcnuf n to r rute n uohtiw t ht e r visruce e lac l nieb g etucexe d. fI you t'nod , ht e oitcnuf n liw l even r r rute n

cno e oy u lac l ti . nittimO g ht e lanoitidnoc tnemetats si a nommoc rorre nehw gnitirw evisrucer snoitcnuf . esU irp ftn ( ) yllarebil gnirud margorp tnempoleved

os taht uoy nac hctaw tahw si gniog no dna ab tro noitucexe fi uoy ees a .ekatsim

Page 28: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 52

II TINU

STCEJBO DNA SESSALC – I

derevoc scipoT

stcejbO & sessalC – :I ,rotarepo noituloser epocS ,stcejbO ssalC ,noitacificepS ssalC

,srotcurtseD ,srotcurtsnoC ,gnidih ataD ,snoitcnuf rebmem gninifeD ,srebmem sseccA

snoitcnuF ,srebmem atad citatS ,srotcurtsnoc deziretemaraP

TINU - yrammuS 2

,++C nI eht ssalc smrof eht sisab rof tcejbo - detneiro gnimmargorp . ehT ssalc si

desu ot enifed eht erutan fo na ,tcejbo dna ti si s'++C cisab tinu fo

noitaluspacne . sihT retpahc senimaxe sessalc dna stcejbo ni .liated

Page 29: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 62

.1 noitacificepS ssalC

sessalC era detaerc gnisu eht k drowye salc s. A ssalc noitaralced senifed a wen epyt taht sknil edoc dna atad . sihT wen epyt si neht desu ot eralced stcejbo fo taht .ssalc ,suhT a ssalc si a lacigol ,noitcartsba tub na

tcejbo sah lacisyhp ecnetsixe . nI rehto ,sdrow na tcejbo si na natsni ec fo a .ssalc

A ssalc noitaralced si ralimis yllacitcatnys ot erutcurts a . a deifilpmis lareneg mrof fo a ssalc noitaralced saw nwohs . ereH si eht eritne

lareneg mrof fo a ssalc noitaralced taht seod ton tirehni yna rehto .ssalc ssalc ssalc - eman {

etavirp atad dna snoitcnuf ssecca - :reificeps atad dna snoitcnuf ssecca - :reificeps atad dna snoitcnuf

// ... ssecca - :reificeps atad dna snoitcnuf

} tcejbo - ;tsil

ehT tcejbo - tsil is lanoitpo . fI pr ,tnese ti d alce res tcejbo s of ht e ssalc . eH re, a ssecc -s ep c fi i re no si e fo eseht ht r ee ++C k owye r :sd

cilbup etavirp

detcetorp

ssalc eeyolpme { rahc ;]08[eman

elbuod ;egaw :cilbup

diov rahc(emantup ;)n* diov rahc(emanteg ;)n* diov elbuod(egawtup ;)w

elbuod ;)(egawteg ;}

snoitcnuF taht era deralced nihtiw a ssalc era dellac m rebme snoitcnuf . snoitcnuf rebmeM yam ssecca yna tnemele fo eht ssalc fo

hcihw yeht era a trap . sihT sedulcni lla etavirp tnemele s. V taht selbaira dellac era ssalc a fo stnemele era rebmem selbairav ro atad srebmem . ehT(

mret ecnatsni elbairav desu osla si levitcelloC ). y fo tnemele yna , a ssalc nac eb derrefer ot sa a rebmem fo taht .ssalc erehT era a wef snoitcirtser taht

ylppa ot ssalc srebmem . A non - citats rebmem na evah tonnac elbairavezilaitini r. oN rebmem nac eb na tcejbo fo eht ssalc taht si gnieb d deralce .

Page 30: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 72

hguohtlA( a rebmem nac eb a retniop ot eht ssalc taht si gnieb ).deralced oN rebmem nac eb deralced sa otua , retxe n, ro etsiger r. nI ,lareneg uoy

dluohs ekam lla atad srebmem fo a ssalc etavirp ot taht ssalc . sihT si trap fo eht yaw taht aluspacne noit si deveihca . ,revewoH ereht yam eb

snoitautis ni hcihw uoy deen lliw ot ekam eno ro erom selbairav cilbup . roF( ,elpmaxe a ylivaeh desu elbairav yam deen ot eb elbissecca yllabolg

ni redro ot eveihca retsaf nur nehW ).semit a elbairav si ,cilbup ti am y eb dessecca yltcerid yb yna rehto trap fo ruoy pr margo . ehT xatnys rof gnissecca a cilbup atad rebmem si eht emas sa rof gnillac a rebmem :noitcnuf yficepS eht s'tcejbo ,eman eht tod ,rotarepo dna eht elbairav

sihT .eman elpmis margorp setartsulli eht su e fo a cilbup :elbairav

.2 stcejbO ssalC

edulcni# >maertsoi< gnisu ecapseman ;dts

ssalc ssalcym {

:cilbup tni ,i ,j ;k // elbissecca ot eritne margorp

;}

tni )(niam {

ssalcym ,a ;b

i.a = ;001 // ssecca ot ,i ,j dna k si KO j.a = ;4 k.a = i.a * ;j.a

k.b = ;21 // ,rebmemer k.a dna k.b era tnereffid

tuoc << k.a << " " << ;k.b

nruter ;0 }

.3 rotarepo noituloser epocS

onk uoy sA w eht , :: rotarepo sknil a ssalc eman htiw a rebmem eman ni redro otllet eht relipmoc tahw ssalc eht rebmem sgnoleb ot . evewoH r s eht , epoc

noituloser rotarepo sah rehtona detaler :esu ti nac wolla ssecca ot a eman ni na gnisolcne epocs taht si "neddih" yb a lacol noitaralced fo eht emas eman . roF ,elpmaxe redisnoc siht :tnemgarf

Page 31: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 82

tni ;i // labolg i

diov )(f {

tni ;i // lacol i

i = ;01 // sesu lacol i }

sA eht tnemmoc ,stseggus eht tnemngissa i = 01 srefer ot eht lacol i. tuB tahw fi

noitcnuf (f ) sdeen ot ssecca eht labolg noisrev fo i? tI yam od os yb gnidecerp eht i htiw eht :: otarepo r eh nwohs sa , r .e

tni ;i // labolg i diov )(f

{ ni t ;i // lacol i

i:: = ;01 // won srefer ot labolg i

} .4 srebmem sseccA

yB ,tluafed snoitcnuf dna atad deralced nihtiw a ssalc era etavirp ot taht ssalc dna yam eb dessecca ylno yb rehto srebmem fo eht ssalc . ehT

cilbup ssecca reificeps swolla snoitcnuf ro atad ot eb elbissecca ot rehto strap fo ruoy margorp . ehT torp detce ssecca reificeps si dedeen ylno nehw ecnatirehni si .devlovni ecnO an secca s eificeps r ah s eeb n desu , it

r niame s in ef cef t itnu l ehtie r ehtona r secca s reificeps si deretnuocne ro eht dne of eht ssalc noitaralced si .dehcaer

uoY yam egnahc ssecca snoitacificeps sa netfo sa a nihtiw ekil uoyssalc .noitaralced roF ,elpmaxe uoy yam hctiws ot cilbup rof emos

snoitaralced dna neht hctiws kcab ot etavirp iaga n. ehT ssalc noitaralced ni eht wollof gni elpmaxe setartsulli :erutaef siht

.5 srotcurtsnoC

Co tcurtsn ro s era laiceps rebmem snoitcnuf taht era detucexe ew revenehw etaerc wen stcejbo fo a ssalc ehT .epyt boj fo a rotcurtsnoc si ot erusne taht eht srebmem atad fo

hcae tcejbo trats tuo htiw bisnes el laitini .seulav fI a rotcurtsnoc ylno sah eno ,retemarap ereht si a driht yaw ot eulav laitini na ssap ot otcurtsnoc taht r.

roF ,elpmaxe redisnoc gniwollof eht trohs .margorp

edulcni# >maertsoi< gnisu ecapseman ;dts

Page 32: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 92

ssalc X { tni ;a

:cilbup

tni(X )j { a = ;j } tni )(ateg { nruter ;a }

;} tni )(niam

{ X bo = ;99 // sessap 99 ot j

tuoc << ;)(ateg.bo // stuptuo 99 nruter ;0

}

,ereH eht rotcurtsnoc rof X etemarap eno sekat r. yaP laiceps noitnetta ot woh bo si deralced ni (niam ). nI siht mrof fo ilaitini ,noitaz 99 si

yllacitamotua dessap ot eht j retemarap ni eht (X ) otcurtsnoc r. tahT ,si eht noitaralced tnemetats si deldnah yb eht relipmoc sa fi ti erew nettirw ekil

:siht

X bo = ;)99(X

nI ,lareneg yna emit uoy evah a rotcurtsnoc taht seriuqer ylno eno ,tnemugra uoy nac esu rehtie bo (i) ro bo = i ot ezilaitini na tcejbo . ehT nosaer si siht rof taht uoy revenehw etaerc a rotcurtsnoc taht sekat eno ,tnemugra

uoy tnemugra taht fo epyt eht morf noisrevnoc a gnitaerc ylticilpmi osla eraot eht epyt fo eht lc rebmemeR .ssa taht eht evitanretla nwohs ereh seilppa

ylno ot srotcurtsnoc taht etemarap eno yltcaxe evah r.

.6 srotcurtseD enO esoprup fo a rotcurtsnoc si ot edivorp rof eht citamotua noitisiuqca fo a .ecruoser roF

,elpmaxe a rotcurtsnoc thgim etacolla a fub ref ro nepo a .elif gnivaH detacolla eht ecruoser eht ni ,rotcurtsnoc ew deen a gnidnopserroc noitarepo taht yllacitamotua

setacollaed ro sesaeler esiwrehto eht .ecruoser ehT rotcurtsed si a laiceps rebmem noitcnuf taht nac eb desu ot revetahw od ecruoser noitacollaed si .dedeen tI sevres sa eht

tnemelpmoc ot eht srotcurtsnoc eht fo .ssalc nehW a rotcurtseD sI dellaC

ehT rotcurtsed si dellac yllacitamotua revenehw na tcejbo fo sti ssalc si :deyortsed // p stniop ot tluafed detcurtsnoc tcejbo

meti_selaS p* = wen ;meti_selaS {

Page 33: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 03

// wen epocs meti_selaS ;)p*(meti // ypoc rotcurtsnoc seipoc *p otni meti

eteled ;p // rotcurtsed dellac no tcejbo detniop ot by p } // tixe lacol ;epocs rotcurtsed dellac no meti

selbairaV hcus sa eti m era deyortsed yllacitamotua nehw t yeh og tuo fo .epocs ,ecneH ehtrotcurtsed no eti m si nur nehw eht esolc ylruc si nA .deretnuocne tcejbo taht si

yllacimanyd detacolla si deyortsed ylno nehw a retniop gnitniop ot eht tcejbo si teled e d .fI ew od ton teled e a retniop ot a yllacimanyd colla deta ,tcejbo neht eht rotcurtsed si

reven nur no taht ehT .tcejbo tcejbo lliw tsisrep ,reverof gnidael ot a yromem .kaelyna ,revoeroM secruoser desu edisni eht tcejbo lliw osla ton eb .desaeler

.7 srotcurtsnoc deziretemaraP

tI si elbissop ot ssap stnemugra ot srotcurtsnoc . T llacipy y a eseht , r stnemug pleh ezilaitini na tcejbo nehw ti si detaerc . T deziretemarap a etaerc o

otcurtsnoc r ylpmis , dda sretemarap ot ti eht yaw uoy dluow ot yna rehto noitcnuf . nehW uoy enifed dob s'rotcurtsnoc eht y sretemarap eht esu , ot

tcejbo eht ezilaitini . roF ,elpmaxe ereh si a elpmis ssalc taht sedulcni a deziretemarap :rotcurtsnoc

edulcni# >maertsoi< gnisu ecapseman ;dts ssalc ssalcym { tni ,a ;b

:cilbup tni(ssalcym ,i tni )j ;i=a{ };j=b

diov )(wohs tuoc{ << a << " " << };b ;}

i tn )(niam {

ssalcym ,3(bo ;)5 ;)(wohs.bo

nruter ;0 }

ecitoN taht ni eht noitinifed fo (ssalcym ,) eht sretemarap i dna j era laitini evig ot desu seulav ot a dna b.

ehT margorp setartsulli eht tsom nommoc yaw ot yficeps stnemugra nehw eralced uoy na tcejbo taht sesu a deziretemarap rotcurtsnoc .

llacificepS y tnemetats siht , ssalcym ,3(bo ;)4

sesuac na tcejbo dellac bo ot eb detaerc dna stnemugra eht sessap3 dna 4 ot eht i dna j sretemarap fo (ssalcym ). ssap osla yam uoY

aralced fo epyt siht gnisu stnemugra noit :tnemetats

Page 34: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 13

ssalcym bo = ,3(ssalcym ;)4

,revewoH eht tsrif dohtem si eht eno yllareneg ,desu dna siht si eht hcaorppa nekat yb tsom fo eht selpmaxe ni siht koob . llautcA y llams a si ereht ,

ecnereffid lacinhcet neewteb eht owt sepyt fo snoitaralced ht ta setaler ot ypoc srotcurtsnoc . otcurtsnoc deziretemarap a sesu taht elpmaxe rehtona si ereH r. tI

setaerc ssalc a taht serots noitamrofni tuoba yrarbil .skoob

edulcni# >maertsoi< edulcni# >gnirtsc<

gnisu ecapseman ;dts tsnoc tni NI = ;1 tsnoc tni DEKCEHC TUO_ = ;0

ssalc koob { rahc ;]04[rohtua rahc ;]04[eltit

tni ;sutats :cilbup

rahc(koob ,n* rahc ,t* tni ;)s tni )(sutats_teg nruter{ };sutats

diov tni(sutats_tes )s sutats{ = };s diov ;)(wohs

;} rahc(koob::koob ,n* rahc ,t* tni )s

{ ,rohtua(ypcrts ;)n

pcrts ,eltit(y ;)t sutats = ;s

} diov )(wohs::koob

{ tuoc << eltit << " yb " << ;rohtua tuoc << " si ;"

)NI==sutats(fi tuoc << .ni" \ ;"n esle tuoc << .tuo" \ ;"n

} tni )(niam

{ koob ,"niawT"(1b moT" ,"reywaS ;)NI koob ,"ellivleM"(2b yboM" ,"kciD ;)TUO_DEKCEHC

Page 35: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 23

hs.1b ;)(wo ;)(wohs.2b

nruter ;0 }

deziretemaraP srotcurtsnoc era yrev lufesu esuaceb yeht wolla uoy ot diova gnivah ot ekam na lanoitidda noitcnuf llac ylpmis ot ezilaitini eno ro erom selbairav ni na bo j ce t. hcaE noitcnuf llac uoy nac diova sekam ruoy

margorp erom tneiciffe . ,oslA eciton taht eht trohs (sutats_teg ) dna (sutats_tes ) snoitcnuf era denifed ni ,enil nihtiw eht koob ssalc . sihT si a

nommoc ecitcarp nehw gnitirw ++C .smargorp .8 srebmem atad citatS

nehW uoy edecerp a rebmem s'elbairav noitaralced htiw itats c, uoy era gnillet eht relipmoc taht ylno eno ypoc fo taht elbairav lliw tsixe dna taht lla stcejbo fo eht ssalc lliw erahs taht elbairav . ekilnU raluger atad ,srebmem

laudividni seipoc fo a citats rebmem elbairav era ton edam rof hcae tcejbo . oN tam ret woh ynam stcejbo fo a ssalc era ,detaerc ylno eno ypoc fo a citats

atad rebmem stsixe . ,suhT lla stcejbo fo taht ssalc esu taht emas elbairav . llA citats selbairav era dezilaitini ot orez erofeb eht tsrif tcejbo c si r .detae

nehW uoy eralced a citats ad at rebmem nihtiw a ,ssalc uoy era ton gninifed ti . tahT( ,si uoy era ton gnitacolla egarots rof ).ti ,daetsnI uoy tsum

edivorp a labolg noitinifed rof ti ,erehwesle edistuo eht ssalc . sihT si enod yb gniralceder eht citats elbairav gnisu eht epocs r itulose no rotarepo ot yfitnedi

eht salc s to cihw h it sgnoleb . sihT sesuac s egarot for ht e lbairav e to be detacolla . ,rebmemeR( a ssalc oitaralced n is lpmis y a acigol l taht tcurtsnoc

tilaer lacisyhp evah ton seod y ). T a fo tceffe dna egasu eht dnatsrednu ocitats d ebmem ata r :margorp siht redisnoc ,

edulcni# >maertsoi< gnisu ecapseman ;dts ssalc derahs {

citats tni ;a tni ;b

:cilbup diov tni(tes ,i tni )j ;i=a{ };j=b diov ;)(wohs

} ; tni ;a::derahs // enifed a

diov )(wohs::derahs {

tuoc << sihT" si citats :a " << ;a tuoc << "\ sihTn si non - citats :b " << ;b tuoc << "\ ;"n

}

Page 36: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 33

tni )(niam {

derahs ,x ;y ,1(tes.x ;)1 // tes a ot 1

;)(wohs.x ,2(tes.y ;)2 // egnahc a ot 2

;)(wohs.y ;)(wohs.x */ ,ereH a sah neeb degnahc rof htob x dna y

esuaceb a si derahs yb htob stcejbo . /* r nrute ;0

} sihT margorp syalpsid eht gniwollof tuptuo nehw .nur

sihT si citats :a 1 sihT si non - citats :b 1 sihT si citats :a 2 sihT si non - citats :b 2 sihT si citats :a 2 sihT si non - citats :b 1

.9 snoitcnuF rebmeM citatS rebmeM snoitcnuf yam osla eb ralced de sa itats c. erehT era lareves

snoitcirtser decalp no citats rebmem snoitcnuf . yehT yam ylno yltcerid refer ot rehto citats srebmem fo eht ssalc . fO( esruoc , abolg l noitcnuf s na d tad a am y be

essecca d by tats ic rebmem itcnuf ).sno A citats rebmem noitcnuf d seo ton evah a siht etniop r.

erehT tonnac eb a citats dna a non - citats noisrev fo eht emas noitcnuf . A citats rebmem noitcnuf yam ton eb lautriv . F llani y, eht y onnac t be alced red as

noc st ro v elitalo . gniwolloF si a ylthgils dekrower noisrev fo eht derahs -ecruoser margorp eht morf suoiverp noitces . ecitoN taht (ecruoser_teg ) si won deralced sa itats c. sA eht margorp sulli setart , _teg ecruoser ( ) yam eb dellac

rehtie yb ,flesti yltnednepedni fo yna tcejbo , yb gnisu eht ssalc eman dna eht epocs noituloser po ,rotare ro ni noitcennoc htiw na tcejbo

edulcni# >maertsoi< gnisu ecapseman ;dts ssalc lc {

citats tni ;ecruoser :cilbup citats tni ;)(ecruoser_teg

diov )(ecruoser_eerf { ecruoser = ;0 } ;}

Page 37: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 43

tni ;ecruoser::lc // enifed ecruoser tni )(ecruoser_teg::lc

{ (fi )ecruoser nruter ;0 // ecruoser ydaerla ni esu

esle { ecruoser = ;1

nruter ;1 // ecruoser detacolla ot siht tcejbo }

} tni )(niam

{ lc ,1bo ;2bo */ )(ecruoser_teg si citats os yam eb dellac tnednepedni

fo yna tcejbo . /* ))(ecruoser_teg::lc(fi tuoc << 1bo" sah ecruoser \ ;"n ))(ecruoser_teg::lc!(fi tuoc << 2bo" deined ecruoser \ ;"n

;)(ecruoser_eerf.1bo ))(ecruoser_teg.2bo(fi // nac llits llac gnisu tcejbo xatnys

tuoc << 2bo" nac won esu ecruoser \ ;"n nruter ;0 }

llautcA y , citats rebmem snoitcnuf evah detimil ppa ,snoitacil tub eno doog esu rof meht si ot "ezilaitinierp" etavirp citats atad erofeb yna tcejbo yllautca si

detaerc . roF ,elpmaxe siht si a yltcefrep dilav ++C :margorp edulcni# >maertsoi<

gnisu ecapseman ;dts ssalc epyt_citats {

citats tni ;i :cilbup

ats cit diov tni(tini )x i{ = };x diov )(wohs tuoc{ << };i

;} tni ;i::epyt_citats // enifed i tni )(niam

{ // tini citats atad erofeb tcejbo noitaerc

;)001(tini::epyt_citats epyt_citats ;x

;)(wohs.x // syalpsid 001 nruter ;0 }

Page 38: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 53

TINU – III

STCEJBO DNA SESSALC – II

derevoc scipoT

stcejbO & sessalC – :II ,stcejbo gninruteR ,stnemugra sa stcejbo gnissaP ,snoitcnuf dneirF

snoitcnuf cireneG ,srotcurtsnoc ypoC ,stcejbo ot sretnioP ,stcejbo cimanyD ,stcejbo fo syarrA

u gnidaolrevo rotarepO snoitacilppA ,sessalc dna ,+ sa hcus snoitcnuf dneirf gnis - erp , -

tsop ,tnemercni - .>> ,<< gnidaolrevo ,.cte ] [ ,tnemercni

TINU - yrammuS 3 nI traP ,enO sretniop dna syarra erew denimaxe sa yeht etaler ot s'++C

tliub - ni epyt s. ,ereH yeht era dessucsid evitaler ot stcejbo . sihT hc retpa osla

skool ta a erutaef detaler ot eht retniop dellac a cnerefer e. ehT retpahc

sedulcnoc htiw na noitanimaxe fo s'++C cimanyd noitacolla .srotarepo

.1 snoitcnuf dneirF

tI si elbissop ot tnarg a rebmemnon noitcnuf ssecca ot eht etavirp srebmem fo a salc yb s gnisu a neirf d. A dneirf noitcnuf sah ssecca ot lla etavirp dna detcetorp

srebmem fo eht ssalc rof hcihw ti si a neirf d. T alced o r a e dneirf ,noitcnufp sti edulcni r epytoto nihtiw eht ,ssalc gnidecerp ti htiw eht drowyek neirf d.

redisnoC :margorp siht

edulcni# >maertsoi< gnisu ecapseman ;dts ssalc ssalcym {

tni ,a ;b :cilbup

dneirf tni ssalcym(mus ;)x diov tni(ba_tes ,i tni ;)j ;}

diov tni(ba_tes::ssalcym ,i tni )j { a = ;i b = ;j }

Page 39: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 63

// :etoN )(mus si ton a rebmem noitcnuf fo yna .ssalc tni ssalcym(mus )x

{ */ esuaceB )(mus si a dneirf fo ,ssalcym ti nac

yltcerid ssecca a dna b. /* nruter a.x + ;b.x

}

tni )(niam {

ssalcym ;n

,3(ba_tes.n ;)4 tuoc << ;)n(mus nruter ;0

} nI siht ,elpmaxe eht (mus ) noitcnuf si ton a rebmem fo salcym s. evewoH r ti ,

h llits sa lluf ssecca ot sti etavirp srebmem . ,oslA eciton taht (mus ) si dellac tuohtiw eht esu otarepo tod eht fo r. esuaceB ti si ton a rebmem ,noitcnuf ti seod

ton deen ot eb ti ,deedni( yam ton )eb deifilauq htiw na s'tcejbo .eman .2 tnemugra sa stcejbo gnissaP s

stcejbO yam eb dessap ot snoitcnuf ni tsuj eht emas yaw taht yna rehto epyt elbairav fo nac . stcejbO era dessap ot snoitcnuf hguorht eht eht fo esu

dradnats llac - yb - eulav msinahcem . hguohtlA eht gnissap fo stcejbo si ,drawrofthgiarts emos rehtar tcepxenu de stneve rucco taht etaler ot

srotcurtsnoc dna srotcurtsed . T dnatsrednu o hw y trohs siht redisnoc ,.margorp

// gnissaP na tcejbo ot a .noitcnuf >maertsoi< ecapseman ;dts

ssalc ssalcym { ;i

:cilbup tni(ssalcym ;)n ;)(ssalcym~

diov tni(i_tes )n { ;n=i } ni t )(i_teg { nruter ;i } ;}

tni(ssalcym::ssalcym )n

Page 40: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 73

{ i = ;n

tuoc << gnitcurtsnoC" " << i << "\ ;"n }

)(ssalcym~::ssalcym {

tuoc << gniyortseD" " << i << "\ ;"n }

diov ssalcym(f ;)bo

)(niam ssalcym

;)o(f tuoc << tuoc <<

nruter ;0

}

diov ssalcym(f )bo {

;)2(i_tes.bo

tuoc << sihT" si lacol :i " << ;)(i_teg.bo tuoc << "\ ;"n

}

sihT margorp secudorp siht :tuptuo gnitcurtsnoC 1

sihT si lacol :i 2 gniyortseD 2

sihT si i ni :niam 1 gniyortseD 1

sA eht tuptuo ,swohs ereht si eno llac ot eht ,rotcurtsnoc cihw h srucco nehw o si cr ni detae (niam ) a ereht tub , r e owt otcurtsed eht ot sllac r. s'teL

ees yhw siht si eht .esac nehW na tcejbo si dessap ot a ,noitcnuf a ypoc fo taht tcejbo si edam dna( siht ypoc emoceb s ht e etemarap r in ht e )noitcnuf . ihT s naem s aht t a en w cejbo t emoc s tni o cnetsixe e. nehW eht noitcnuf

,setanimret eht ypoc fo eht tnemugra ,.e.i( eht )retemarap si deyortsed . sihT

)(i_teg.o << "\ ;"n

Page 41: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 83

sesiar owt latnemadnuf :snoitseuq ,tsriF si eht s'tcejbo rotcurtsnoc dellac nehw eht ypoc si ?edam ,dnoceS si eht s'tcejbo sed rotcurt dellac nehw eht ypoc am srewsna ehT ?deyortsed si y .uoy esirprus ,tsrif ta ,

nehW a ypoc fo na tnemugra si edam gnirud a noitcnuf ,llac eht lamron rotcurtsnoc si ton ellac d. ,daetsnI eht s'tcejbo ypoc rotcurtsnoc si dellac . A

ypoc rotcurtsnoc enifed s woh a ypoc fo na tcejbo si edam . uoy nac ylticilpxe enifed a ypoc rotcurtsnoc rof a ssalc taht uoy etaerc . ,revewoH fi a ssalc

seod ton ylticilpxe enifed a ypoc ,rotcurtsnoc sa si eht esac ,ereh neht ++C sedivorp eno yb tluafed . ehT ed luaf t poc y tsnoc ru otc r cr etae s a siwtib e

aht( t si , lacitnedi ) poc y of ht e tcejbo . hT e r nosae a esiwtib ypoc si edam is sae y to natsrednu d if oy u niht k uoba t ti . cniS e a lamron rotcurtsnoc si desu ot

ezilaitini emos tcepsa fo na ,tcejbo ti tsum ton eb dellac ot ekam a ypoc of na ydaerla gnitsixe tcejbo . hcuS a llac dluow retla eht stnetnoc fo eht .tcejbo

nehW gnissap na tcejbo ot a ,noitcnuf uoy tnaw ot esu eht tnerruc etats fo eht ,tcejbo ton sti laitini .etats ,revewoH nehw eht noitcnuf setanimret dna eht ypoc fo eht tcejbo desu sa na ar tsed si tnemug r rotcurtsed eht ,deyo si

ellac d. sihT si yrassecen esuaceb eht tcejbo sah enog tuo fo epocs . sihT si yhw eht gnidecerp margorp dah owt sllac ot eht .rotcurtsed ehT tsrif saw

hw en ht e etemarap r to (f ) tnew tuo - fo - epocs . hT e oces nd is ehw n o i edisn (niam ) saw deyortsed nehw eht margorp .dedne

oT :ezirammus nehW a ypoc fo na tcejbo si na sa desu eb ot detaerca ot tnemugra ,noitcnuf eht lamron rotcurtsnoc si ton dellac . ,daetsnI eht

tluafed ypoc rotcurtsnoc tib a sekam - yb - nedi tib poc lacit y. ,revewoH nehw eht ypoc si deyortsed yllausu( yb gniog tuo fo epocs nehw eht noitcnuf

,)snruter eht rotcurtsed si .dellac suaceB e ht e luafed t poc y tsnoc r otcu r cr etae s an caxe t tacilpud e of ht e lanigiro , i t nac , at semit , be a uos rce of tr elbuo . evE n guoht h tcejbo s a er essap d to noitcnuf s b y naem s of ht e

amron l lac l- yb - ulav e etemarap r nissap g sinahcem m hcihw , in roeht ,y stcetorp dna setalusni eht gnillac ,tnemugra ti si llits elbissop rof a edis

tceffe ot rucco taht yam ,tceffa eht ,egamad neve ro tcejbo desu sa na tnemugra . roF ,elpmaxe fi na cejbo t esu d as an ar nemug t etacolla s

romem y na d fr ee s aht t romem y ehw n it is ,deyortsed neht sti lacol ypoc edisni eht noitcnuf lliw eerf eht emas yromem nehw sti rotcurtsed si dellac .

sihT lliw evael eht iro lanig tcejbo degamad dna ylevitceffe .sselesu .3 stcejbo gninruteR

A ellac eht ot tcejbo na nruter yam noitcnuf r. si siht ,elpmaxe roF a dilav ++C :margorp // gninruteR stcejbo morf a .noitcnuf

edulcni# >maertsoi< gnisu ecapseman ;dts ssalc ssalcym {

tni ;i

Page 42: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 93

:cilbup diov tni(i_tes )n { ;n=i }

tni )(i_teg { nruter ;i } ;}

ssalcym ;)(f // nruter tcejbo fo epyt ssalcym tni )(niam

{ ssalcym ;o

o = ;)(f tuoc << )(i_teg.o << "\ ;"n nruter ;0

} ssalcym )(f

{ ssalcym ;x

;)1(i_tes.x nruter ;x

}

nehW na tcejbo si ruter den yb a ,noitcnuf a yraropmet tcejbo si yllacitamotua detaerc taht eulav nruter eht sdloh . tI si siht tcejbo taht si

yllautca denruter yb eht oitcnuf n. retfA eht eulav sah neeb ,denruter siht tcejbo si deyortsed . ehT noitcurtsed

fo siht yraropmet tcejbo m ya esuac detcepxenu edis stceffe ni emos snoitautis . roF ,elpmaxe fi eht tcejbo denruter yb eht noitcnuf sah a rotcurtsed taht seerf yllacimanyd detacolla ,yromem taht yromem lliw eb

deerf neve hguoht eht tcejbo taht si gniviecer eht nruter eulav si llits gnisu ti .

.4 stcejbo fo syarrA

nI ,++C ti si elbissop ot evah syarra fo stcejbo . ehT xatnys rof gniralced dna gnisu na tcejbo yarra si yltcaxe eht emas sa ti si rof yna rehto epyt fo

yarra . roF ,elpmaxe siht margorp sesu a eerht - tnemele yarra fo :stcejbo i# edulcn >maertsoi<

gnisu ecapseman ;dts ssalc lc {

tni ;i :cilbup

diov tni(i_tes )j { ;j=i }

Page 43: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 04

tni )(i_teg { nruter ;i } ;} tni )(niam

{ lc ;]3[bo tni ;i

;0=i(rof ;3<i )++i ;)1+i(i_tes.]i[bo ;0=i(rof ;3<i )++i

tuoc << )(i_teg.]i[bo << "\ ;"n nruter ;0

}

sihT margorp syalpsid eht srebmun 1, 2, dna 3 no fI .neercs eht a ssalc senifed a deziretemarap ,rotcurtsnoc uoy na ni tcejbo hcae ezilaitini yam

yarra yb gniyficeps na noitazilaitini ,tsil tsuj ekil uoy od rof rehto sepyt fo .syarra ,revewoH eht tcaxe rof m of ht e oitazilaitini n sil t liw l be ediced d by

ht e ebmun r of sretemarap deriuqer yb eht s'tcejbo srotcurtsnoc . roF stcejbo esohw srotcurtsnoc ylno evah eno ,retemarap uoy nac ylpmis yficeps a tsil

fo laitini ,seulav gnisu eht lamron yarra - noitazilaitini xatnys . sA hcae tnemele ni eht yarra si ,detaerc a eulav morf eht tsil si dessap ot eht

s'rotcurtsnoc retemarap . roF ,elpmaxe ereh si a ylthgils tnereffid noisrev fo eht gnidecerp margorp taht sesu na :noitazilaitini

edulcni# >maertsoi< gnisu ecapseman ;dts

alc ss lc { tni ;i

tni )(i_teg nruter ;i } ;} tni )(niam

{ lc ]3[bo = ,1{ ,2 ;}3 // srezilaitini tni ;i

;0=i(rof ;3<i )++i tuoc << )(i_teg.]i[bo << "\ ;"n nruter ;0

}

:cilbup c tni(l )j { ;j=i } // rotcurtsnoc

{

Page 44: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 14

sA ,erofeb siht margorp syalpsid eht srebmun 1, 2, dna 3 no .neercs eht,yllautcA eht tini noitazilai xatnys nwohs ni eht gnidecerp margorp si dnahtrohs rof siht regnol :mrof

lc ]3[bo = { ,)1(lc ,)2(lc )3(lc ;}

,ereH eht rotcurtsnoc rof lc lticilpxe dekovni si y. fO ,esruoc eht trohs

mrof desu ni margorp eht si erom nommoc . ehT trohs mrof skrow esuaceb fo eht citamotua noisrevnoc taht seilppa ot srotcurtsnoc gnikat ylno eno

tnemugra . ,suhT eht trohs mrof nac ylno eb desu ot ezilaitini tcejbo syarra esohw srotcurtsnoc ylno eriuqer eno ar .tnemug fI na rotcurtsnoc s'tcejbo

ugra erom ro owt seriuqer regnol eht esu ot evah lliw uoy ,stnem noitazilaitini mrof . roF ,elpmaxe

edulcni# >maertsoi<

gnisu ecapseman ;dts ssalc lc {

tni ;h tni ;i

:cilbup tni(lc ,j tni )k { ;j=h ;k=i } // rotcurtsnoc htiw 2 sretemarap

tni )(i_teg nruter{ };i tni )(h_teg nruter{ };h

;} tni )(niam

{ lc ]3[bo = {

,1(lc ,)2 // ezilaitini ,3(lc ,)4 ,5(lc )6

;}

tni ;i ;0=i(rof ;3<i )++i {

tuoc << ;)(h_teg.]i[bo tuoc << ," ;" tuoc << )(i_teg.]i[bo << "\ ;"n

} nruter ;0

}

Page 45: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 24

eH r ,e lc s' rotcurtsnoc sah owt sretemarap ,dna ,erofereht riuqer se owt stnemugra . sihT snaem taht the s nahtroh d oitazilaitini n amrof t onnac t be

esu d na d ht e nol g mrof , nwohs ni eht ,elpmaxe tsum eb .deyolpme .5 stcejbo cimanyD

++C swolla uoy ot etareneg a laiceps epyt fo retniop taht "stniop" yllacireneg ot a rebmem fo a ,ssalc ton ot a cificeps ecnatsni fo taht rebmem

ni na tcejbo . sihT tros fo retniop si dellac a retniop ot a ssalc rebmem ro a retniop - ot - ebmem r, rof trohs . A retniop ot a rebmem si ton eht emas sa a lamron ++C retniop . ,daetsnI a retniop ot a rebmem vorp sedi ylno na tesffo

otni na tcejbo fo eht s'rebmem ssalc ta hcihw taht rebmem nac eb dnuof . ecniS rebmem sretniop era ton eurt ,sretniop eht . dna –> tonnac eb deilppa

ot meht . oT ssecca a rebmem fo a ssalc nevig a retniop ot ,ti uoy tsum esu eht laiceps p etnio r- ot - srotarepo rebmem .* dna –>*. riehT boj si ot wolla uoy ot ssecca a rebmem fo a ssalc nevig a retniop ot taht .rebmem

++C sedivorp owt cimanyd noitacolla :srotarepo wen dna teled e. esehT era srotarepo

desu ot etacolla dna eerf yromem ta nur emit . cimanyD noitacolla si na tnatropmi fo omla st la l r lae - lrow d pr smargo . As enialpxe d in raP t enO ,

+C + sla o troppus s cimanyd yromem noitacolla ,snoitcnuf dellac (collam ) dna (eerf ). esehT era dedulcni rof eht ekas fo ytilibitapmoc htiw C.

,revewoH rof ++C ,edoc uoy dluohs esu eht wen dna eteled srotarepo esuaceb yeht evah lareves .segatnavda

ehT wen rotarepo setacolla yromem dna snruter a retniop ot eht trats fo ti . ehT eteled rotarepo seerf yromem ylsuoiverp detacolla gnisu en w. ehT

lareneg smrof fo wen na d eteled era nwohs :ereh rav_p = wen epyt ; eteled av_p r;

eH r ,e rav_p si a retniop elbairav taht seviecer a retniop ot yromem taht si egral hguone ot dloh na meti fo epyt epyt .

ecniS eht paeh si ,etinif ti nac emoceb detsuahxe . fI ereht si tneiciffusni iava yromem elbal ot llif na oitacolla n r tseuqe , eht n wen lliw f ia l na d a

a_dab oll c xe oitpec n liw l eb areneg det . sihT noitpecxe is enifed d in ht e edaeh r wen< >. Y ruo pr margo dluohs ah eldn siht noitpecxe dna ekat

fi noitca etairporppa a eruliaf srucco . If iht s e oitpecx n is on t eldnah d by uoy r pr margo , eht n ruoy pr margo w li l be etanimret d. ehT snoitca fo wen no

eruliaf sa tsuj debircsed era deificeps yb dradnatS ++C . ehT elbuort si taht ton lla ,srelipmoc yllaicepse redlo ,seno lliw evah detnemelpmi wen ni

ailpmoc ecn htiw dradnatS ++C . nehW ++C saw tsrif ,detnevni wen denruter llun no uliaf re. taht hcus degnahc saw siht ,retaL wen desuac na noitpecxe no eruliaf . llaniF y, ti saw dediced taht a wen eruliaf lliw etareneg

na noitpecxe yb ,tluafed tub taht a llun iop etn r luoc d be r enrute d daetsni , as an noitpo . suhT , en w ah s eeb n etnemelpmi d id f ltneref y id ta , f ef r tne

utcafunam relipmoc yb ,semit r sre . hguohtlA lla srelipmoc lliw yllautneve tnemelpmi wen ni ecnailpmoc htiw dradnatS ,++C yltnerruc eht ylno yaw

Page 46: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 34

ot wonk eht p esicer noitca fo wen no eruliaf si ot kcehc ruoy s'relipmoc .noitatnemucod

ecniS dradnatS ++C seificeps taht wen setareneg na noitpecxe no ,eruliaf siht si eht yaw eht edoc ni siht koob si nettirw . fI ruoy relipmoc seldnah na

noitacolla eruliaf yltnereffid , uoy lliw deen ot ekam .segnahc etairporppa eht ereH si a margorp taht setacolla yromem ot dloh na :regetni

edulcni# >maertsoi< edulcni# >wen<

gnisu ecapseman ;dts tni )(niam

{ tni ;p* yrt {

p = wen ;tni // etacolla ecaps rof na tni colla_dab( )ax {

<< " noitacollA eruliaF \ ;"n nruter ;1

} p* = ;001

tuoc << tA" " << p << " ;" tuoc << si" eht eulav " << p* << "\ ;"n

eteled ;p nruter ;0

}

sihT margorp sngissa ot p na sserdda ni eht paeh taht si egral hguone ot dloh egetni na r. tI neht sngissa taht yromem ht e eulav 001 dna syalpsid eht

stnetnoc fo eht yromem no eht neercs . llaniF y yllacimanyd eht seerf ti ,romem detacolla y. ebmemeR r, fi ruoy relipmoc stnemelpmi wen hcus taht ti

snruter llun tsum uoy ,eruliaf no egnahc margorp gnidecerp ehtletairporppa y. ehT eteled rotarepo tsum eb desu ylno htiw a dilav retniop

ylsuoiverp detacolla yb nisu g en w. nisU g na y ehto r pyt e of etniop r tiw h teled e is enifednu d na d liw l somla t ylniatrec esuac suoires ,smelborp hcus

sa a metsys .hsarc hguohtlA wen dna eteled mrofrep nuf snoitc ralimis ot (collam ) dna (eerf ), yeht evah es arev l segatnavda . iF tsr , new yllacitamotua

acolla et s guone h romem y to loh d na tcejbo fo eht ficeps ei d epyt . Y uo od ton deen ot su e ht e ezis of otarepo r. suaceB e ht e ezis si detupmoc ua llacitamot y, it

mile etani s na y tilibissop y of r re ror in iht s r age rd. ,dnoceS en w tua llacitamo y r nrute s a etniop r of ht e eificeps d epyt . uoY t'nod deen ot esu na ticilpxe

epyt tsac sa uoy od nehw gnitacolla yromem yb gnisu (collam ). llaniF y ,htob wen na d teled e nac eb aolrevo ,ded gniwolla uoy ot cr etae imotsuc ez d

} hctac tuoc

Page 47: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 44

oitacolla n .smetsys hguohtlA ereht si on lamrof elur taht setats ,siht ti si tseb ton ot xim wen

dna eteled htiw (collam ) dna (eerf ) ni eht emas margorp . erehT si on eetnaraug taht yeht era yllautum .elbitapmoc

.6 ioP stcejbo ot sretn

suJ t as oy u ac n vah e retniop s to ehto r epyt s of selbairav , oy u ac n vah e retniop s t o tcejbo s. nehW gnissecca srebmem fo a ssalc nevig a retniop ot na ,tcejbo esu eht worra (– )> rotarepo daetsni fo eht rotarepo tod . ehT txen margorp artsulli set woh ot ssecca na tcejbo nevig a retniop ot :ti

edulcni# >maertsoi<

gnisu ecapseman ;dts

ssalc lc { tni ;i

:cilbup tni(lc )j { ;j=i }

tni )(i_teg { nruter ;i } ;} tni )(niam

{ lc ,)88(bo ;p*

p = ;bo& // teg sserdda fo bo tuoc << p- ;)(i_teg> // esu -> ot llac )(i_teg nruter ;0

}

sA uoy onk w, nehw a retniop si cni r ,detneme ti stniop ot eht txen tnemele fo ti s .epyt roF ,elpmaxe na i egetn r etniop r liw l niop t to ht e xen t egetni r. In

lareneg , la l etniop r citemhtira si evitaler ot eht esab epyt fo eht tniop re . tahT( ,si ti si evitaler ot eht epyt fo atad taht eht retniop si deralced sa

gnitniop ).ot ehT emas si eurt fo sretniop ot .stcejbo roF ,elpmaxe siht margorp sesu a retniop ot ssecca lla eerht stnemele fo yarra bo retfa gnieb dengissa ob s' gnitrats dda :sser

edulcni# >maertsoi<

gnisu ecapseman ;dts ssalc lc {

tni ;i :cilbup

Page 48: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 54

)(lc { ;0=i } tni(lc )j { ;j=i }

tni )(i_teg { nruter ;i } ;} tni )(niam

{ lc ]3[bo = ,1{ ,2 ;}3 lc ;p* tni ;i

p = ;bo // teg trats fo yarra ;0=i(rof ;3<i )++i {

tuoc << p- )(i_teg> << "\ ;"n ;++p // tniop ot txen tcejbo

} nruter ;0

} uoY nac ngissa eht sserdda fo a cilbup rebmem fo na tcejbo ot a retniop

dna neht ssecca taht rebmem yb retniop eht gnisu . roF ,elpmaxe siht si a dilav ++C margorp taht syalpsid eht rebmun 1 no eht :neercs

edulcni# >maertsoi<

gnisu ecapseman ;dts ssalc lc {

:cilbup tni ;i

tni(lc )j { ;j=i } ;} tni )(niam

{ lc ;)1(bo tni ;p*

p = ;i.bo& // teg sserdda fo i.bo tuoc << ;p* // ssecca i.bo aiv p nruter ;0

} esuaceB p egetni na ot gnitniop si r a sa deralced si ti , etniop regetni n r. tI

si tnavelerri taht i si a rebmem fo bo ni siht .noitautis .7 srotcurtsnoc ypoC

Page 49: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 64

enO fo eht erom tnatropmi smrof fo na dedaolrevo rotcurtsnoc si eht otcurtsnoc ypoc r . gninifeD a ypoc rotcurtsnoc nac pleh uoy tneverp smelborp

taht thgim co ruc nehw ehtona ezilaitini ot desu si tcejbo eno r. s'teL nigeb yb gnitatser eht melborp rotcurtsnoc ypoc eht taht si dengised ot .evlos yB

ehtona ezilaitini ot desu si tcejbo eno nehw ,tluafed r a smrofrep ++C ,poc esiwtib y. tahT ,si na lacitnedi ypoc fo ht e gnizilaitini tcejbo si detaerc ni

eht tegrat .tcejbo hguohtlA siht si yltcefrep etauqeda rof ynam sesac — dna yllareneg

yltcaxe tahw tnaw uoy ot neppah — ereht era snoitautis ni hcihw a esiwtib ypoc dluohs ton eb .desu enO fo eht tsom nommoc si nehw na cejbo t

setacolla yromem nehw ti si detaerc . roF ,elpmaxe emussa a ssalc dellac ssalCyM taht setacolla yromem rof hcae tcejbo nehw ti si ,detaerc dna na

tcejbo A fo taht ssalc . sihT snaem taht A sah ydaerla detacolla sti romem y. ehtruF r taht emussa , A si desu ot ezilaitini B, sa :ereh nwohs

ssalCyM B = ;A

fI a esiwtib ypoc si ,demrofrep neht B lliw eb na tcaxe ypoc fo A. sihT snaem taht B lliw eb gnisu eht emas eceip fo detacolla yromem taht A si ,gnisu daetsni fo gnitacolla sti nwo . ,ylraelC siht si ton eht ised der emoctuo .

roF ,elpmaxe fi ssalCyM sedulcni a rotcurtsed taht seerf eht ,yromem neht eht emas eceip fo yromem lliw eb deerf eciwt nehw A dna B era !deyortsed

ehT emas epyt fo melborp nac rucco ni owt lanoitidda :syaw ,tsrif nehw a ypoc na fo tcejbo si am ed nehw ti si dessap sa na tnemugra ot a ;noitcnuf

,dnoces nehw a yraropmet tcejbo si detaerc sa a a morf eulav nruternoitcnuf . ,rebmemeR yraropmet stcejbo era yllacitamotua detaerc ot dloh

eht nruter eulav fo a noitcnuf dna yeht yam osla eb detaerc ni ec niatr rehto .secnatsmucric

oT evlos eht epyt fo melborp tsuj ,debircsed ++C swolla uoy ot etaerc a ypoc ,rotcurtsnoc hcihw eht relipmoc sesu nehw eno tcejbo sezilaitini

rehtona . ,suhT ruoy poc esiwtib tluafed eht sessapyb rotcurtsnoc ypoc y. ehT tsom nommoc lareneg mrof fo a ypoc rotcurtsnoc si

emanssalc tsnoc( emanssalc &o) { // ydob fo rotcurtsnoc

}

eH r ,e o si a ecnerefer ot eht tcejbo no eht thgir edis fo eht noitazilaitini . tI si elbissimrep for a poc y tsnoc r otcu r to vah e anoitidda l retemarap s as

nol g as eht y vah e luafed t ar mug e stn denifed of r meht . evewoH r, ni lla sesac eht tsrif rap etema r sum t be a r efe r ecne ot eht tcejbo gniod eht

.gnizilaitini tI si tnatropmi ot dnatsrednu taht ++C senifed owt tcnitsid sepyt fo

snoitautis ni bo eno fo eulav eht hcihw rehtona ot nevig si tcej . ehT tsrif si tnemngissa . ehT dnoces si ,noitazilaitini hcihw nac rucco yna fo eerht :syaw

■ nehW eno tcejbo ylticilpxe sezilaitini ,rehtona hcus sa ni a noitaralced

■ nehW a ypoc fo na tcejbo si edam ot eb dessap ot a noitcnuf

■ lnommoc tsom( detareneg si tcejbo yraropmet a nehW y nruter a sa ,

Page 50: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 74

)eulav

ehT ypoc rotcurtsnoc seilppa ylno ot ilaitini snoitaz . roF ,elpmaxe gnimussa a ssalc dellac salcym s, dna taht y si na tcejbo fo epyt salcym s,

hcae fo eht gniwollof stnemetats sevlovni .noitazilaitini

ssalcym x = ;y // )y(cnuf ; //

y = ;)(cnuf //

gniwolloF si na elpmaxe ehw re na e ilpx ic t poc y c tsno r otcu r is dedeen . ihT s pr margo setaerc a yrev detimil "efas" regetni yarra epyt taht stneverp yarra seiradnuob morf b nie g revo r nu . garotS e of r cae h arra y is etacolla d

by ht e su e of en w, na d a retniop ot eht yromem si deniatniam nihtiw hcae yarra cejbo .t

*/ sihT margorp setaerc a "efas" yarra ssalc . ecniS ecaps

rof eht yarra si detacolla gnisu ,wen a ypoc rotcurtsnoc si dedivorp ot etacolla yromem nehw eno yarra tcejbo si

desu ot ezilaitini .rehtona /*

edulcni# >maertsoi< edulcni# >wen< edulcni# ldtsc< >bi

gnisu ecapseman ;dts

ssalc yarra { tni ;p* tni ;ezis

:cilbup tni(yarra )zs {

yrt { p = wen ;]zs[tni } hctac colla_dab( )ax {

tuoc << noitacollA" eruliaF \ ;"n ;)ERULIAF_TIXE(tixe

} ezis = ;zs

} )(yarra~ { eteled ][ ;p }

// ypoc rotcurtsnoc

gnizilaitini x a retemarap

y ylticilpxe y dessap sa

y gniviecer a ,yraropmet nruter tcejbo

Page 51: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 84

tsnoc(yarra yarra ;)a&

diov tni(tup ,i tni )j { 0=>i(fi && )ezis<i ]i[p = ;j

} tni tni(teg )i {

nruter ;]i[p } ;} // ypoC rotcurtsnoC

tsnoc(yarra::yarra yarra )a& { tni ;i yrt {

p = wen ;]ezis.a[tni } hctac colla_dab( )ax {

tuoc << noitacollA" eruliaF \ ;"n F_TIXE(tixe ;)ERULIA

} ;0=i(rof ;ezis.a<i )++i ]i[p = ;]i[p.a

} tni )(niam

{ yarra ;)01(mun

tni ;i ;0=i(rof ;01<i )++i ;9=i(rof ;0=>i i -- )

uoc t "\ ;"n // etaerc rehtona yarra dna ezilaitini htiw mun

yarra ;)mun(x // sekovni ypoc rotcurtsnoc ;0=i(rof ;01<i )++i tuoc << ;)i(teg.x

nruter ;0

}

s'teL kool ylesolc ta tahw sneppah ehw n mun is esu d to zilaitini e x ni eht tnemetats

yarra ;)mun(x // sekovni ypoc rotcurtsnoc ehT ypoc rotcurtsnoc si ,dellac yromem rof eht wen yarra si detacolla

dna derots ni .x p , dna eht etnoc stn fo mun era deipoc ot x arra s' y. siht nIaw y , x dna mun evah syarra taht niatnoc eht emas ,seulav tub hcae yarra si

,i(tup.mun

tuoc << ;)i(teg.mun

<<

Page 52: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 94

etarapes dna tcnitsid . tahT( ,si p.mun dna p.x od ton tniop ot eht emas eceip fo ).yromem fI eht ypoc rotcurtsnoc dah ton neeb ,detaerc t eh tluafed

esiwtib noitazilaitini dluow evah detluser ni x dna mun gnirahs eht emas yromem rof rieht syarra . tahT( ,si p.mun dna p.x dluow evah deedni

detniop ot eht emas ).noitacol .8 sessalc dna snoitcnuf cireneG

++C swolla a noitcnuf ot ngissa a temarap re a tluafed eulav nehw on gnidnopserroc tnemugra ot taht retemarap si deificeps ni a llac ot taht

noitcnuf . ehT tluafed eulav si deificeps ni a rennam yllacitcatnys ralimis ot a elbairav noitazilaitini . roF ,elpmaxe siht seralced (cnufym ) sa gnikat eno d elbuo tnemugra htiw a tluafed eulav fo :0.0

diov elbuod(cnufym d = )0.0 { // ...

} oN w , (cnufym ) nac eb dellac eno fo owt ,syaw sa eht gniwollof

selpmaxe :wohs ;)432.891(cnufym // ssap na ticilpxe eulav

)(cnufym ; // tel noitcnuf esu tluafed ehT tsrif llac sessap eht eulav 432.891 ot d. ehT dnoces llac yllacitamotua

sevig d eht tluafed eulav .orez enO nosaer taht tluafed stnemugra era dedulcni ni ++C si esuaceb yeht edivorp eht rof dohtem rehtona

tixelpmoc retaerg eganam ot remmargorp y. T eht eldnah o tsediw yteirav fo ,snoitautis etiuq yltneuqerf a noitcnuf sniatnoc erom sretemarap naht era

deriuqer rof sti tsom nommoc egasu . ,suhT nehw eht tluafed stnemugra uoy ,ylppa deen yficeps ylno eht stnemugra taht era lufgninaem ot eht

tcaxe ,noitautis ton lla esoht dedeen yb eht tsom lareneg esac . roF ,elpmaxe ynam fo eht ++C O/I snoitcnuf ekam esu fo tluafed stnemugra rof tsuj siht

.nosaer A elpmis noitartsulli fo woh lufesu a tluafed noitcnuf tnemugra nac eb si

nwohs eht yb (rcsrlc ) noitcnuf ni eht gniwollof rgorp ma . ehT (rcsrlc ) noitcnuf sraelc eht neercs yb gnittuptuo a seires tsom eht ton( sdeefenil fo

siht rof tneiciffus tub ,yaw tneiciffe elpmaxe ). esuaceB a yrev nommoc oediv edom syalpsid 52 senil fo ,txet eht tluafed tnemugra fo 52 si dedivorp .

evewoH r ceb , ssel ro erom yalpsid sedom oediv emos esua naht 52 ,senil uoy nac edirrevo eht tluafed tnemugra yb gniyficeps eno .ylticilpxe .9 ,+ sa hcus snoitcnuf dneirf gnisu gnidaolrevo rotarepO snoitacilppA - ,

erp - tsop ,tnemercni - ,<< gnidaolrevo ,.cte ] [ ,tnemercni .>>

:mrof lareneg siht sekat noitcnuf rotarepo rebmem A

Page 53: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 05

ter - epyt ssalc - ::eman otarepo r gra(# - )tsil { // snoitarepo

}

,netfO rotarepo snoitcnuf nruter na tcejbo fo eht ssalc yeht etarepo ,no tub ter - epyt nac eb yna dilav epyt . ehT # edlohecalp a si r. nehW oy u etaerc

na rotarepo ,noitcnuf etutitsbus eht rotarepo rof eht #. roF ,elpmaxe fi uoy era gnidaolrevo eht / otarepo r, esu rotarepo /. a gnidaolrevo era uoy nehW

otarepo yranu r , gra - tsil tpme eb lliw y. nehW uoy era gnidaolrevo yranib ,srotarepo gra - tsil lliw .retemarap eno niatnoc

ehT( snosaer rof siht ylgnimees lausunu noitautis lliw eb edam raelc ni a ).tnemom

ereH si a elpmis tsrif elpmaxe fo rotarepo gnidaolrevo . sihT margorp setaerc a ssalc c ella d l co , hcihw ots res dutignol e na d dutital e seulav . tI

lrevo sdao ht e + o rotarep evitaler ot siht ssalc . margorp siht enimaxElluferac y eht ot noitnetta laiceps gniyap , noitinifed fo (+rotarepo ):

>maertsoi<edulcni# ecapseman ;dts

col ssalC { ,edutignol ;edutital

:cilbup )(col }{

tni(col ,gl tni )tl { edutignol = gl ;

dutital e ;tl }

diov )(wohs { tuoc << edutignol tuoc << edutital

} col col(+rotarepo ;)2po

;} // daolrevO + rof .col col col(+rotarepo::col )2po

{ col ;pmet

edutignol.pmet = edutignol.2po + ;edutignol dutital.pmet e edutital.2po + ;edutital

nruter et ;pm }

=

<< " ;"

<< "\ ;"n

=

Page 54: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 15

tni {

col ,01(1bo ,)02 (2bo ,5 ;)03 ;)(wohs.1bo // syalpsid 01 02 ;)(wohs.2bo // syalpsid 5 03

1bo = 1bo + ;2bo

;)(wohs.1bo // syalpsid 51 05 nruter ;0

}

sA uoy nac ,ees (+rotarepo ) sah ylno eno retemarap neve hguoht ti sdaolrevo eht nib ra y + op otare r. (Y uo thgim tcepxe owt sretemarap

roc r gnidnopse ot eht wt o sdnarepo fo a yranib ).rotarepo ehT nosaer taht (+rotarepo ) sekat ylno eno retemarap si taht eht dnarepo no eht tfel edis fo

eht + si dessap ylticilpmi ot eht noitcnuf hguorht eht siht niop et r. ehT dnarepo no eht thgir si dessap ni eht retemarap 2po . ehT tcaf taht eht tfel dnarepo si dessap gnisu siht osla seilpmi eno tnatropmi :tniop nehW

yranib srotarepo are ,dedaolrevo ti si eht tcejbo no eht fel t aht t etareneg s ht e lac l to ht e otarepo r f .noitcnu sA m denoitne , it is ommoc n of r an edaolrevo d

otarepo r oitcnuf n to r rute n a n bo j tce fo eht ssalc ti setarepo nopu . yB gniod ,os ti swolla eht rotarepo ot eb desu ni regral e px r snoisse . oF r elpmaxe , if

ht e +rotarepo ( ) nuf oitc n r enrute d mos e ehto r t ,epy siht noisserpxe dluow ton evah neeb :dilav

1bo = 1bo + ;2bo nI or red rof eht us m of bo 1 dna bo 2 ot eb engissa d to 1bo , eht moctuo e of

aht t noitarepo tsum eb na tcejbo fo epyt col . ehtruF ,r vah ni g +rotarepo ( ) r rute n an cejbo t of pyt e ol c ekam s lbissop e ht e gniwollof :tnemetats

;)(wohs.)2bo+1bo( // syalpsid emoctuo fo 2bo+1bo

nI siht ,noitautis 2bo+1bo setareneg a yraropmet tcejbo taht sesaec ot tsixe retfa eht llac ot (wohs ) .setanimret tI si tnatropmi ot dnatsrednu taht na rotarepo noitcnuf nac ter nru yna epyt dna eht taht pyt e r enrute d dneped s lelos y opu n uoy r ificeps c

noitacilppa . It is suj t taht , netfo , na rotarepo noitcnuf lliw nruter na tcejbo fo eht ssalc nopu hcihw ti .setarepo

enO tsal tniop tuoba eht (+rotarepo ) :noitcnuf tI seod ton fidom y rehtie .dnarepo esuaceB eht lanoitidart esu fo eht + rotarepo seod ton yfidom

rehtie ,dnarepo ti sekam esnes rof eht dedaolrevo noisrev ton rehtie os od ot . roF( ,elpmaxe 7+5 sdleiy ,21 tub rehtien 5 ron 7 si ).degnahc hguohtlA uoy

era eerf ot mrofrep na y noitarepo uoy edisni tnaw na rotarepo ,noitcnuf ti si yllausu tseb ot yats nihtiw eht txetnoc fo eht otarepo eht fo esu lamron r.

ehT txen margorp sdda eerht lanoitidda dedaolrevo srotarepo ot eht col

)(niam

Page 55: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 25

:ssalc eht – , eht ,= dna eht yranu ++. yaP laiceps tta noitne ot woh eseht snoitcnuf era .denifed

edulcni# >maertsoi<

gnisu ecapseman ;dts ssalc col {

tni ,edutignol ;edutital :cilbup

)(col }{ // dedeen ot tcurtsnoc seiraropmet tni(col ,gl tni {

edutignol = ;gl dutital e ;tl

} diov )(wohs { tuoc << edutignol tuoc << edutital

} col col(+rotarepo ;)2po col rotarepo - col( ;)2po col col(=rotarepo ;)2po col ;)(++rotarepo

;} // daolrevO + rof .col col col(+rotarepo::col )2po

{ col ;pmet

edutignol.pmet = edutignol.2po + ;edutignol dutital.pmet e edutital.2po + tal ;eduti

nruter ;pmet } // daolrevO - rof .col col rotarepo::col - col( )2po

{ col ;pmet

// eciton redro fo sdnarepo edutignol.pmet = edutignol - ;edutignol.2po

dutital.pmet e edutital - ;edutital.2po nruter ;pmet

}

)tl

=

<< " ;"

<< "\ ;"n

=

=

Page 56: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 35

// daolrevO tnemngisa rof col.col repo::col col(=rota )2po {

edutignol = ;edutignol.2po edutital = ;edutital.2po

nruter ;siht* // ,.e.i nruter tcejbo taht detareneg llac

} // daolrevO xiferp ++ rof .col col )(++rotarepo::col

{ ;++edutignol

;++edutital nruter ;siht*

} tni )(niam

{ col ,01(1bo ,)02 (2bo ,5 ,)03 ,09(3bo ;)09

;)(wohs.1bo ;)(wohs.2bo

;1bo++ ;)(wohs.1bo // syalpsid 11 12

2bo = ;1bo++ ;)(wohs.1bo // syalpsid 21 22 ;)(wohs.2bo // syalpsid 21 22

1bo = 2bo = ;3bo // elpitlum tnemngissa ;)(wohs.1bo // syalpsid 09 09 ;)(wohs.2bo // syalpsid 09 09

nruter ;0

} ,tsriF enimaxe eht rotarepo –( ) oitcnuf n. ecitoN eht redro fo eht sdnarepo

ni eht oitcartbus n. nI gnipeek htiw eht gninaem fo ,noitcartbus eht dnarepo no eht thgir fo edis eht sunim ngis si detcartbus morf eht dnarepo no eht

tfel . esuaceB ti si eht tcejbo no eht tfel aht t etareneg s ht e lac l to ht e rotarepo –( ) oitcnuf n, 2po s' atad sum t eb detcartbus morf detniop atad eht ot yb iht s. tI si tnatropmi ot rebmemer hcihw dnarepo setareneg eht llac ot eht

.noitcnuf nI ,++C fi eht = si ton aolrevo ,ded a tluafed tnemngissa noitarepo si

detaerc otua llacitam y of r na y salc s oy u ed enif . hT e luafed t nemngissa t is lpmis y a ebmem r- yb -m ebme r, poc esiwtib y. yB gnidaolrevo eht =, uoy nac

Page 57: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 45

enifed ylticilpxe tahw eht tnemngissa seod aler vit e to a ssalc . In iht s elpmaxe , ht e edaolrevo d = eod s ltcaxe y ht e mas e niht g a s eht ,tluafed tub

ni rehto ,snoitautis ti dluoc mrofrep rehto snoitarepo . ecitoN taht eht=rotarepo ( ) uf oitcn n r nrute s iht* s, cihw h is ht e cejbo t aht t etareneg d ht e

llac . ihT s tnemegnarra si assecen yr fi uoy tnaw ot eb elba ot esu elpitlum tnemngissa snoitarepo hcus sa :siht

1bo = 2bo = ;3bo // elpitlum tnemngissa

oN w fo noitinifed eht ta kool , (++rotarepo ). sA uoy nac ,ees ti sekat on

.sretemarap cniS e ++ is a ranu y po otare ,r ti s lno y narepo d is lticilpmi y essap d by nisu g ht e siht etniop r.

ecitoN taht htob (=rotarepo ) dna (++rotarepo ) retla eht eulav fo na .dnarepo nI eht esac fo ,tnemngissa eht dnarepo no eht tfel eht( eno gnitareneg eht llac ot eht (=rotarepo ) )noitcnuf si dengissa a wen ulav e. nI

eht esac fo eht ++ , eht dnarepo si cni r detneme . sA detats ,ylsuoiverp hguohtla uoy era eerf ot ekam eseht srotarepo gnihtyna od uoy ,esaelp ti si

tsomla syawla tsesiw ot yats tnetsisnoc htiw rieht .sgninaem lanigiro In ht e pr nidece g pr margo , lno y ht e pr ife x rof m of ht e cni r neme t otarepo r

aw s .dedaolrevo ,revewoH dradnatS ++C swolla oy u to lticilpxe y cr tae e tarapes e pr ife x na d iftsop x snoisrev fo eht tnemercni ro tnemerced

srotarepo . enifed tsum uoy ,siht hsilpmocca oT owt snoisrev fo eht (++rotarepo ) oitcnuf n. nwohs sa denifed si enO ni eht gniogerof pr margo .

ehT rehto si deralced ekil :siht

col tni(++rotarepo ;)x fI eht ++ sedecerp sti eht ,dnarepo (++rotarepo ) noitcnuf si dellac . fI eht

++ swollof sti ,dnarepo eht tni(++rotarepo )x si dellac dna x sah eht eulav .orez ehT gnidecerp elpmaxe nac eb dezilareneg . ereH era eht lareneg smrof

rof eht xiferp dna xiftsop ++ dna – – rotarepo .snoitcnuf

P // r cni xife r tneme epyt (++rotarepo ) {

// ydob xiferp fo rotarepo } // xiftsoP tnemercni

epyt (++rotarepo tni x) { // ydob fo xiftsop rotarepo

} // tnemerced xiferP

epyt rotarepo – –( ) { // ydob xiferp fo rotarepo

}

Page 58: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 55

// xiftsoP tnemerced epyt rotarepo – – tni( x) {

// ydob fo xiftsop rotarepo }

1.9 gnidaolrevO [ ]

nI ,++C eht [ ] si deredisnoc a yranib rotarepo hw ne gnidaolrevo era uoy ti . ,eroferehT eht lareneg mrof fo a rebmem [rotarepo (] ) noitcnuf si sa

nwohs :ereh epyt ssalc - eman tni(][rotarepo:: i)

{ // . . .

} T llacinhce y epyt fo eb ot evah ton seod retemarap eht , tni , tub na

[rotarepo (] ) noitcnuf is ipyt llac y esu d to pr divo e arra y gnitpircsbus , na d as hcus , an egetni r ulav e i s yllareneg desu

neviG na tcejbo dellac O, eht noisserpxe

]3[O

setalsnart otni siht llac ot eht [rotarepo (] ) :noitcnuf

)3(][rotarepo.O

tahT ,si eht eulav fo eht isserpxe no nihtiw eht gnitpircsbus srotarepo si

dessap ot eht [rotarepo ]( ) noitcnuf ni sti ticilpxe etemarap r. ehT iht s retniop w li l niop t to O, eht ejbo tc taht detareneg eht nI .llac eht gniwollof ,margorp

epyta seralced na yarra fo eerht sregetni . stI curtsnoc rot sezilaitini hcae rebmem of ht e arra y to ht e eificeps d seulav . ehT edaolrevo d [rotarepo ]( ) noitcnuf r snrute eht eulav fo eht rra ay as exedni d by ht e ulav e of ti s etemarap r.

edulcni# >maertsoi<

gnisu ecapseman ;dts

ssalc epyta { tni ;]3[a

:cilbup a tni(epyt ,i tni ,j tni )k {

]0[a = ;i

Page 59: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 65

]1[a = ;j ]2[a = ;k

} tni tni(][rotarepo )i { nruter ;]i[a }

;}

tni )(niam {

epyta ,1(bo ,2 ;)3 tuoc << ;]1[bo // syalpsid 2 nruter ;0

} Y eht ngised nac uo [rotarepo (] ) noitcnuf ni hcus a yaw taht eht [ ] nac eb esu d htob no eht tfel dna thgir sedis fo na tnemngissa tnemetats . oT od ,siht

ylpmis yficeps eht fo eulav nruter [rotarepo (] ) a sa r efe r ecne . ehTsekam margorp gniwollof siht egnahc dna swohs sti :esu

edulcni# >maertsoi<

gnisu ecapseman ;dts

ssalc epyta { tni ;]3[a

:cilbup tni(epyta ,i tni ,j tni )k {

]0[a ]1[a ]2[a

} tni tni(][rotarepo& )i { nruter ;]i[a }

;} tni )(niam

{ epyta ,1(bo ,2 ;)3

tuoc << ;]1[bo // syalpsid 2 tuoc << " ;" ]1[bo = ;52 // ][ no tfel fo =

tuoc << ;]1[bo // won syalpsid 52 nruter ;0

}

= i; = ;j = ;k

Page 60: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 75

esuaceB [rotarepo (] ) won snruter a ecnerefer ot eht yarra tnemele

dexedni yb ,i ti nac eb desu no eht tfel edis fo na tnemngissa ot yfidom na tnemele fo eht yarra . fO( ,esruoc ti yam llits eb desu no eht thgir edis sa

).llew enO egatnavda fo gnieb elba ot daolrevo eht [ ] rotarepo si taht ti swolla

a snaem fo gnitnemelpmi efas yarra gnixedni ni ++C . onk uoy sA w ,++C ni ,ot elbissop si ti nurrevo ro( )nurrednu na yarra yradnuob ta nur emit

tuohtiw gnitareneg a nur - emit rorre egassem . uoy fi ,revewoH ssalc a etaercarra eht sniatnoc taht y ssecca wolla dna , to aht t arra y lno y thr guo h ht e

edaolrevo d [ ] itpircsbus ng otarepo ,r eht n oy u ac n etni r pec t an tuo - fo -gnar e xedni . oF r elpmaxe , iht s pr argo m dda s a gnar e cehc k t o eht

gnidecerp margorp dna sevorp ht ta ti :skrow // A efas yarra .elpmaxe

edulcni# >maertsoi< edulcni# >bildtsc<

gnisu ecapseman ;dts ssalc epyta {

tni ;]3[a :cilbup

tni(epyta ,i tni ,j tni )k { ]0[a = ;i ]1[a = ;j ]2[a = ;k

} tni tni(][rotarepo& ;)i

;} // edivorP egnar gnikcehc rof .epyta tni tni(][rotarepo::epyta& )i

{ 0<i(fi || >i )2 {

tuoc << yradnuoB" rorrE \ ;"n ;)1(tixe

} nruter ;]i[a

} tni )(niam

{ epyta ,1(bo ,2 ;)3

tuoc << ;]1[bo // syalpsid 2

Page 61: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 85

tuoc << " ;" ]1[bo = ;52 // ][ sraeppa no tfel

tuoc << ;]1[bo // syalpsid 52 ]3[bo = ;44 // setareneg emitnur ,rorre 3 tuo - fo - egnar nruter ;0

} nI siht ,margorp nehw eht tnemetats ]3[bo = ;44

,setucexe eht yradnuob rorre si detpecretni yb (][rotarepo ,) dna eht margorp si detanimret erofeb yna egamad nac eb enod . nI( lautca ,ecitcarp

emos tros of rorre - gnildnah noitcnuf dluow eb dellac ot laed htiw eht tuo -fo - egnar ;noitidnoc eht margorp dluow ton evah ot ).etanimret

gnidaolrevO 2.9 –> ehT –> otarepo retniop r eht dellac osla , ssalc rebmem ssecca ,rotarepo si

deredisnoc a yranu rotarepo nehw lrevo gnidao . stI lareneg egasu si nwohs :ereh

tcejbo - ;tnemele>

eH r ,e tcejbo si eht tcejbo taht setavitca eht llac . ehT rotarepo – (> ) noitcnuf tsum nruter

a retniop ot na tcejbo fo eht ssalc taht rotarepo – (> ) setarepo nopu . ehT tnemele tsum eb emos rebmem secca elbis nihtiw eht .tcejbo ehT gniwollof margorp setartsulli gnidaolrevo eht –> yb gniwohs eht ecnelaviuqe neewteb

i.bo dna bo – i> nehw rotarepo – (> ) snruter eht siht :retniop edulcni# >maertsoi<

gnisu ecapseman ;dts ssalc ssalcym {

:cilbup tni ;i

ssalcym po* rotare - )(> nruter{ };siht ;} tni )(niam

{ ssalcym ;bo

bo - i> = ;01 // emas sa i.bo tuoc << i.bo << " " << bo - ;i> nruter ;0

} nA rotarepo – (> ) noitcnuf tsum eb a rebmem fo eht ssalc nopu hcihw ti

.skrow ehT lareneg noteleks fo na dedaolrevo tuptuo rotarepo is // lareneg noteleks fo eht dedaolrevo tuptuo rotarepo

&maertso

Page 62: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 95

rotarepo &maertso(<< ,so tsnoc epyTssalC )tcejbo& { // yna laiceps cigol ot eraperp tcejbo // lautca tuptuo fo srebmem so << // ... // nruter maertso tcejbo

nruter ;so }

eW nac won etirw eht eti_selaS m tuptuo otarepo r:

&maertso &maertso(<<rotarepo ,tuo tsnoc &meti_selaS )s

{ tuo << nbsi.s << "\ "t << dlos_stinu.s << "\ "t

<< eunever.s << "\ "t << ;)(ecirp_gva.s nruter ;tuo

} ehT meti_selaS tupnI rotarepO ehT eti_selaS m tupni rotarepo skool :ekil

&maertsi &maertsi(>>rotarepo ,ni &meti_selaS )s

{ elbuod ;ecirp

ni >> nbsi.s >> dlos_stinu.s >> ;ecirp // kcehc taht eht stupni dedeeccus fi )ni(

eunever.s = dlos_stinu.s * ;ecirp esle

s = ;)(meti_selaS // tupni :deliaf teser tcejbo ot tluafed etats nruter ;ni

}

Page 63: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 06

TINU – VI

ECNATIREHNI – I

derevoc scipoT

ecnatirehnI – :I ssalc esab detcetorp ,srebmem detcetorp dna ecnatirehnI ,ssalC esaB

sessalc esab elpitlum gnitirehni ,ecnatirehni

TINU - yrammuS 4 ecnatirehnI si eno fo eht senotsrenroc fo POO b esuace ti swolla eht noitaerc

fo lacihcrareih snoitacifissalc . gnisU ,ecnatirehni uoy nac etaerc a lareneg ssalc

taht senifed stiart nommoc ot a tes fo detaler smeti . sihT ssalc yam neht eb

detirehni yb ,rehto erom cificeps ,sessalc hcae gnidda ylno esoht sgniht taht

era euqinu ot gnitirehni eht .ssalc nI gnipeek htiw dradnats ,ygolonimret ++C

ot derrefer si detirehni si taht ssalc a sa a esab ssalc . ehT ssalc taht seod eht

gnitirehni si dellac eht devired ssalc . ehtruF r a , devired ssalc nac eb desu sa a

ab es ssalc rof rehtona devired ssalc . aw siht nI y elpitlum , ecnatirehni si

.deveihca s'++C troppus fo ecnatirehni si htob hcir dna elbixelf .

.1 ssalC esaB

nehW a ssalc stirehni ,rehtona eht srebmem fo eht srebmem emoceb ssalc esab eht fo devired ssalc . ssalC ecnatirehni sesu siht lareneg :mrof ssalc devired - ssalc - eman : ssecca esab - ssalc - eman {

// ydob fo ssalc ;}

Page 64: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 16

ehT ssecca sutats fo eht esab - ssalc srebmem edisni eht devired ssalc si denimreted yb secca s. ehT esab - ssalc ssecca reificeps tsum eb rehtie ilbup c,

tavirp e, ro etcetorp d. fI on ssecca reificeps si ,tneserp eht ssecca reificeps si etavirp yb tluafed fi eht devired ssalc si a salc s. fI eht devired ssalc si a tcurts ,

neht cilbup si eht tluafed ni eht ecnesba fo na ticilpxe reificeps ssecca . 'teL s enimaxe eht snoitacifimar fo gnisu cilbup ro etavirp secca s. ehT( detcetorp reificeps si denimaxe ni eht txen ).noitces nehW eht ssecca reificeps rof a esab ssalc si ilbup c, lla cilbup srebmem fo

eht esab emoceb cilbup srebmem fo eht devired ,ssalc dna a ll detcetorp srebmem fo eht esab emoceb detcetorp srebmem fo eht devired ssalc . nI lla

,sesac eht s'esab etavirp stnemele niamer etavirp ot eht esab dna era ton elbissecca yb srebmem fo eht devired ssalc . roF ,elpmaxe sa detartsulli ni siht ,margorp tcejbo s fo epyt devired nac yltcerid ssecca eht cilbup srebmem fo

esab : edulcni# >maertsoi<

gnisu ecapseman ;dts ssalc esab {

tni ,i ;j :cilbup

diov tni(tes ,a tni )b { ;a=i ;b=j diov} )(wohs { tuoc << i << " " << j << "\ ;"n } ;}

ssalc devired : cilbup esab { i tn ;k )x { ;x=k }

)(kwohs { tuoc << k << "\ ;"n }

)(niam devired ;)3(bo

,1(tes.bo ;)2 // ssecca rebmem fo esab ;)(wohs.bo // ssecca rebmem fo esab

;)(kwohs.bo // sesu rebmem fo devired ssalc nruter ;0

} nehW eht esab ssalc si detirehni yb gnisu eht avirp et eificeps ssecca r cilbup lla ,

dna detcetorp srebmem fo eht esab ssalc emoceb etavirp srebmem fo eht devired ssalc . roF ,elpmaxe eht gniwollof margorp lliw ton neve elipmoc esuaceb htob

(tes ) dna (wohs ) era won etavirp fo stnemele devired : // sihT gorp mar t'now .elipmoc

>maertsoi< edulcni# ecapseman ;dts

:cilbup tni(devired

diov ;}

tni {

Page 65: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 26

esab ssalc {

,i ;j :cilbup

diov tni(tes ,a tni )b { ;a=i ;b=j } diov )(wohs tuoc << i << " " << j << "\ };"n

;} // cilbuP stnemele fo esab era etavirp ni .devired

ssalc devired : etavirp esab { tni ;k

:cilbup tni(devired )x { ;x=k }

diov )(kwohs { tuoc << k << "\ ;"n } ;} tni )(niam

{ devired ;)3(bo

,1(tes.bo ;)2 // ,rorre t'nac ssecca )(tes ;)(wohs.bo // ,rorre t'nac ssecca )(wohs

nruter ;0 } .2 srebmem detcetorp dna ecnatirehnI

The etcetorp d owyek rd is edulcni d in +C + to pr divo e gr etae r tilibixelf y in

ht e cnatirehni e msinahcem . ehW n a ebmem r of a salc s is alced red as etcetorp d, aht t ebmem r is on t lbissecca e by ehto ,r ebmemnon r tnemele s of ht e pr margo .

W ti h no tnatropmi e ,noitpecxe ssecca ot a detcetorp m rebme si eht emas sa ssecca ot a etavirp rebmem — ti nac eb dessecca ylno yb rehto srebmem fo sti ssalc . ehT

elos noitpecxe ot siht si nehw a detcetorp rebmem si detirehni . nI siht ,esac a detcetorp rebmem sreffid yllaitnatsbus morf a etavirp .eno

As nialpxe ed in ht e pr nidece g noitces , a tavirp e ebmem r of a sab e salc s is on tlbissecca e by ehto r trap s of uoy r pr margo , nidulcni g na y evired d ssalc .

ewoH ev ,r pr tceto ed rebmem s heb va e id f ef r ltne y. If ht e sab e salc s is etirehni d as ilbup c, eht n eht esab 'ssalc etorp detc srebmem emoceb detcetorp srebmem fo eht

devired ssalc dna ,era ,erofereht elbissecca yb eht devired ssalc . yB gnisu etcetorp d, uoy nac etaerc ssalc srebmem taht era etavirp ot rieht ssalc tub taht nac

llits eb detirehni dna dessecca yb devired a ssalc . ereH si na :elpmaxe edulcni# >maertsoi<

gnisu ecapseman ;dts ssalc esab {

:detcetorp

{

Page 66: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 36

tni ,i ;j // etavirp ot ,esab tub elbissecca yb devired :cilbup

diov tni(tes ,a tni )b { ;a=i ;b=j } diov )(wohs tuoc << i << " " << j << "\ ;"n }

;} ssalc devired : bup cil esab {

tni ;k :cilbup

// devired yam ssecca s'esab i dna j diov )(ktes { ;j*i=k } diov )(kwohs { tuoc << k << "\ ;"n }

;} tni )(niam

{ devired ;bo

,2(tes.bo ;)3 // ,KO nwonk ot devired ;)(wohs.bo // ,KO nwonk ot devired

;)(ktes.bo ;)(kwohs.bo

nruter ;0 } nI siht ,elpmaxe esuaceb esab si detirehni yb devired sa cilbup dna esuaceb i dna j ar alced e r sa de etcetorp d, devired s' noitcnuf (ktes ) yam ssecca meht . fI i

dna j dah neeb deralced sa etavirp yb esab , neht devired dluow ton evah ssecca ot ,meht dna t eh margorp dluow ton .elipmoc

nehW a devired ssalc si desu sa a esab ssalc rof rehtona devired ,ssalc yna rebmem detcetorp fo eht laitini esab ssalc taht si detirehni sa( )cilbup yb eht tsrif

devired ssalc yam osla eb detirehni sa detcetorp niaga yb a oces dn devired ssalc . roF ,elpmaxe siht margorp si ,tcerroc dna 2devired seod deedni evah ssecca ot i dna j.

edulcni# >maertsoi< gnisu ecapseman ;dts ssalc esab {

:detcetorp tni ,i ;j

:cilbup diov tni(tes ,a tni )b { ;a=i ;b=j } diov )(wohs { tuoc << i << " " << j << "\ ;"n }

;} // i dna j detirehni sa .detcetorp

{

Page 67: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 46

ssalc 1devired : cilbup esab { tni ;k

:cilbup diov )(ktes { k = ;j*i } // lagel diov )(kwohs { tuoc << k << "\ ;"n }

;} // i dna j detirehni yltceridni hguorht .1devired

ssalc 2devired : cilbup devired 1 { tni ;m

:cilbup diov )(mtes { m = i- ;j } // lagel diov )(mwohs { tuoc << m << "\ ;"n }

;} tni )(niam

{ 1devired ;1bo 2devired ;2bo

,2(tes.1bo ;)3 ;)(wohs.1bo

;)(ktes.1bo ;)(kwohs.1bo

,3(tes.2bo ;)4 ;)(wohs.2bo

;)(ktes.2bo ;)(mtes.2bo

;)(kwohs.2bo ohs.2bo ;)(mw

nruter ;0 }

evewoh ,fI r , esab sa detirehni erew tavirp e, neht lla srebmem fo esab dluowemoceb etavirp srebmem fo devired 1, hcihw snaem taht yeht dluow ton eb

elbissecca yb devired 2. evewoH( r , i dna j dluow llits eb elbissecca yb 1devired .) sihT utis noita si lli etartsu d by ht e niwollof g pr margo , cihw h is in re ror na( d 'now t )elipmoc . hT e moc tnem s bircsed e cae h re r ro :

// sihT margorp t'now .elipmoc

edulcni# gnisu ssalc esab {

>maertsoi<

ecapseman ;dts

Page 68: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 56

:detcetorp tni ,i ;j

:cilbup diov tni(tes ,a tni )b { ;a=i ;b=j } diov s )(woh tuoc << i << " " << j << "\ ;"n }

;} // ,woN lla stnemele fo esab era etavirp ni .1devired

ssalc 1devired : etavirp esab { tni ;k

:cilbup // siht si lagel esuaceb i dna j era etavirp ot 1devired

diov )(ktes { k = ;j*i } // KO diov )(kwohs { tuoc << k << "\ ;"n }

;} // sseccA ot ,i ,j ,)(tes dna )(wohs ton .detirehni

2devired : cilbup 1devired { ;m

:cilbup // lagelli esuaceb i dna j era etavirp ot 1devired

diov )(mtes { diov )(mwohs

;} tni

{ 1devired 2devired

,1(tes.1bo ;)2 // ,rorre t'nac esu )(tes ;)(wohs.1bo // ,rorre t'nac esu )(wohs

,3(tes.2bo ;)4 // ,rorre t'nac esu )(tes ;)(wohs.2bo // ,rorre t'nac esu )(wohs

nruter ;0 .3 ecnatirehni ssalc esab detcetorP

tI si elbissop ot tirehni a esab ssalc sa etcetorp d. nehW siht si ,enod lla cilbup

na detcetorp d srebmem fo eht esab ssalc emoceb detcetorp srebmem fo eht devired .ssalc

roF ,elpmaxe edulcni# >maertsoi<

gnisu ecapseman ;dts

{

ssalc tni

// rorrE << "\ ;"n }

m = i- ;j }

{ tuoc << m

)(niam

;1bo

;2bo

Page 69: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 66

ssalc esab { :detcetorp

tni ,i ;j // etavirp ot ,esab tub elbissecca yb devired :cilbup

diov tni(jites ,a tni )b { =i ;a ;b=j } diov )(jiwohs { tuoc << i << " " << j << "\ ;"n }

;} // tirehnI esab sa .detcetorp

ssalc devired : detcetorp {esab tni ;k

:cilbup // devired yam ssecca s'esab i dna j dna .)(jites

diov )(ktes { ,01(jites ;)21 k = ;j*i } // yam ssecca )(jiwohs ereh

diov )(llawohs { tuoc << k << " ;" ;)(jiwohs } ;} tni )(niam

{ devired ;bo

,2(jites.bo ;)3 // ,lagelli )(jites si detcetorp rebmem fo devired

cilbup rebmem fo devired ;)(llawohs.bo // ,KO cilbup rebmem fo devired

// ;)(jiwohs.bo // ,lagelli )(jiwohs si detcetorp // rebmem fo devired

nruter ;0 }

sA uoy nac yb ees gnidaer eht ,stnemmoc neve hguoht (jites ) dna (jiwohs ) ar eilbup c rebmem s of sab e, ht ey moceb e pr etceto d rebmem s of evired d ehw n it is

etirehni d nisu g ht e etcetorp d ssecca ificeps er. ihT s naem s aht t eht y liw l on t be lbissecca e disni e m nia ( ).

.4 sessalc esab elpitlum gnitirehni

tI a rof elbissop si devired ssalc ot tirehni owt ro erom esab sessalc . roF ,elpmaxe

ni siht trohs ,elpmaxe devired stirehni htob 1esab dna 2esab . // nA elpmaxe fo pitlum el esab .sessalc

edulcni# >maertsoi< gnisu ecapseman ;dts

// //

;)(ktes.bo // ,KO

Page 70: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 76

ssalc 1esab { :detcetorp

tni ;x :cilbup

diov )(xwohs { tuoc << x << "\ ;"n } ;}

ssalc 2esab { :detcetorp

tni ;y :cilbup

diov )(ywohs tuoc{ << y << "\ };"n ;} // tirehnI elpitlum esab .sessalc

ssalc ed :devir cilbup ,1esab cilbup 2esab { :cilbup

diov tni(tes ,i tni )j { ;i=x ;j=y } ;} tni )(niam

{ devired ;bo

,01(tes.bo ;)02 // dedivorp yb devired ;)(xwohs.bo // morf 1esab ;)(ywohs.bo // morf 2esab

nruter ;0 }

sA ht e lpmaxe e setartsulli , to irehni t om er aht n no e sab e ssalc , su e a ammoc - se etarap d tsil . ,rehtruF eb erus ot esu an ssecca - eificeps r of r cae h sab e detirehni .

Page 71: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 86

TINU - V

I ECNATIREHN – II

ecnatirehnI dna ,srotcurtseD ,srotcurtsnoC

ot evitaler esira taht snoitseuq rojam owt era erehT si ecnatirehni nehw srotcurtsed dna srotcurtsnoc

esab era nehw ,tsriF .devlovni - devired dna ssalc - ?dellac snoitcnuf rotcurtsed dna rotcurtsnoc ssalc

esab ot dessap eb sretemarap nac woh ,dnoceS - senimaxe noitces sihT ?snoitcnuf rotcurtsnoc ssalc

owt eseht .scipot tnatropmi

detucexE erA snoitcnuF rotcurtseD dna rotcurtsnoC nehW

rotcurtsed ro/dna rotcurtsnoc niatnoc ot htob ro ,ssalc devired a ,ssalc esab a rof elbissop si tI

exe era snoitcnuf eseht hcihw ni redro eht dnatsrednu ot tnatropmi si tI .snoitcnuf na nehw detuc

enimaxe ,nigeb oT .ecnetsixe fo tuo seog ti nehw dna ecnetsixe otni semoc ssalc devired a fo tcejbo

:margorp trohs siht

>maertsoi< edulcni#

;dts ecapseman gnisu

{ esab ssalc

:cilbup

esab gnitcurtsnoC" << tuoc { )(esab \ } ;"n

<< tuoc { )(esab~ esab gnitcurtseD" \ } ;"n

;}

{ esab cilbup :devired ssalc

:cilbup

devired gnitcurtsnoC" << tuoc { )(devired \ } ;"n

devired gnitcurtseD" << tuoc { )(devired~ \ } ;"n

;}

)(niam tni

{

;bo devired

Page 72: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 96

bo tcurtsed dna tcurtsnoc tub gnihton od //

;0 nruter

}

moc eht sA ni tnem )(niam tcejbo na syortsed neht dna stcurtsnoc ylpmis margorp siht ,setacidni

dellac bo ssalc fo si taht devired syalpsid margorp siht ,detucexe nehW .

esab gnitcurtsnoC

devired gnitcurtsnoC

devired gnitcurtseD

esab gnitcurtseD

srif ,ees nac uoy sA t esab yb dewollof detucexe si rotcurtsnoc s' devired esuaceb( txeN .s' bo si

,)margorp siht ni deyortsed yletaidemmi devired yb dewollof ,dellac si rotcurtsed s' esab .s'

devired a fo tcejbo na nehW .dezilareneg eb nac tnemirepxe gniogerof eht fo stluser ehT si ssalc

'ssalc devired eht yb dewollof ,tsrif dellac eb lliw ti ,rotcurtsnoc a sniatnoc ssalc esab eht fi ,detaerc

esab eht yb dewollof ,tsrif dellac si rotcurtsed sti ,deyortsed si tcejbo devired a nehW .rotcurtsnoc

tuP .stsixe ti fi ,rotcurtsed 'ssalc fo redro rieht ni detucexe era snoitcnuf rotcurtsnoc ,yltnereffid

.noitavired fo redro esrever ni detucexe era snoitcnuf rotcurtseD .noitavired

.noitavired fo redro ni detucexe era snoitcnuf rotcurtsnoc taht esnes sekam ti ,ti tuoba kniht uoy fI

a esuaceB si mrofrep ot sdeen ti noitazilaitini yna ,ssalc devired yna fo egdelwonk on sah ssalc esab

.ssalc devired eht yb demrofrep noitazilaitini yna ot etisiuqererp ylbissop dna morf etarapes

.tsrif detucexe eb tsum ti ,eroferehT

lbisnes etiuq si ti ,esiwekiL eht esuaceB .noitavired fo redro esrever ni detucexe eb srotcurtsed taht e

fo noitcurtsed eht seilpmi tcejbo esab eht fo noitcurtsed eht ,ssalc devired eht seilrednu ssalc esab

eht erofeb dellac eb tsum rotcurtsed devired eht ,eroferehT .tcejbo devired eht ylluf si tcejbo

.deyortsed

Page 73: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 07

rehtona rof ssalc esab eht semoceb ssalc devired a erehw ,si taht( ecnatirehni elpitlum fo sesac nI

ni srotcurtsed ,noitavired fo redro ni dellac era srotcurtsnoC :seilppa elur lareneg eht ,)ssalc devired

xe roF .redro esrever margorp siht ,elpma

>maertsoi< edulcni#

;dts ecapseman gnisu

{ esab ssalc

:cilbup

esab gnitcurtsnoC" << tuoc { )(esab \ } ;"n

esab gnitcurtseD" << tuoc { )(esab~ \ } ;"n

;}

{ esab cilbup : 1devired ssalc

:cilbup

1devired gnitcurtsnoC" << tuoc { )(1devired \ ;"n }

1devired gnitcurtseD" << tuoc { )(1devired~ \ } ;"n

;}

{ 1devired cilbup :2devired ssalc

:cilbup

2devired gnitcurtsnoC" << tuoc { )(2devired \ } ;"n

2devired gnitcurtseD" << tuoc { )(2devired~ \ } ;"n

;}

)(niam tni

{

;bo 2devired

bo tcurtsed dna tcurtsnoc //

;0 nruter

}

:tuptuo siht syalpsid

esab gnitcurtsnoC

1devired gnitcurtsnoC

Page 74: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 17

2devired gnitcurtsnoC

2devired gnitcurtseD

1devired gnitcurtseD

esab gnitcurtseD

siht ,elpmaxe roF .sessalc esab elpitlum gnivlovni snoitautis ni seilppa elur lareneg emas ehT

gorp mar

>maertsoi< edulcni#

;dts ecapseman gnisu

{ 1esab ssalc

:cilbup

1esab gnitcurtsnoC" << tuoc { )(1esab \ } ;"n

1esab gnitcurtseD" << tuoc { )(1esab~ \ } ;"n

;}

{ 2esab ssalc

:cilbup

2esab gnitcurtsnoC" << tuoc { )(2esab \ } ;"n

gnitcurtseD" << tuoc { )(2esab~ 2esab \ } ;"n

;}

{ 2esab cilbup ,1esab cilbup :devired ssalc

:cilbup

devired gnitcurtsnoC" << tuoc { )(devired \ } ;"n

devired gnitcurtseD" << tuoc { )(devired~ \ } ;"n

;}

)(niam tni

{

;bo devired

bo tcurtsed dna tcurtsnoc //

;0 nruter

}

Page 75: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 27

:tuptuo siht secudorp

1esab gnitcurtsnoC

2esab gnitcurtsnoC

devired gnitcurtsnoC

devired gnitcurtseD

2esab gnitcurtseD

1esab gnitcurtseD

ni deificeps sa ,thgir ot tfel ,noitavired fo redro ni dellac era srotcurtsnoc ,ees nac uoy sA devired s'

c era srotcurtseD .tsil ecnatirehni dah taht snaem sihT .tfel ot thgir ,redro esrever ni della 2esab neeb

erofeb deificeps 1esab ni devired :ereh nwohs sa ,tsil s'

{ 1esab cilbup ,2esab cilbup :devired ssalc

:siht ekil dekool evah dluow margorp siht fo tuptuo eht neht

2esab gnitcurtsnoC

noC 1esab gnitcurts

devired gnitcurtsnoC

devired gnitcurtseD

1esab gnitcurtseD

2esab gnitcurtseD

esaB ot sretemaraP gnissaP - srotcurtsnoC ssalC

.stnemugra eriuqer taht snoitcnuf rotcurtsnoc dedulcni evah selpmaxe gnidecerp eht fo enon ,raf oS

o erehw sesac nI esu ylpmis uoy ,sretemarap erom ro eno seriuqer rotcurtsnoc 'ssalc devired eht yln

a ot stnemugra ssap uoy od woh ,revewoH .xatnys rotcurtsnoc deziretemarap dradnats eht

salc devired eht fo mrof dednapxe na esu ot si rewsna ehT ?ssalc esab a ni rotcurtsnoc rotcurtsnoc s's

esab erom ro eno ot stnemugra gnola sessap taht noitaralced - fo mrof lareneg ehT .srotcurtsnoc ssalc

devired dednapxe siht - :ereh nwohs si noitaralced rotcurtsnoc ssalc

Page 76: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 37

devired - gra(rotcurtsnoc - gra(1esab : )tsil - ,)tsil

gra(2esab - ,)tsil

... //

gra(Nesab - )tsil

{

// rotcurtsnoc devired fo ydob

}

,ereH 1esab hguorht Nesab ecitoN .ssalc devired eht yb detirehni sessalc esab eht fo seman eht era

esab eht morf noitaralced rotcurtsnoc 'ssalc devired eht setarapes noloc a taht - ,snoitacificeps ssalc

na esab eht taht d - fo esac eht ni ,sammoc yb rehto hcae morf detarapes era snoitacificeps ssalc

:margorp siht redisnoC .sessalc esab elpitlum

>maertsoi< edulcni#

;dts ecapseman gnisu

{ esab ssalc

:detcetorp

;i tni

:cilbup

curtsnoC" << tuoc ;x=i { )x tni(esab esab gnit \ } ;"n

esab gnitcurtseD" << tuoc { )(esab~ \ } ;"n

;}

{ esab cilbup :devired ssalc

;j tni

:cilbup

.esab ot gnola dessap si y ;x sesu devired //

)y(esab :)y tni ,x tni(devired

devired gnitcurtsnoC" << tuoc ;x=j { \ } ;"n

itcurtseD" << tuoc { )(devired~ devired gn \ } ;"n

" << j << " " << i << tuoc { )(wohs diov \ } ;"n

Page 77: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 47

;}

)(niam tni

{

;)4 ,3(bo devired

3 4 syalpsid // ;)(wohs.bo

;0 nruter

}

,ereH devired ,sretemarap owt gnikat sa deralced si rotcurtsnoc s' x dna y ,revewoH . )(devired sesu

ylno y ;x dessap si ot gnola .)(esab eht htob eralced tsum rotcurtsnoc 'ssalc devired eht ,lareneg nI

,setartsulli elpmaxe eht sA .ssalc esab eht yb deriuqer yna sa llew sa seriuqer ti taht )s(retemarap

c esab eht ni ti ot dessap era ssalc esab eht yb deriuqer sretemarap yna deificeps tsil tnemugra 'ssal

:sessalc esab elpitlum sesu taht elpmaxe na si ereH .noloc eht retfa

>maertsoi< edulcni#

;dts ecapseman gnisu

{ 1esab ssalc

:detcetorp

;i tni

:cilbup

1esab gnitcurtsnoC" << tuoc ;x=i { )x tni(1esab \ } ;"n

D" << tuoc { )(1esab~ 1esab gnitcurtse \ } ;"n

;}

{ 2esab ssalc

:detcetorp

;k tni

:cilbup

2esab gnitcurtsnoC" << tuoc ;x=k { )x tni(2esab \ } ;"n

1esab gnitcurtseD" << tuoc { )(2esab~ \ } ;"n

;}

{ 2esab cilbup ,1esab cilbup :devired ssalc

Page 78: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 57

;j tni

:cilbup

:)z tni ,y tni ,x tni(devired )z(2esab ,)y(1esab

devired gnitcurtsnoC" << tuoc ;x=j { \ } ;"n

devired gnitcurtseD" << tuoc { )(devired~ \ } ;"n

" << k << " " << j << " " << i << tuoc { )(wohs diov \ } ;"n

;}

)(niam tni

{

;)5 ,4 ,3(bo devired

5 3 4 syalpsid // ;)(wohs.bo

;0 nruter

}

mi si tI esab a ot stnemugra taht dnatsrednu ot tnatrop - ot stnemugra aiv dessap era rotcurtsnoc ssalc

yna esu ton seod rotcurtsnoc 'ssalc devired a fi neve ,eroferehT .rotcurtsnoc 'ssalc devired eht

qer ssalc esab eht fi eno eralced ot deen llits lliw ti ,stnemugra eht ,noitautis siht nI .ti seriu

siht ni ,elpmaxe roF .esab eht ot gnola dessap ylpmis era ssalc devired eht ot dessap stnemugra

tub ,stnemugra on sekat rotcurtsnoc 'ssalc devired eht ,margorp )(1esab dna )(2esab :od

>maertsoi< edulcni#

ts ecapseman gnisu ;d

{ 1esab ssalc

:detcetorp

;i tni

:cilbup

1esab gnitcurtsnoC" << tuoc ;x=i { )x tni(1esab \ } ;"n

1esab gnitcurtseD" << tuoc { )(1esab~ \ } ;"n

;}

{ 2esab ssalc

:detcetorp

Page 79: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 67

;k tni

:cilbup

2esab gnitcurtsnoC" << tuoc ;x=k { )x tni(2esab \ } ;"n

<< tuoc { )(2esab~ 2esab gnitcurtseD" \ } ;"n

;}

{ 2esab cilbup ,1esab cilbup :devired ssalc

:cilbup

,retemarap on sesu rotcurtsnoc devireD */

ot meht gnikat sa deralced eb tsum llits tub

.sessalc esab ot gnola meht ssap

/*

)y(2esab ,)x(1esab :)y tni ,x tni(devired

<< tuoc { devired gnitcurtsnoC" \ } ;"n

devired gnitcurtseD" << tuoc { )(devired~ \ } ;"n

" << k << " " << i << tuoc { )(wohs diov \ } ;"n

;}

)(niam tni

{

;)4 ,3(bo devired

4 3 syalpsid // ;)(wohs.bo

;0 nruter

}

o esu ekam ot eerf si noitcnuf rotcurtsnoc 'ssalc devired A deralced si ti taht sretemarap lla dna yna f

tnemugra na gnissap ,yltnereffid tuP .ssalc esab a ot gnola dessap era erom ro eno fi neve ,gnikat sa

siht ,elpmaxe roF .llew sa ssalc devired eht yb esu sti edulcerp ton seod ssalc esab a ot gnola

p si tnemgarf :dilav yltcefre

{ esab cilbup :devired ssalc

;j tni

:cilbup

Page 80: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 77

.esab ot meht sessap neht dna y dna x htob sesu devired //

)y ,x(esab :)y tni ,x tni(devired

devired gnitcurtsnoC" << tuoc ;y*x = j { \ } ;"n

stnemugra gnissap nehw dnim ni peek ot tniop lanif enO esab ot - tnemugra ehT :srotcurtsnoc ssalc

ni si sihT .selbairav dna sllac noitcnuf sedulcni sihT .emit eht ta dilav noisserpxe yna fo tsisnoc nac

.noitazilaitini cimanyd swolla ++C taht tcaf eht htiw gnipeek

sseccA gnitnarG

detirehni si ssalc esab a nehW sa etavirp emoceb ssalc taht fo srebmem detcetorp dna cilbup lla ,

erotser ot tnaw yam uoy ,secnatsmucric niatrec ni ,revewoH .ssalc devired eht fo srebmem etavirp

thgim uoy ,elpmaxe roF .noitacificeps ssecca lanigiro rieht ot srebmem detirehni erom ro eno tnaw

eht hguoht neve ssalc devired eht ni sutats cilbup ssalc esab eht fo srebmem cilbup niatrec tnarg ot

sa detirehni si ssalc esab etavirp ,tsriF .siht hsilpmocca ot syaw owt evah uoy ,++C dradnatS nI .

a esu nac uoy gnisu rreferp eht si hcihw ,tnemetats ehT .yaw de gnisu dengised si tnemetats

na erotser ot yaw dnoces ehT .32 retpahC ni dessucsid si dna secapseman troppus ot yliramirp

na yolpme ot si noitacificeps ssecca s'rebmem detirehni noitaralced ssecca .ssalc devired eht nihtiw

ra snoitaralced sseccA snaem sihT .detacerped era yeht tub ,++C dradnatS yb detroppus yltnerruc e

taht smargorp gnitsixe ynam ,ynam llits era ereht ecniS .edoc wen rof desu eb ton dluohs yeht taht

.ereh denimaxe eb lliw yeht ,snoitaralced ssecca esu

sekat noitaralced ssecca nA :mrof lareneg siht

esab - rebmem::ssalc ;

.noitaralced 'ssalc devired eht ni gnidaeh ssecca etairporppa eht rednu tup si noitaralced ssecca ehT

.noitaralced ssecca na ni )dewolla ,deedni ,ro( deriuqer si noitaralced epyt on taht ecitoN

ecca na woh ees oT :tnemgarf trohs siht htiw nigeb s'tel ,skrow noitaralced ss

Page 81: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 87

{ esab ssalc

:cilbup

esab ni cilbup // ;j tni

;}

.etavirp sa esab tirehnI //

{ esab etavirp :devired ssalc

:cilbup

noitaralced ssecca si ereh //

niaga cilbup j ekam // ;j::esab

.

.

.

;}

esuaceB esab sa detirehni si etavirp yb devired rebmem cilbup eht , j fo rebmem etavirp a edam si

devired gnidulcni yb ,revewoH .

;j::esab

rednu noitaralced ssecca eht sa devired s' cilbup ,gnidaeh j .sutats cilbup sti ot derotser si

taralced ssecca na esu nac uoY .srebmem detcetorp dna cilbup fo sthgir ssecca eht erotser ot noi

roF .sutats ssecca s'rebmem a rewol ro esiar ot noitaralced ssecca na esu tonnac uoy ,revewoH

.ssalc devired a yb cilbup edam eb tonnac ssalc esab a ni etavirp sa deralced rebmem a ,elpmaxe fI(

)!msinahcem noitaluspacne sti yortsed dluow ti ,rucco ot siht dewolla ++C

ot snoitaralced ssecca sesu ti woh eciton ;noitaralced ssecca eht setartsulli margorp gniwollof ehT

erotser j , ,)(ites dna )(iteg ot cilbup .sutats

>maertsoi< edulcni#

man gnisu ;dts ecapse

{ esab ssalc

Page 82: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 97

esab ot etavirp // ;i tni

:cilbup

;k ,j tni

} ;x = i { )x tni(ites diov

} ;i nruter { )(iteg tni

;}

.etavirp sa esab tirehnI //

{ esab etavirp :devired ssalc

:cilbup

edirrevo stnemetats eerht txen ehT */

avirp sa ecnatirehni s'esab ,j erotser dna et

/* .ssecca cilbup ot )(iteg dna ,)(ites

niaga cilbup j ekam // ;j::esab - k ton tub

cilbup )(ites ekam // ;ites::esab

cilbup )(iteg ekam // ;iteg::esab

ssecca etavele tonnac uoy ,lagelli // ;i::esab //

cilbup // ;a tni

;}

)(niam tni

{

red ;bo devi

devired ni etavirp si i esuaceb lagelli // ;01 = i.bo//

devired ni cilbup edam si j esuaceb lagel // ;02 = j.bo

devired ni etavirp si k esuaceb lagelli // ;03 = k.bo//

devired ni cilbup si a esuaceb lagel // ;04 = a.bo

;)01(ites.bo

iteg.bo << tuoc ;a.bo << " " << j.bo << " " << )(

;0 nruter

}

Page 83: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 08

na fo tsom hcihw ni snoitautis esoht etadommocca ot ++C ni detroppus era snoitaralced sseccA

ro cilbup rieht niater ot era srebmem wef a tub ,etavirp edam eb ot dednetni si ssalc detirehni

.sutats detcetorp

hW yeht taht snaem sihT .detacerped era yeht ,snoitaralced ssecca stroppus llits ++C dradnatS eli

stseggus dradnats eht ,daetsnI .erutuf eht ni detroppus eb ton thgim yeht tub ,won rof dewolla era

eht gniylppa yb tceffe emas eht gniveihca gnisu .drowyek

triV sessalC esaB lau

era sessalc esab elpitlum nehw margorp ++C a otni decudortni eb nac ytiugibma fo tnemele nA

:margorp tcerrocni siht redisnoc ,elpmaxe roF .detirehni

.elipmoc ton lliw dna rorre na sniatnoc margorp sihT //

>maertsoi< edulcni#

pseman gnisu ;dts eca

{ esab ssalc

:cilbup

;i tni

;}

.esab stirehni 1devired //

{ esab cilbup : 1devired ssalc

:cilbup

;j tni

;}

.esab stirehni 2devired //

{ esab cilbup : 2devired ssalc

:cilbup

;k tni

;}

.2devired dna 1devired htob stirehni 3devired */

Page 84: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 18

taht snaem sihT esab fo seipoc owt era ereht

/* !3devired ni

{ 2devired cilbup ,1devired cilbup : 3devired ssalc

:cilbup

;mus tni

;}

)(niam tni

{ rebmem

;bo 3devired

???i hcihw ,suougibma si siht // ;01 = i.bo

;02 = j.bo

;03 = k.bo

oot ,ereh suougibma i //

+ i.bo = mus.bo ;k.bo + j.bo

?i hcihw ,suougibma osla //

;" " << i.bo << tuoc

;" " << k.bo << " " << j.bo << tuoc

;mus.bo << tuoc

;0 nruter

}

htob ,etacidni margorp eht ni stnemmoc eht sA 1devired dna 2devired tirehni esab ,revewoH .

3devired htob stirehni 1devired dna ed 2devir fo seipoc owt era ereht taht snaem sihT . esab tneserp

epyt fo tcejbo na ni 3devired ekil noisserpxe na ni ,eroferehT .

;01 = i.bo

hcihw i ni eno eht ,ot derrefer gnieb si 1devired ni eno eht ro ?2devired owt era ereht esuaceB

fo seipoc esab tneserp tcejbo ni bo owt era ereht , i.bo yltnerehni si tnemetats eht ,ees nac uoy sA !s

.suougibma

Page 85: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 28

noituloser epocs eht ylppa ot si tsrif ehT .margorp gnidecerp eht ydemer ot syaw owt era erehT

ot rotarepo i eno tceles yllaunam dna .i o noisrev siht ,elpmaxe roF dna elipmoc seod margorp eht f

:detcepxe sa nur

.i tceles ot noituloser epocs ticilpxe sesu margorp sihT //

>maertsoi< edulcni#

;dts ecapseman gnisu

{ esab ssalc

:cilbup

;i tni

;}

.esab stirehni 1devired //

{ esab cilbup : 1devired ssalc

:cilbup

;j tni

;}

.esab stirehni 2devired //

{ esab cilbup : 2devired ssalc

:cilbup

;k tni

;}

.2devired dna 1devired htob stirehni 3devired */

esab fo seipoc owt era ereht taht snaem sihT

/* !3devired ni

{ 2devired cilbup ,1devired cilbup : 3devired ssalc

:cilbup

;mus tni

;}

)(niam tni

{

;bo 3devired

Page 86: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 38

i s'1devired esu ,devloser epocs // ;01 = i::1devired.bo

;02 = j.bo

;03 = k.bo

devloser epocs //

;k.bo + j.bo + i::1devired.bo = mus.bo

ereh devloser osla //

;" " << i::1devired.bo << tuoc

;" " << k.bo << " " << j.bo << tuoc

oc ;mus.bo << tu

;0 nruter

}

eht esuaceb ,ees nac uoy sA :: detceles yllaunam sah margorp eht ,deilppa saw 1devired noisrev s'

fo esab fo ypoc eno ylno fi tahW :eussi repeed a sesiar noitulos siht ,revewoH . esab yllautca si

everp ot yaw emos ereht sI ?deriuqer ni dedulcni gnieb morf seipoc owt tn 3devired sa ,rewsna ehT ?

gnisu deveihca si noitulos sihT .sey si ,desseug evah ylbaborp uoy lautriv .sessalc esab

seipoc elpitlum tneverp nac uoy ,ssalc esab nommoc a morf devired era stcejbo erom ro owt nehW

sab eht fo esab eht gniralced yb stcejbo esoht morf devired tcejbo na ni tneserp gnieb morf ssalc e

sa ssalc lautriv eht htiw eman 'ssalc esab eht gnidecerp yb siht hsilpmocca uoY .detirehni si ti nehw

drowyek lautriv ehtona si ereh ,elpmaxe roF .detirehni si ti nehw margorp elpmaxe eht fo noisrev r

hcihw ni 3devired sniatnoc

fo ypoc eno ylno :esab

.sessalc esab lautriv sesu margorp sihT //

>maertsoi< edulcni#

;dts ecapseman gnisu

{ esab ssalc

:cilbup

;i tni

;}

.lautriv sa esab stirehni 1devired //

iv : 1devired ssalc { esab cilbup lautr

Page 87: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 48

:cilbup

;j tni

;}

.lautriv sa esab stirehni 2devired //

{ esab cilbup lautriv : 2devired ssalc

:cilbup

;k tni

;}

.2devired dna 1devired htob stirehni 3devired */

/* .ssalc esab fo ypoc eno ylno si ereht ,emit sihT

ilbup : 3devired ssalc { 2devired cilbup ,1devired c

:cilbup

;mus tni

;}

)(niam tni

{

;bo 3devired

suougibmanu won // ;01 = i.bo

;02 = j.bo

;03 = k.bo

suougibmanu //

;k.bo + j.bo + i.bo = mus.bo

suougibmanu //

;" " << i.bo << tuoc

;" " << k.bo << " " << j.bo << tuoc

s.bo << tuoc ;mu

;0 nruter

}

drowyek eht ,ees nac uoy sA lautriv detirehni eht fo tser eht sedecerp ssalc taht woN .noitacificeps '

htob 1devired dna 2devired detirehni evah esab sa lautriv gnivlovni ecnatirehni elpitlum yna ,

Page 88: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 58

fo ypoc eno ylno esuac lliw meht esab eb ot ni ,eroferehT .tneserp 3devired ypoc eno ylno si ereht ,

fo esab dna 01 = i.bo .suougibmanu dna dilav yltcefrep si

htob hguoht nevE :dnim ni peek ot tniop rehtruf enO 1devired dna 2devired yficeps esab sa

lautriv , esab rehtie fo stcejbo ni tneserp llits si eht ,elpmaxe roF .epyt si ecneuqes gniwollof

:dilav yltcefrep

1devired epyt fo ssalc a enifed //

;ssalcym 1devired

;88 = i.ssalcym

a dna ssalc esab lamron a neewteb ecnereffid ylno ehT lautriv tcejbo na nehw srucco tahw si eno

ht erom esab eht stirehni fI .ecno na lautriv tneserp si ssalc esab eno ylno neht ,desu era sessalc esab

.dnuof eb lliw seipoc elpitlum ,esiwrehtO .tcejbo eht ni

Page 89: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 68

TINU – IV

SNOITCNUF LAUTRIV

pmoC .emit nur ta dna emit elipmoc ta htob ++C yb detroppus si msihpromyloP eli - emit

nuR .srotarepo dna snoitcnuf gnidaolrevo yb deveihca si msihpromylop - si msihpromylop emit

.retpahc siht fo scipot eht era eseht dna ,snoitcnuf lautriv dna ecnatirehni gnisu yb dehsilpmocca

snoitcnuF lautriV

A noitcnuf lautriv oitcnuf rebmem a si a yb denifeder dna ssalc esab a nihtiw deralced si taht n

htiw ssalc esab eht ni noitaralced s'noitcnuf eht edecerp ,noitcnuf lautriv a etaerc oT .ssalc devired

drowyek eht lautriv ssalc devired eht ,detirehni si noitcnuf lautriv a gniniatnoc ssalc a nehW .

eno" eht tnemelpmi snoitcnuf lautriv ,ecnesse nI .sdeen nwo sti tif ot noitcnuf lautriv eht senifeder

nihtiw noitcnuf lautriv ehT .msihpromylop seilrednu taht yhposolihp "sdohtem elpitlum ,ecafretni

eht senifed ssalc esab eht mrof eht fo ecafretni taht ot lautriv eht fo noitinifeder hcaE .noitcnuf

.ssalc devired eht ot yllacificeps setaler ti sa noitarepo sti stnemelpmi ssalc devired a yb noitcnuf

a setaerc noitinifeder eht ,si tahT dohtem cificeps .

tsuj evaheb snoitcnuf lautriv ",yllamron" dessecca nehW rebmem ssalc fo epyt rehto yna ekil

nur gnitroppus fo elbapac dna tnatropmi snoitcnuf lautriv sekam tahw ,revewoH .noitcnuf - emit

esab A .retniop a aiv dessecca nehw evaheb yeht woh si msihpromylop - ot desu eb nac retniop ssalc

salc yna fo tcejbo na ot tniop devired a ot stniop retniop esab a nehW .esab taht morf devired s

desab llac ot noitcnuf taht fo noisrev hcihw senimreted ++C ,noitcnuf lautriv a sniatnoc taht tcejbo

nopu ot detniop tcejbo fo epyt eht edam si noitanimreted siht dnA .retniop eht yb nur ta emit ,suhT .

ehT .detucexe era noitcnuf lautriv eht fo snoisrev tnereffid ,ot detniop era stcejbo tnereffid nehw

esab ot seilppa tceffe emas - .secnerefer ssalc

:elpmaxe trohs siht enimaxe ,nigeb oT

>maertsoi< edulcni#

;dts ecapseman gnisu

Page 90: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 78

{ esab ssalc

lbup :ci

{ )(cnufv diov lautriv

.)(cnufv s'esab si sihT" << tuoc \ ;"n

}

;}

{ esab cilbup : 1devired ssalc

:cilbup

{ )(cnufv diov

.)(cnufv s'1devired si sihT" << tuoc \ ;"n

}

;}

{ esab cilbup : 2devired ssalc

:cilbup

{ )(cnufv diov

cnufv s'2devired si sihT" << tuoc .)( \ ;"n

}

;}

)(niam tni

{

;b ,p* esab

;1d 1devired

;2d 2devired

esab ot tniop //

;b& = p

p- )(cnufv s'esab ssecca // ;)(cnufv>

1devired ot tniop //

;1d& = p

p- )(cnufv s'1devired ssecca // ;)(cnufv>

2devired ot tniop //

;2d& = p

Page 91: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 88

p- devired ssecca // ;)(cnufv> )(cnufv s'2

;0 nruter

}

:gniwollof eht syalpsid margorp sihT

.)(cnufv s'esab si sihT

.)(cnufv s'1devired si sihT

.)(cnufv s'2devired si sihT

edisni ,setartsulli margorp eht sA esab noitcnuf lautriv eht , )(cnufv eht taht ecitoN .deralced si

drowyek autriv l nehW .noitaralced noitcnuf eht fo tser eht sedecerp )(cnufv yb denifeder si

1devired dna 2devired drowyek eht , lautriv ti edulcni ot rorre na ton si ti ,revewoH( .dedeen ton si

deen ton tsuj s'ti ;ssalc devired a edisni noitcnuf lautriv a gninifeder nehw ).de

,margorp siht nI esab htob yb detirehni si 1devired dna 2devired ,noitinifed ssalc hcae edisnI .

)(cnufv edisnI .ssalc taht ot evitaler denifeder si ,)(niam :deralced era selbairav ruof

emaN epyT

p retniop ssalc esab

b esab fo tcejbo

1d 1devired fo tcejbo

2d 2devired fo tcejbo

,txeN p fo sserdda eht dengissa si ,b dna )(cnufv aiv dellac si p ecniS . p fo tcejbo na ot gnitniop si

epyt esab fo noisrev taht , )(cnufv ,txeN .detucexe si p fo sserdda eht ot tes si 1d niaga dna , )(cnufv

ac si gnisu yb dell p emit sihT . p epyt fo tcejbo na ot stniop 1devired sesuac sihT .

)(cnufv::1devired ,yllaniF .detucexe eb ot p fo sserdda eht dengissa si ,2d dna p -- )(cnufv> sesuac

fo noisrev eht )(cnufv edisni denifeder 2devired tniop yek ehT .detucexe eb ot dnik eht taht si ereh

hcihw ot tcejbo fo p fo noisrev hcihw senimreted stniop )(cnufv siht ,rehtruF .detucexe si

nur rof sisab eht smrof ssecorp siht dna ,emit nur ta edam si noitanimreted - .msihpromylop emit

Page 92: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 98

ht ni noitcnuf lautriv a llac nac uoy hguohtlA eht dna eman s'tcejbo na gnisu yb rennam "lamron" e

esab a hguorht si ssecca nehw ylno si ti ,rotarepo tod - nur taht )ecnerefer ro( retniop ssalc - emit

yllacitcatnys si siht ,elpmaxe gnidecerp eht gnimussa ,elpmaxe roF .deveihca si msihpromylop

:dilav

fv.2d )(cnufv s'2devired sllac // ;)(cnu

fo egatnavda ekat ton seod ylpmis ti ,gnorw ton si rennam siht ni noitcnuf lautriv a gnillac hguohtlA

fo erutan lautriv eht )(cnufv .

is sraeppa ssalc devired a yb noitcnuf lautriv a fo noitinifeder eht ,ecnalg tsrif tA noitcnuf ot ralim

mret eht dna ,esac eht ton si siht ,revewoH .gnidaolrevo gnidaolrevo lautriv ot deilppa ton si

eht taht si tnatropmi tsom eht spahreP .tsixe secnereffid lareves esuaceb noitinifeder noitcnuf

tsum noitcnuf lautriv denifeder a rof epytotorp esab eht ni deificeps epytotorp eht yltcaxe hctam

dna rebmun eht dna sepyt nruter hcihw ni ,noitcnuf lamron a gnidaolrevo morf sreffid sihT .ssalc

epyt eht ro rebmun eht rehtie ,noitcnuf a daolrevo uoy nehw ,tcaf nI( .reffid yam sretemarap fo epyt

eht fo sretemarap tsum noisrev tcerroc eht tceles nac ++C taht secnereffid eseht hguorht si tI !reffid

sti fo stcepsa lla ,denifeder si noitcnuf lautriv a nehw ,revewoH ).noitcnuf dedaolrevo na fo

a uoy nehw epytotorp eht egnahc uoy fI .emas eht eb tsum epytotorp lautriv a enifeder ot tpmett

lautriv sti dna ,relipmoc ++C eht yb dedaolrevo deredisnoc eb ylpmis lliw noitcnuf eht ,noitcnuf

srebmem citatsnon eb tsum snoitcnuf lautriv taht si noitcirtser tnatropmi rehtonA .tsol eb lliw erutan

eht hcihw fo sessalc eht fo eb tonnac yehT .trap era y dneirf tonnac snoitcnuf rotcurtsnoc ,yllaniF .s

noitcnuf neewteb secnereffid dna snoitcirtser eht fo esuaceB .nac snoitcnuf rotcurtsed tub ,lautriv eb

mret eht ,noitinifeder noitcnuf lautriv dna gnidaolrevo gnidirrevo d ot desu si noitcnuf lautriv ebircse

.ssalc devired a yb noitinifeder

ecnerefeR ssalC esaB a hguorhT noitcnuF lautriV a gnillaC

esab a hguorht dellac saw noitcnuf lautriv A - lautriv a fo erutan cihpromylop eht tub ,retniop ssalc

dellac nehw elbaliava osla si noitcnuf esab a hguorht - ticilpmi na si ecnerefer A .ecnerefer ssalc

tcejbo yna ro ssalc esab eht fo tcejbo na ot refer ot desu eb nac ecnerefer ssalc esab a ,suhT .retniop

Page 93: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 09

esab a hguorht dellac si noitcnuf lautriv a nehW .esab taht morf devired - ht ,ecnerefer ssalc noisrev e

.llac eht fo emit eht ta ot derrefer gnieb tcejbo eht yb denimreted si detucexe noitcnuf eht fo

si ecnerefer ssalc esab a hguorht dekovni si noitcnuf lautriv a hcihw ni noitautis nommoc tsom ehT

xe roF .retemarap noitcnuf a si ecnerefer eht nehw eht no noitairav gniwollof eht redisnoc ,elpma

.margorp gnidecerp

/* .noitcnuf lautriv a ssecca ot desu si ecnerefer ssalc esab a ,ereH */

>maertsoi< edulcni#

;dts ecapseman gnisu

{ esab ssalc

:cilbup

{ )(cnufv diov lautriv

)(cnufv s'esab si sihT" << tuoc .\ ;"n

}

;}

{ esab cilbup : 1devired ssalc

:cilbup

{ )(cnufv diov

.)(cnufv s'1devired si sihT" << tuoc \ ;"n

}

;}

{ esab cilbup : 2devired ssalc

:cilbup

{ )(cnufv diov

.)(cnufv s'2devired si sihT" << tuoc \ ;"n

}

;}

.retemarap ecnerefer ssalc esab a esU //

diov { )r& esab(f

;)(cnufv.r

Page 94: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 19

}

)(niam tni

{

;b esab

;1d 1devired

;2d 2devired

)(f ot tcejbo esab a ssap // ;)b(f

)(f ot tcejbo 1devired a ssap // ;)1d(f

)(f ot tcejbo 2devired a ssap // ;)2d(f

;0 nruter

}

gnidecerp sti sa tuptuo emas eht secudorp margorp sihT noitcnuf eht ,elpmaxe siht nI .noisrev )(f

epyt fo retemarap ecnerefer a senifed esab edisnI . )(niam fo stcejbo gnisu dellac si noitcnuf eht ,

epyt esab , 1devired dna , 2devired edisnI . )(f fo noisrev cificeps eht , )(cnufv si dellac si taht

yb denimreted .dellac si noitcnuf eht nehw decnerefer gnieb tcejbo fo epyt eht

hguorht snoitcnuf lautriv llac lliw retpahc siht ni selpmaxe eht fo tser eht ,yticilpmis fo ekas eht roF

esab - esab rof emas era stceffe eht tub ,sretniop ssalc - .secnerefer ssalc

lautriV ehT detirehnI sI etubirttA

a nehw taht snaem sihT .detirehni osla si erutan lautriv sti ,detirehni si noitcnuf lautriv a nehW

devired rehtona rof ssalc esab a sa desu flesti si noitcnuf lautriv a detirehni sah taht ssalc devired

c noitcnuf lautriv eht ,ssalc a semit ynam woh rettam on ,yltnereffid tuP .neddirrevo eb llits na

:margorp siht redisnoc ,elpmaxe roF .lautriv sniamer ti ,detirehni si noitcnuf lautriv

>maertsoi< edulcni#

;dts ecapseman gnisu

{ esab ssalc

:cilbup

Page 95: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 29

{ )(cnufv diov lautriv

i sihT" << tuoc .)(cnufv s'esab s \ ;"n

}

;}

{ esab cilbup : 1devired ssalc

:cilbup

{ )(cnufv diov

.)(cnufv s'1devired si sihT" << tuoc \ ;"n

}

;}

)(cnufv noitcnuf lautriv stirehni 2devired */

/* .1devired morf

{ 1devired cilbup : 2devired ssalc

:cilbup

iv llits si )(cnufv // lautr

{ )(cnufv diov

.)(cnufv s'2devired si sihT" << tuoc \ ;"n

}

;}

)(niam tni

{

;b ,p* esab

;1d 1devired

;2d 2devired

esab ot tniop //

;b& = p

p- )(cnufv s'esab ssecca // ;)(cnufv>

1devired ot tniop //

;1d& = p

p- )(cnufv s'1devired ssecca // ;)(cnufv>

op // 2devired ot tni

Page 96: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 39

;2d& = p

p- )(cnufv s'2devired ssecca // ;)(cnufv>

;0 nruter

}

:tuptuo siht syalpsid margorp gnidecerp eht ,detcepxe sA

.)(cnufv s'esab si sihT

.)(cnufv s'1devired si sihT

.)(cnufv s'2devired si sihT

,esac siht nI 2devired stirehni 1devired naht rehtar esab tub , )(cnufv .lautriv llits si

lacihcrareiH erA snoitcnuF lautriV

sa deralced si noitcnuf a nehW lautriv .ssalc devired a yb neddirrevo eb yam ti ,ssalc esab a yb

salc devired a nehW .neddirrevo eb ot evah ton seod noitcnuf eht ,revewoH a edirrevo ot sliaf s

noitcnuf eht ,noitcnuf taht sessecca ssalc devired taht fo tcejbo na nehw neht ,noitcnuf lautriv

hcihw ni margorp siht redisnoc ,elpmaxe roF .desu si ssalc esab eht yb denifed 2devired ton seod

edirrevo )(cnufv :

>maertsoi< edulcni#

;dts ecapseman gnisu

{ esab ssalc

:cilbup

{ )(cnufv diov lautriv

.)(cnufv s'esab si sihT" << tuoc \ ;"n

}

;}

{ esab cilbup : 1devired ssalc

:cilbup

{ )(cnufv diov

.)(cnufv s'1devired si sihT" << tuoc \ ;"n

Page 97: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 49

}

;}

{ esab cilbup : 2devired ssalc

:cilbup

)(cnufv // desu si s'esab ,2devired yb neddirrevo ton

;}

)(niam tni

{

;b ,p* esab

;1d 1devired

;2d 2devired

esab ot tniop //

;b& = p

p- )(cnufv s'esab ssecca // ;)(cnufv>

1devired ot tniop //

;1d& = p

p- )(cnufv s'1devired ssecca // ;)(cnufv>

2devired ot tniop //

= p ;2d&

p- )(cnufv s'esab esu // ;)(cnufv>

;0 nruter

}

:tuptuo siht secudorp margorp ehT

.)(cnufv s'esab si sihT

.)(cnufv s'1devired si sihT

.)(cnufv s'esab si sihT

Page 98: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 59

esuaceB 2devired edirrevo ton seod )(cnufv yb denifed noitcnuf eht , esab nehw desu si nufv )(c si

epyt fo stcejbo ot evitaler decnerefer 2devired .

si ecnatirehni esuaceB .elur lareneg erom a fo esac laiceps a setartsulli margorp gnidecerp ehT

nehw taht snaem sihT .lacihcrareih osla era snoitcnuf lautriv taht esnes sekam ti ,++C ni lacihcrareih

fo redro esrever ni dnuof noitinifeder tsrif eht ,noitcnuf lautriv a edirrevo ot sliaf ssalc devired a

,margorp gniwollof eht ni ,elpmaxe roF .desu si noitavired 2devired morf devired si 1devired ,

morf devired si hcihw esab ,revewoH . 2devired evo ton seod edirr )(cnufv ,taht snaem sihT .

ot evitaler 2devired fo noisrev tsesolc eht , )(cnufv ni si 1devired si ti ,eroferehT .

)(cnufv::1devired fo tcejbo na nehw desu si taht 2devired llac ot stpmetta )(cnufv .

>maertsoi< edulcni#

;dts ecapseman gnisu

esab ssalc {

:cilbup

{ )(cnufv diov lautriv

.)(cnufv s'esab si sihT" << tuoc \ ;"n

}

;}

{ esab cilbup : 1devired ssalc

:cilbup

{ )(cnufv diov

.)(cnufv s'1devired si sihT" << tuoc \ ;"n

}

;}

{ 1devired cilbup : 2devired ssalc

:cilbup

2devired yb neddirrevo ton )(cnufv */ .

morf devired si 2devired ecnis ,esac siht nI

.desu si )(cnufv s'1devired ,1devired

/*

Page 99: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 69

;}

)(niam tni

{

;b ,p* esab

;1d 1devired

;2d 2devired

esab ot tniop //

;b& = p

p- )(cnufv s'esab ssecca // ;)(cnufv>

1devired ot tniop //

;1d& = p

p- ssecca // ;)(cnufv> )(cnufv s'1devired

2devired ot tniop //

;2d& = p

p- )(cnufv s'1devired esu // ;)(cnufv>

;0 nruter

}

:gniwollof eht syalpsid margorp ehT

.)(cnufv s'esab si sihT

.)(cnufv s'1devired si sihT

.)(cnufv s'1devired si sihT

snoitcnuF lautriV eruP

nidecerp eht nI eht ,ssalc devired a yb denifeder ton si noitcnuf lautriv a nehw ,etartsulli noitces g

on eb nac ereht snoitautis ynam ni ,revewoH .desu eb lliw ssalc esab eht ni denifed noisrev

,elpmaxe roF .ssalc esab a nihtiw noitcnuf lautriv a fo noitinifed lufgninaem eb ton yam ssalc esab a

esab a wolla ot yltneiciffus tcejbo na enifed ot elba - ni ,rehtruF .detaerc eb ot noitcnuf lautriv ssalc

oT .noitcnuf lautriv a edirrevo sessalc devired lla taht erusne ot tnaw lliw uoy snoitautis emos

us ++C ,sesac owt eseht eldnah .noitcnuf lautriv erup eht stropp

Page 100: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 79

A noitcnuf lautriv erup a eralced oT .ssalc esab eht nihtiw noitinifed on sah taht noitcnuf lautriv a si

:mrof lareneg siht esu ,noitcnuf lautriv erup

lautriv cnuf epyt - retemarap(eman - tsil ;0 = )

noitcnuf lautriv a nehW eht fI .noitinifed nwo sti edivorp tsum ssalc devired yna ,erup edam si

elipmoc a ,noitcnuf lautriv erup eht edirrevo ot sliaf ssalc devired - .tluser lliw rorre emit

salc esab ehT .noitcnuf lautriv erup a fo elpmaxe elpmis a sniatnoc margorp gniwollof ehT ,s

rebmun dellac regetni na sniatnoc , lav noitcnuf eht , )(lavtes noitcnuf lautriv erup eht dna , )(wohs .

sessalc devired ehT epytxeh , epytced dna , epyttco tirehni rebmun enifeder dna )(wohs ti taht os

fo eulav eht stuptuo lav sab rebmun evitcepser hcae ni .)latco ro ,lamiced ,lamicedaxeh ,si taht( e

>maertsoi< edulcni#

;dts ecapseman gnisu

{ rebmun ssalc

:detcetorp

;lav tni

:cilbup

} ;i = lav { )i tni(lavtes diov

noitcnuf lautriv erup a si )(wohs //

;0 = )(wohs diov lautriv

;}

rebmun cilbup : epytxeh ssalc {

:cilbup

{ )(wohs diov

" << lav << xeh << tuoc \ ;"n

}

;}

{ rebmun cilbup : epytced ssalc

Page 101: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 89

:cilbup

{ )(wohs diov

" << lav << tuoc \ ;"n

}

;}

{ rebmun cilbup : epyttco ssalc

:cilbup

{ )(wohs diov

" << lav << tco << tuoc \ ;"n

}

;}

)(niam tni

{

;d epytced

epytxeh ;h

;o epyttco

;)02(lavtes.d

02 syalpsid // ;)(wohs.d - lamiced

;)02(lavtes.h

41 syalpsid // ;)(wohs.h - lamicedaxeh

;)02(lavtes.o

42 syalpsid // ;)(wohs.o - latco

;0 nruter

}

ton yam ssalc esab a woh setartsulli ti ,elpmis etiuq si elpmaxe siht hguohtlA ot elba eb

,esac siht nI .noitcnuf lautriv a enifed yllufgninaem rebmun ecafretni nommoc eht sedivorp ylpmis

enifed ot nosaer on si erehT .esu ot sepyt devired eht rof )(wohs edisni rebmun fo esab eht ecnis

yawla nac uoy ,esruoc fO .denifednu si rebmun eht lautriv a fo noitinifed redlohecalp a etaerc s

gnikam ,revewoH .noitcnuf )(wohs ti enifeder deedni lliw sessalc devired lla taht serusne osla erup

.sdeen nwo rieht teem ot

Page 102: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 99

sessalc devired lla ,erup sa deralced si noitcnuf lautriv a nehw taht dnim ni peeK fI .ti edirrevo tsum

elipmoc a ,siht od ot sliaf ssalc devired a - .tluser lliw rorre emit

sessalC tcartsbA

eb ot dias si noitcnuf lautriv erup eno tsael ta sniatnoc taht ssalc A tcartsba tcartsba na esuaceB .

hcihw rof snoitcnuf erom ro eno sniatnoc ssalc ,)noitcnuf lautriv erup a ,si taht( noitinifed on si ereht

etelpmocni na setutitsnoc ssalc tcartsba na ,daetsnI .detaerc eb yam ssalc tcartsba na fo stcejbo on

.sessalc devired rof noitadnuof a sa desu si taht epyt

na fo stcejbo etaerc tonnac uoy hguohtlA na ot secnerefer dna sretniop etaerc nac uoy ,ssalc tcartsba

nur troppus ot sessalc tcartsba swolla sihT .ssalc tcartsba - nopu seiler hcihw ,msihpromylop emit

esab - .noitcnuf lautriv reporp eht tceles ot secnerefer dna sretniop ssalc

noitcnuF lautriV gnisU s

tcejbo fo stcepsa lartnec eht fo enO - ,ecafretni eno" fo elpicnirp eht si gnimmargorp detneiro

hcihw ot ecafretni eht ,denifed eb nac snoitca fo ssalc lareneg a taht snaem sihT ".sdohtem elpitlum

ificeps nwo sti gninifed noitavired hcae htiw ,tnatsnoc si esab a ,smret ++C etercnoc nI .snoitarepo c

neht ssalc devired hcaE .ssalc lareneg a ot ecafretni eht fo erutan eht enifed ot desu eb nac ssalc

.epyt devired eht yb desu atad fo epyt eht ot etaler yeht sa snoitarepo cificeps eht stnemelpmi

tsom eht fo enO "sdohtem elpitlum ,ecafretni eno" eht tnemelpmi ot syaw elbixelf dna lufrewop

nur dna ,sessalc tcartsba ,snoitcnuf lautriv esu ot si hcaorppa - eseht gnisU .msihpromylop emit

t esab( cificeps ot lareneg morf sevom taht yhcrareih ssalc a etaerc uoy ,serutaef .)devired o

sesac nI .ssalc esab a ni secafretni dna serutaef nommoc lla enifed uoy ,yhposolihp siht gniwolloF

nI .noitcnuf lautriv a esu ,ssalc devired eht yb ylno detnemelpmi eb nac snoitca niatrec erehw

e enifed dna etaerc uoy ssalc esab eht ni ,ecnesse .esac lareneg eht ot setaler taht nac uoy gnihtyrev

.sliated cificeps eht ni sllif ssalc devired ehT

Page 103: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 001

"sdohtem elpitlum ,ecafretni eno" eht fo eulav eht setartsulli taht elpmaxe elpmis a si gniwolloF

c smrofrep taht detaerc si yhcrareih ssalc A .yhposolihp ot stinu fo metsys eno morf snoisrevno

ssalc esab ehT ).snollag ot sretil ,elpmaxe roF( .rehtona trevnoc ,selbairav owt seralced 1lav dna

2lav snoitcnuf eht senifed osla tI .ylevitcepser ,seulav detrevnoc dna laitini eht dloh hcihw , )(tiniteg

dna (vnocteg ) fo stnemele esehT .eulav detrevnoc eht dna eulav laitini eht nruter hcihw , trevnoc

tirehni lliw taht sessalc devired lla ot elbacilppa dna dexif era trevnoc taht noitcnuf eht ,revewoH .

,noisrevnoc eht mrofrep yllautca lliw )(etupmoc lautriv erup a si , yb denifed eb tsum taht noitcnuf

morf devired sessalc eht trevnoc fo erutan cificeps ehT . )(etupmoc epyt tahw yb denimreted eb lliw

.ecalp gnikat si noisrevnoc fo

.elpmaxe lacitcarp noitcnuf lautriV //

>maertsoi< edulcni#

;dts ecapseman gnisu

revnoc ssalc { t

:detcetorp

eulav laitini // ;1lav elbuod

eulav detrevnoc // ;2lav elbuod

:cilbup

{ )i elbuod(trevnoc

;i = 1lav

}

} ;2lav nruter { )(vnocteg elbuod

} ;1lav nruter { )(tiniteg elbuod

;0 = )(etupmoc diov lautriv

;}

.snollag ot sretiL //

bup : g_ot_l ssalc { trevnoc cil

:cilbup

} { )i(trevnoc : )i elbuod(g_ot_l

{ )(etupmoc diov

;4587.3 / 1lav = 2lav

Page 104: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 101

}

;}

suisleC ot tiehnerhaF //

{ trevnoc cilbup : c_ot_f ssalc

:cilbup

} { )i(trevnoc : )i elbuod(c_ot_f

{ )(etupmoc diov

1lav( = 2lav - ;8.1 / )23

}

;}

)(niam tni

{

ssalc esab ot retniop // ;p* trevnoc

;)4(bogl g_ot_l

;)07(bocf c_ot_f

trevnoc ot msinahcem noitcnuf lautriv esu //

;bogl& = p

p << tuoc - ;" si sretil " << )(tiniteg>

p- ;)(etupmoc>

p << tuoc - snollag " << )(vnocteg> \ g_ot_l // ;"n

;bocf& = p

p << tuoc - niteg> ;" si tiehnerhaF ni " << )(ti

p- ;)(etupmoc>

p << tuoc - suisleC " << )(vnocteg> \ c_ot_f // ;"n

;0 nruter

}

morf sessalc devired owt setaerc margorp gnidecerp ehT trevnoc dellac , g_ot_l dna c_ot_f esehT .

na snollag ot sretil fo snoisrevnoc eht mrofrep sessalc hcaE .ylevitcepser ,suisleC ot tiehnerhaF d

sedirrevo ssalc devired )(etupmoc neve ,revewoH .noisrevnoc derised eht mrofrep ot yaw nwo sti ni

Page 105: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 201

neewteb sreffid )dohtem ,si taht( noisrevnoc lautca eht hguoht g_ot_l dna c_ot_f ecafretni eht ,

.tnatsnoc sniamer

ysae yrev a si esac wen a gnildnah taht si snoitcnuf lautriv dna sessalc devired fo stifeneb eht fo enO

ot teef morf noisrevnoc a dda nac uoy ,margorp gnidecerp eht gnimussa ,elpmaxe roF .rettam

:ssalc siht gnidulcni yb sretem

sretem ot teeF //

t_f ssalc { trevnoc cilbup : m_o

:cilbup

} { )i(trevnoc : )i elbuod(m_ot_f

{ )(etupmoc diov

;82.3 / 1lav = 2lav

}

;}

ni si snoitcnuf lautriv dna sessalc tcartsba fo esu tnatropmi nA seirarbil ssalc a etaerc nac uoY .

esu eb lliw taht yrarbil ssalc elbisnetxe ,cireneg lliw remmargorp rehtonA .sremmargorp rehto yb d

sessalc lla ot nommoc stnemele lla dna ecafretni eht senifed hcihw ,ssalc lareneg ruoy tirehni

,seirarbil ssalc gnitaerc yB .ssalc devired eht ot cificeps snoitcnuf esoht dda lliw dna ,ti morf devired

era uoy rehto gnittel llits elihw ssalc lareneg a fo ecafretni eht lortnoc dna etaerc ot elba

.sdeen cificeps rieht ot ti tpada sremmargorp

ssalc esab ehT :tniop lanif enO trevnoc noitcnuf lautriv ehT .ssalc tcartsba na fo elpmaxe na si

)( etupmoc denifed ton si nihtiw trevnoc ehT .dedivorp eb nac noitinifed lufgninaem on esuaceb

ssalc trevnoc rof noitamrofni tneiciffus niatnoc ton seod ylpmis )( etupmoc ylno si tI .denifed eb ot

nehw trevnoc .detaerc si epyt etelpmoc a taht ssalc devired a yb detirehni si

lraE gnidniB etaL .sv y

Page 106: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 301

nur dna snoitcnuf lautriv no retpahc siht gnidulcnoc erofeB - smret owt era ereht ,msihpromylop emit

tcejbo dna ++C fo snoissucsid ni yltneuqerf desu era yeht esuaceb denifed eb ot deen taht - detneiro

:gnimmargorp gnidnib ylrae dna ib etal gnidn . gnidnib ylraE elipmoc ta rucco taht stneve ot srefer

ta nwonk si noitcnuf a llac ot dedeen noitamrofni lla nehw srucco gnidnib ylrae ,ecnesse nI .emit

dnuob era llac noitcnuf a dna tcejbo na taht snaem gnidnib ylrae ,yltnereffid tuP( .emit elipmoc

d dradnats gnidulcni( sllac noitcnuf lamron edulcni gnidnib ylrae fo selpmaxE ).noitalipmoc gniru

ylrae ot egatnavda niam ehT .srotarepo dedaolrevo dna ,sllac noitcnuf dedaolrevo ,)snoitcnuf yrarbil

ot yrassecen noitamrofni lla esuaceB .ycneiciffe si gnidnib elipmoc ta denimreted si noitcnuf a llac

.tsaf yrev era sllac noitcnuf fo sepyt eseht ,emit

si gnidnib ylrae fo etisoppo ehT gnidnib etal noitcnuf ot srefer gnidnib etal ,++C ot setaler ti sA .

snoitcnuf lautriV .emit nur litnu devloser ton era taht sllac uoy sA .gnidnib etal eveihca ot desu era

si dellac yllautca noitcnuf lautriv eht ,ecnerefer ro retniop esab a aiv si ssecca nehw ,wonk

eb tonnac siht sesac tsom ni esuaceB .retniop eht yb ot detniop tcejbo fo epyt eht yb denimreted

t elipmoc ta denimreted niam ehT .emit nur litnu deknil ton era noitcnuf eht dna tcejbo eht ,emi

etaerc ot uoy swolla gnidnib etal ,gnidnib ylrae ekilnU .ytilibixelf si gnidnib etal ot egatnavda

ivah tuohtiw setucexe margorp eht elihw gnirrucco stneve ot dnopser nac taht smargorp etaerc ot gn

devloser ton si llac noitcnuf a esuaceb taht dnim ni peeK ".edoc ycnegnitnoc" fo tnuoma egral a

.semit noitucexe rewols tahwemos rof ekam nac gnidnib etal ,emit nur litnu

Page 107: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 401

TINU – IIV

O/I ELIF ,CISAB SMETSYS O/I

smaertS ++C

ht ekiL C e - dessucsid erew smaertS .smaerts hguorht setarepo metsys O/I ++C eht ,metsys O/I desab

A :ezirammus ot ,revewoH .ereh detaeper eb ton lliw noissucsid taht ;9 retpahC ni liated ni maerts

A .noitamrofni semusnoc ro secudorp rehtie taht ecived lacigol a si lacisyhp a ot deknil si maerts

lacisyhp lautca eht hguoht neve yaw emas eht ni evaheb smaerts llA .metsys O/I eht yb ecived

eht ,emas eht evaheb smaerts lla esuaceB .yllaitnatsbus reffid yam ot detcennoc era yeht secived

no etarepo nac snoitcnuf O/I emas esu nac uoy ,elpmaxe roF .ecived lacisyhp fo epyt yna yllautriv

siht ot egatnavda ehT .neercs eht ot ro retnirp eht ot etirw ot elif a ot setirw taht noitcnuf emas eht

.metsys O/I eno ylno nrael deen uoy taht si hcaorppa

sessalC maertS ++C ehT

enoitnem sA ni metsys O/I sti rof troppus sedivorp ++C dradnatS ,d >maertsoi< a ,redaeh siht nI .

sessalc O/I ehT .snoitarepo O/I stroppus taht denifed si seihcrareih ssalc fo tes detacilpmoc rehtar

a ,81 retpahC ni denialpxe sA .sessalc etalpmet fo metsys a htiw nigeb eht senifed ssalc etalpmet

ssalc etalpmet a ecnO .etarepo lliw ti hcihw nopu atad eht gniyficeps ylluf tuohtiw ssalc a fo mrof

dradnatS ,yrarbil O/I eht ot setaler ti sA .detaerc eb nac ti fo secnatsni cificeps ,denifed neeb sah

azilaiceps owt setaerc ++C 8 rof eno :sessalc etalpmet O/I eht fo snoit - rof rehtona dna sretcarahc tib

8 eht ylno esu lliw koob sihT .sretcarahc ediw - tsom eht raf yb era yeht ecnis sessalc retcarahc tib

.htob ot ylppa seuqinhcet emas eht tuB .nommoc

nopu tliub si metsys O/I ++C ehT si tsrif ehT .seihcrareih ssalc etalpmet tnereffid tub detaler owt

wol eht morf devired - dellac ssalc O/I level fubmaerts_cisab wol ,cisab eht seilppus ssalc sihT . -

O/I ++C eritne eht rof troppus gniylrednu eht sedivorp dna ,snoitarepo tuptuo dna tupni level .metsys

esu ot deen ton lliw uoy ,gnimmargorp O/I decnavda gniod era uoy sselnU fubmaerts_cisab

morf devired si htiw gnikrow eb ylnommoc tsom lliw uoy taht yhcrareih ssalc ehT .yltcerid

soi_cisab hgih a si sihT . - e ,gnittamrof sedivorp taht ssalc O/I level sutats dna ,gnikcehc rorr

rof ssalc esab A( .O/I maerts ot detaler noitamrofni soi_cisab dellac si esab_soi senifed hcihw ,

yb desu stiart etalpmetnon lareves soi_cisab ). soi_cisab ,sessalc devired lareves rof esab a sa desu si

Page 108: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 501

gnidulcni maertsi_cisab , isab maertso_c dna , maertsoi_cisab etaerc ot desu era sessalc esehT .

.ylevitcepser ,tuptuo/tupni dna ,tuptuo ,tupni fo elbapac smaerts

tsuj seihcrareih ssalc etalpmet eht fo snoitazilaiceps owt setaerc yrarbil O/I eht ,denialpxe sA

8 rof eno :debircsed - ahc tib fo gnippam eht fo tsil a si ereH .sretcarahc ediw rof eno dna sretcar

ediw dna retcarahc rieht ot seman ssalc etalpmet - .snoisrev retcarahc

desabretcarahC ssalC etalpmeT

ssalC

ediW - desabretcarahC

ssalC

fubmaertsw fubmaerts fubmaerts_cisab

oiw soi soi_cisab s

maertsiw maertsi maertsi_cisab

maertsow maertso maertso_cisab

maertsoiw maertsoi maertsoi_cisab

maertsfw maertsf maertsf_cisab

maertsfiw maertsfi maertsfi_cisab

maertsfow maertsfo maertsfo_cisab

retcarahc ehT - iamer eht tuohguorht desu eb lliw seman desab eht era yeht ecnis ,koob siht fo redn

yb desu erew taht seman emas eht osla era yehT .smargorp ruoy ni esu yllamron lliw uoy taht seman

edoc ecruos eht ta elbitapmoc era yrarbil O/I wen eht dna dlo eht yhw si sihT .yrarbil O/I dlo eht

.level

tniop tsal enO ehT : soi rotinom ro lortnoc taht selbairav dna snoitcnuf rebmem ynam sniatnoc ssalc

uoy fi taht rebmemer tsuJ .yltneuqerf ot derrefer eb lliw tI .maerts a fo noitarepo latnemadnuf eht

edulcni >maertsoi< tropmi siht ot ssecca evah lliw uoy ,margorp ruoy ni .ssalc tna

smaertS denifederP s'++C

tliub ruof ,noitucexe snigeb margorp ++C a nehW - .denepo yllacitamotua era smaerts ni

:era yehT

eciveD tluafeD gninaeM maertS

draobyeK tupni dradnatS nic

neercS tuptuo dradnatS tuoc

Page 109: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 601

neercS tuptuo rorre dradnatS rrec

golc neercS rrec fo noisrev dereffuB

smaertS nic , tuoc dna , rrec s'C ot dnopserroc nidts , tuodts dna , rredts .

.elosnoc eht htiw etacinummoc ot desu era smaerts dradnats eht ,tluafed yB

SO ,xinU ,SOD sa hcus( noitcerider O/I troppus taht stnemnorivne ni ,revewoH ,)swodniW dna ,2/

eht ,yticilpmis fo ekas eht roF .selif ro secived rehto ot detcerider eb nac smaerts dradnats eht

.derrucco sah noitcerider O/I on taht emussa retpahc siht ni selpmaxe

:smaerts lanoitidda ruof eseht senifed osla ++C dradnatS niw , tuow , ew rr dna , golw era esehT .

ediw - epyt fo era sretcarahc ediW .smaerts dradnats eht fo snoisrev retcarahc t_rahcw era dna

61 yllareneg - htiw detaicossa stes retcarahc egral eht dloh ot desu era sretcarahc ediW .seititnauq tib

.segaugnal namuh emos

O/I dettamroF

,htdiw dleif a tes nac uoy ,elpmaxe roF .snoitarepo O/I tamrof ot uoy swolla metsys O/I ++C ehT

.deyalpsid eb lliw tniop lamiced eht retfa stigid ynam woh enimreted ro ,esab rebmun a yficeps

uoy taht syaw tnereffid yllautpecnoc tub detaler owt era erehT nac uoy ,tsriF .atad tamrof nac

eht fo srebmem ssecca yltcerid soi .ssalc

eht edisni denifed sgalf sutats tamrof suoirav tes nac uoy ,yllacificepS soi suoirav llac ro ssalc soi

dellac snoitcnuf laiceps esu nac uoy ,dnoceS .snoitcnuf rebmem srotalupinam aht dedulcni eb nac t

eht gnisu yb O/I dettamrof fo noissucsid eht nigeb lliw eW .noisserpxe O/I na fo trap sa soi rebmem

.sgalf dna snoitcnuf

srebmeM soi eht gnisU gnittamroF

ofni yaw eht lortnoc taht sgalf tamrof fo tes a ti htiw detaicossa sah maerts hcaE .dettamrof si noitamr

ehT soi dellac noitaremune ksamtib a seralced ssalc sgalftmf era seulav gniwollof eht hcihw ni

nihtiw denifed era seulav eseht ,yllacinhceT( .denifed esab_soi a si ,reilrae denialpxe sa ,hcihw ,

rof ssalc esab soi ).

eifesab dleiftsujda ced ahplaloob dl

lanretni xeh dleiftaolf dexif

Page 110: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 701

cifitneics thgir tco tfel

swpiks sopwohs tniopwohs esabwohs

esacreppu fubtinu

ton yam ti ,relipmoc redlo na gnisu era uoy fI .sgalf tamrof eht raelc ro tes ot desu era seulav esehT

eht enifed sgalftmf taremune gnol a otni dedocne eb lliw sgalf tamrof eht ,esac siht nI .epyt noi

.regetni

eht nehW swpiks etihw gnidael ,tes si galf - era )senilwen dna ,sbat ,secaps( sretcarahc ecaps

nehW .maerts a no tupni gnimrofrep nehw dedracsid swpiks etihw ,deraelc si - rahc ecaps era sretca

.dedracsid ton

eht nehW tfel nehW .deifitsuj tfel si tuptuo ,tes si galf thgir eht nehW .deifitsuj thgir si tuptuo ,tes si

lanretni ro ngis yna neewteb secaps gnitresni yb dleif a llif ot deddap si eulav ciremun a ,tes si galf

fI .retcarahc esab .tluafed yb deifitsuj thgir si tuptuo ,tes era sgalf eseht fo enon

.esab rebmun eht egnahc ot elbissop si ti ,revewoH .lamiced ni tuptuo era seulav ciremun ,tluafed yB

eht gnitteS tco eht gnitteS .latco ni deyalpsid eb ot tuptuo sesuac galf xeh esuac galf eb ot tuptuo s

eht tes ,lamiced ot tuptuo nruter oT .lamicedaxeh ni deyalpsid ced .galf

gnitteS esabwohs noisrevnoc eht fi ,elpmaxe roF .nwohs eb ot seulav ciremun fo esab eht sesuac

,tluafed yB .F1x0 sa deyalpsid eb lliw F1 eulav eht ,lamicedaxeh si esab si noitaton cifitneics nehw

eht ,deyalpsid e eht ,deyalpsid si eulav lamicedaxeh a nehw ,oslA .esacrewol ni si x .esacrewol ni si

nehW esacreppu .esacreppu ni deyalpsid era sretcarahc eseht ,tes si

gnitteS sopwohs deyalpsid eb ot ngis sulp gnidael a sesuac .seulav evitisop erofeb

gnitteS tniopwohs gnitaolf lla rof deyalpsid eb ot sorez gniliart dna tniop lamiced a sesuac - tniop

tuptuo — .ton ro dedeen rehtehw

eht gnittes yB cifitneics gnitaolf ,galf - .noitaton cifitneics gnisu deyalpsid era seulav ciremun tniop

nehW dexif gnitaolf ,tes si - si galf rehtien nehW .noitaton lamron gnisu deyalpsid era seulav tniop

.dohtem etairporppa na sesoohc relipmoc eht ,tes

nehW fubtinu .noitarepo noitresni hcae retfa dehsulf si reffub eht ,tes si

nehW ahplaloob snaelooB ,tes si sdrowyek eht gnisu tuptuo ro tupni eb nac eurt dna eslaf .

eht ot refer ot nommoc si ti ecniS tco , ced dna , xeh sa ot derrefer ylevitcelloc eb nac yeht ,sdleif

dleifesab eht ,ylralimiS . tfel , thgir dna , lanretni sa ot derrefer eb nac sdleif dleiftsujda niF . ,ylla

eht cifitneics dna dexif sa decnerefer eb nac sdleif dleiftaolf .

Page 111: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 801

sgalF tamroF eht gnitteS

eht esu ,galf a tes oT )(ftes fo rebmem a si noitcnuf sihT .noitcnuf soi nommoc tsom stI .

:ereh nwohs si mrof

sgalftmf(ftes sgalftmf sgalf ;)

ter noitcnuf sihT yb deificeps sgalf esoht no snrut dna sgalf tamrof eht fo sgnittes suoiverp eht snru

sgalf eht no nrut ot ,elpmaxe roF . sopwohs :tnemetats siht esu nac uoy ,galf

;)sopwohs::soi(ftes.maerts

,ereH maerts fo esu eht ecitoN .tceffa ot hsiw uoy maerts eht si oi ::s yfilauq ot sopwohs .

ecniS sopwohs eht yb denifed tnatsnoc detaremune na si soi yb deifilauq eb tsum ti ,ssalc soi nehw

eht htiw 001 eulav eht syalpsid margorp gniwollof ehT .desu si ti sopwohs dna tniopwohs sgalf

.no denrut

>maertsoi< edulcni#

an gnisu ;dts ecapsem

)(niam tni

{

;)tniopwohs::soi(ftes.tuoc

;)sopwohs::soi(ftes.tuoc

0.001+ syalpsid // ;0.001 << tuoc

;0 nruter

}

taht dnatsrednu ot tnatropmi si tI )(ftes eht fo noitcnuf rebmem a si soi smaerts stceffa dna ssalc

eroferehT .ssalc taht yb detaerc ot llac yna , )(ftes on si erehT .maerts cificeps a ot evitaler enod si

gnillac fo tpecnoc )(ftes .sutats tamrof labolg fo ++C ni tpecnoc on si ereht ,yltnereffid tuP .flesti yb

.yllaudividni noitamrofni sutats tamrof nwo sti sniatniam maerts hcaE

guohtlA tneiciffe erom a si ereht ,margorp gnidecerp eht htiw gnorw yllacinhcet gnihton si ereht h

ot sllac elpitlum gnikam fo daetsnI .ti etirw ot yaw )(ftes fo seulav eht rehtegot RO ylpmis nac uoy ,

ilpmocca llac elgnis siht ,elpmaxe roF .tes tnaw uoy sgalf eht :gniht emas eht sehs

,sgalf erom ro owt rehtegot RO nac uoY //

;)sopwohs::soi | tniopwohs::soi(ftes.tuoc

Page 112: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 901

eht nihtiw denifed era sgalf tamrof eht esuaceB soi gnisu yb seulav rieht ssecca tsum uoy ,ssalc soi

,elpmaxe roF .rotarepo noituloser epocs eht dna hs esabwo uoY .dezingocer eb ton lliw flesti yb

yficeps tsum .esabwohs::soi

sgalF tamroF gniraelC

fo tnemelpmoc ehT )(ftes si )(ftesnu fo noitcnuf rebmem sihT . soi erom ro eno raelc ot desu si

sgalftmf(ftesnu diov si mrof lareneg stI .sgalf tamrof sgalf ;)

hT yb deificeps sgalf e sgalf sgnittes galf suoiverp ehT ).detceffanu era sgalf rehto llA( .deraelc era

.denruter era

setartsulli margorp gniwollof ehT )(ftesnu eht htob stes tsrif tI . esacreppu dna cifitneics tI .sgalf

aton cifitneics ni 21.001 stuptuo neht ni si noitaton cifitneics eht ni desu "E" eht ,esac siht nI .noit

eht sraelc ti ,txeN .esacreppu esacreppu a gnisu ,noitaton cifitneics ni 21.001 stuptuo niaga dna galf

".e" esacrewol

>maertsoi< edulcni#

;dts ecapseman gnisu

)(niam tni

{

ppu::soi(ftes.tuoc ;)cifitneics::soi | esacre

20+E2100.1 syalpsid // ;21.001 << tuoc

esacreppu raelc // ;)esacreppu::soi(ftesnu.tuoc

" << tuoc \ 20+e2100.1 syalpsid // ;21.001 << "n

;0 nruter

}

) (ftes fo mroF dedaolrevO nA

fo mrof dedaolrevo na si erehT )(ftes iht sekat taht :mrof lareneg s

sgalftmf(ftes sgalftmf 1sgalf sgalftmf , 2sgalf ;)

yb deificeps sgalf eht ylno ,noisrev siht nI 2sgalf tes neht dna deraelc tsrif era yehT .detceffa era

yb deificeps sgalf eht ot gnidrocca 1sgalf fi neve taht etoN . 1sgalf sgalf rehto sniatnoc esoht ylno ,

yb deificeps 2sgalf ,elpmaxe roF .denruter si gnittes sgalf suoiverp ehT .detceffa eb lliw

>maertsoi< edulcni#

;dts ecapseman gnisu

) (niam tni

Page 113: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 011

{

;)tniopwohs::soi ,sopwohs::soi | tniopwohs::soi(ftes.tuoc

+ ton ,0.001 syalpsid // ;0.001 << tuoc 0.001

;0 nruter

}

,ereH tniopwohs ton tub ,tes si sopwohs .retemarap dnoces eht ni deificeps ton si ti ecnis ,

owt eht fo esu nommoc tsom eht spahreP - fo mrof retemarap )(ftes ,esab rebmun eht gnittes nehw si

er ,denialpxe sA .sgalf tamrof dna ,noitacifitsuj eht ot secneref tco , ced dna , xeh nac sdleif

sa ot derrefer eb ylevitcelloc dleifesab eht ,ylralimiS . tfel , thgir dna , lanretni derrefer eb nac sdleif

sa ot dleiftsujda eht ,yllaniF . cifitneics dna dexif sa decnerefer eb nac sdleif dleiftaolf eht ecniS .

lf nehw galf eno ffo nrut ot deen yam uoy ,evisulcxe yllautum era sgnipuorg eseht esirpmoc taht sga

ni tuptuo oT .lamicedaxeh ot tuptuo stes margorp gniwollof eht ,elpmaxe roF .rehtona gnittes

ab rebmun rehto eht taht eriuqer snoitatnemelpmi emos ,lamicedaxeh ni ffo denrut eb sgalf es

eht no gninrut ot noitidda xeh owt eht gnisu dehsilpmocca ylisae tsom si sihT .galf - mrof retemarap

fo )(ftes .

>maertsoi< edulcni#

;dts ecapseman gnisu

)(niam tni

{

;)dleifesab::soi ,xeh::soi(ftes.tuoc

yalpsid siht // ;001 << tuoc 46 s

;0 nruter

}

eht ,ereH dleifesab ,.e,.i( sgalf ced , tco dna , xeh eht neht dna deraelc tsrif era ) xeh .tes si galf

ni deificeps sgalf eht ylno ,rebmemeR 2sgalf yb deificeps sgalf yb detceffa eb nac 1sgalf roF .

tpmetta tsrif eht ,margorp siht ni ,elpmaxe eht tes ot sopwohs .sliaf galf

.krow ton lliw margorp sihT //

>maertsoi< edulcni#

;dts ecapseman gnisu

)(niam tni

{

Page 114: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 111

tes ton sopwohs ,rorre // ;)xeh::soi ,sopwohs::soi(ftes.tuoc

' << 001 << tuoc \ 001+ ton ,001 syalpsid // ;'n

s::soi ,sopwohs::soi(ftes.tuoc tcerroc si siht // ;)sopwoh

001+ syalpsid won // ;001 << tuoc

;0 nruter

}

esu ot tnaw lliw uoy emit eht fo tsom taht dnim ni peeK )(ftesnu elgnis eht dna sgalf raelc ot

fo noisrev retemarap )(ftes ehT .sgalf tes ot )reilrae debircsed( sgalftmf(ftes , alftmf )sg fo noisrev

)(ftes doog rehtonA .esab rebmun eht gnittes sa hcus ,snoitautis dezilaiceps ni desu netfo tsom si

lla fo etats eht seificeps taht etalpmet galf a gnisu era uoy hcihw ni noitautis a evlovni yam esu

ro eno ylno retla ot hsiw tub sgalf tamrof ni etalpmet eht yficeps dluoc uoy ,esac siht nI .owt 1sgalf

esu dna 2sgalf .detceffa eb lliw sgalf esoht fo hcihw yficeps ot

sgalF gnittamroF eht gninimaxE

oT .yna retla ton tub sgnittes tamrof tnerruc eht wonk ot tnaw ylno uoy nehw semit eb lliw erehT

a ,laog siht hsilpmocc soi noitcnuf rebmem eht sedulcni )(sgalf tnerruc eht snruter ylpmis hcihw ,

:ereh nwohs si epytotorp stI .galf tamrof hcae fo gnittes

;) (sgalf sgalftmf

sesu margorp gniwollof ehT )(sgalf aler sgalf tamrof eht fo gnittes eht yalpsid ot ot evit tuoc yaP .

eht ot noitnetta laiceps )(sgalfwohs .etirw uoy smargorp ni lufesu ti dnif thgim uoY .noitcnuf

>maertsoi< edulcni#

;dts ecapseman gnisu

; )(sgalfwohs diov

)(niam tni

{

sgalf tamrof fo noitidnoc tluafed wohs //

;)(sgalfwohs

::soi(ftes.tuoc ;)dexif::soi | tniopwohs::soi | thgir

;)(sgalfwohs

;0 nruter

Page 115: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 211

}

.sgalf tamrof eht fo sutats eht syalpsid noitcnuf sihT //

)(sgalfwohs diov

{

;f sgalftmf::soi

;i gnol

sgnittes galf teg // ;)(sgalf.tuoc )gnol( = f

galf hcae kcehc //

>> i = i ;i ;0004x0=i(rof )1

;" 1" << tuoc )f & i(fi

;" 0" << tuoc esle

" << tuoc \ ;"n

}

:ereh nwohs si margorp eht morf tuptuo ehT

1 0 0 0 0 0 0 0 0 1 0 0 0 0 0

1 0 0 0 1 0 0 1 0 1 0 0 0 1 0

sgalF llA gnitteS

ehT )(sgalf rof lla tes ot uoy swolla taht mrof dnoces a sah noitcnuf a htiw detaicossa sgalf tam

maerts . fo noisrev siht rof epytotorp ehT )(sgalf :ereh nwohs si

sgalftmf(sgalf sgalftmf f ;)

ni dnuof nrettap tib eht ,noisrev siht esu uoy nehW f htiw detaicossa sgalf tamrof eht tes ot desu si

galf tamrof lla ,suhT .maerts eht .sgnittes suoiverp eht snruter noitcnuf ehT .detceffa era s

fo noisrev siht setartsulli margorp txen ehT )(sgalf no snrut taht ksam galf a stcurtsnoc tsrif tI .

sopwohs , esabwohs , tco dna , thgir sesu neht tI .ffo era sgalf rehto llA . )(sgalf rof eht tes ot tam

htiw detaicossa sgalf tuoc noitcnuf ehT .sgnittes eseht ot )(sgalfwohs tes era sgalf eht taht seifirev

).margorp suoiverp eht ni desu noitcnuf emas eht si tI( .detacidni sa

>maertsoi< edulcni#

;dts ecapseman gnisu

Page 116: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 311

;)(sgalfwohs diov

)(niam tni

{

wohs // sgalf tamrof fo noitidnoc tluafed

;)(sgalfwohs

ffo srehto ,no era thgir ,tco ,esabwohs ,sopwohs //

;thgir::soi | tco::soi | esabwohs::soi | sopwohs::soi = f gnol

sgalf lla tes // ;)f(sgalf.tuoc

;)(sgalfwohs

;0 nruter

}

f dna ,) (noisicerp ,) (htdiw gnisU ) (lli

yb denifed snoitcnuf rebmem eerht era ereht ,sgalf gnittamrof eht ot noitidda nI soi eseht tes taht

eseht od taht snoitcnuf ehT .retcarahc llif eht dna ,noisicerp eht ,htdiw dleif eht :sretemarap tamrof

era sgniht )(htdiw , )(noisicerp dna , )(llif .ylevitcepser ,

.nrut ni denimaxe si hcaE

ti sretcarahc fo rebmun eht sa ecaps hcum sa ylno seipucco ti ,tuptuo si eulav a nehw ,tluafed yB

eht gnisu yb htdiw dleif muminim a yficeps nac uoy ,revewoH .ti yalpsid ot sekat )(htdiw .noitcnuf

si epytotorp stI :ereh nwohs

ezismaerts(htdiw ezismaerts w ;)

,ereH w ,snoitatnemelpmi emos nI .denruter si htdiw dleif suoiverp eht dna ,htdiw dleif eht semoceb

ehT .desu si htdiw dleif tluafed eht ,t'nsi ti fI .tuptuo hcae erofeb tes eb tsum htdiw dleif eht

ezismaerts yt .relipmoc eht yb regetni fo mrof emos sa denifed si ep

lliw dleif eht ,htdiw deificeps eht naht ssel sesu eulav a nehw ,htdiw dleif muminim a tes uoy retfA

ezis eht fI .htdiw dleif eht hcaer ot )tluafed yb ,ecaps( retcarahc llif tnerruc eht htiw deddap eb eht fo

.detacnurt era seulav oN .nurrevo eb lliw dleif eht ,htdiw dleif muminim eht sdeecxe eulav

gnitaolf gnittuptuo nehW - retfa deyalpsid eb ot stigid fo rebmun eht enimreted nac uoy ,seulav tniop

eht gnisu yb tniop lamiced eht )(noisicerp p stI .noitcnuf :ereh nwohs si epytotor

ezismaerts(noisicerp ezismaerts p ;)

Page 117: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 411

ot tes si noisicerp eht ,ereH p emos nI .6 si noisicerp tluafed ehT .denruter si eulav dlo eht dna ,

gnitaolf hcae erofeb tes eb tsum noisicerp eht ,snoitatnemelpmi - neht ,ton si ti fI .tuptuo tniop eht

.secaps htiw dellif si ti ,dellif eb ot sdeen dleif a nehw ,tluafed yB .desu eb lliw noisicerp tluafed

eht gnisu yb retcarahc llif eht yficeps nac uoY )(llif rahc(llif rahc si epytotorp stI .noitcnuf hc ;)

ot llac a retfA )(llif , hc if wen eht semoceb a si ereH .denruter si eno dlo eht dna ,retcarahc ll

:snoitcnuf eseht setartsulli taht margorp

>maertsoi< edulcni#

;dts ecapseman gnisu

)(niam tni

{

; )4(noisicerp.tuoc

;)01(htdiw.tuoc

" << 54321.01 << tuoc \ 21.01 syalpsid // ;"n

;)'*'(llif.tuoc

(htdiw.tuoc ;)01

" << 54321.01 << tuoc \ 21.01***** syalpsid // ;"n

oot ,sgnirts ot seilppa htdiw dleif //

;)01(htdiw.tuoc

" << "!iH" << tuoc \ !iH******* syalpsid // ;"n

;)01(htdiw.tuoc

yfitsuj tfel // ;)tfel::soi(ftes.tuoc

*****21.01 syalpsid // ;54321.01 << tuoc

nruter ;0

}

:ereh nwohs si tuptuo s'margorp sihT

21.01

21.01*****

!iH*******

*****21.01

fo smrof dedaolrevo era erehT )(htdiw , )(noisicerp dna , )(llif eht egnahc ton od tub niatbo taht

:ereh nwohs era smrof esehT .gnittes tnerruc

Page 118: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 511

;) (llif rahc

htdiw ezismaerts ;) (

;) (noisicerp ezismaerts

O/I tamroF ot srotalupinaM gnisU

laiceps fo esu eht hguorht si maerts a fo sretemarap tamrof eht retla nac uoy yaw dnoces ehT

dellac snoitcnuf srotalupinam srotalupinam dradnats ehT .noisserpxe O/I na ni dedulcni eb nac taht

02 elbaT ni nwohs era - srotalupinam O/I eht fo ynam ,elbat eht gninimaxe yb ees nac uoy sA .1

eht fo snoitcnuf rebmem lellarap soi ++C ot yltnecer dedda erew srotalupinam eht fo ynaM .ssalc

redlo yb detroppus eb ton lliw dna .srelipmoc

esopruP rotalupinaM tuptuO/tupnI

no snruT ahplaloob ahpaloob .galf

no snruT ced tuptuO/tupnI ced .galf

.maerts eht hsulf dna retcarahc enilwen a tuptuO ldne tuptuO/tupnI

.llun a tuptuO sdne tuptuO

no snruT dexif tuptuO dexif .galf

.maerts a hsulF hsulf tuptuO

xeh tuptuO no snruT xeh .galf

no snruT lanretni tuptuO/tupnI lanretni .galf

no snruT tfel tuptuO tfel .galf

ffo snruT ahplaoobon tuptuO ahplaloob .galf

ffo snruT esabwohson tuptuO/tupnI esabwohs .galf

ffo snruT tniopwohson tuptuO tniopwohs .galf

opwohsont uptuO ffo snruT s sopwohs .galf

02 elbaT - srotalupinaM ++C ehT .1

sa hcus( sretemarap ekat taht srotalupinam ssecca oT )(wtes edulcni tsum uoy ,)

>pinamoi< .margorp ruoy ni

tuptuO/tupnI esopruP rotalupinaM

ffo snruT swpikson swpiks tupnI .galf

Page 119: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 611

o snruT fubtinuon ff fubtinu tuptuO .galf

ffo snruT esacreppuon esacreppu tuptuO .galf

no snruT tco tco tuptuO/tupnI .galf

sgalftmf( sgalfsoiteser f sgalf eht ffo nruT )

ni deificeps .f

tuptuO/tupnI

no snruT thgir thgir tuptuO .galf

no snruT cifitneics cifitneics ptuO .galf tu

tni(esabtes esab esab rebmun eht teS )

ot .esab

tuptuO/tupnI

tni(lliftes hc ot retcarahc llif eht teS ) .hc tuptuO

sgalftmf(sgalfsoites f sgalf eht no nruT )

ni deificeps .f

tuptuo/tupnI

tni( noisicerptes p fo stigid fo rebmun eht teS )

.noisicerp

tuptuO

s tni(wte w ot htdiw dleif eht teS ) .w tuptuO

no snruT esabwohs esabwohs tuptuO .galf

no snruT tniopwohs tniopwohs tuptuO .galf

no snruT sopwohs sopwohs tuptuO .galf

no snruT swpiks swpiks tupnI .galf

no snruT fubtinu fubtinu tuptuO .galf

no snruT esacreppu esacreppu tuptuO .galf

tupnI .ecaps etihw gnidael pikS sw

02 elbaT - )deunitnoc( srotalupinaM ++C ehT .1

:srotalupinam emos sesu taht elpmaxe na si ereH

>maertsoi< edulcni#

>pinamoi< edulcni#

;dts ecapseman gnisu

Page 120: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 711

)(niam tni

{

;ldne << 001 << xeh << tuoc

tuoc ;0.3432 << )01(wtes << )'?'(lliftes <<

;0 nruter

}

syalpsid sihT

46

3432??????

a nehw taht eciton oslA .noisserpxe O/I regral a nihtiw rucco srotalupinam eht woh ecitoN

sa hcus ,tnemugra na ekat ton seod rotalupinam )(ldne wollof ton si ti ,elpmaxe eht ni yb de

dedaolrevo eht ot dessap si taht noitcnuf eht fo sserdda eht si ti esuaceb si sihT .sesehtnerap <<

.rotarepo

sesu taht margorp gnidecerp eht fo noisrev tnelaviuqe yllanoitcnuf a si ereh ,nosirapmoc a sA soi

tluser emas eht eveihca ot snoitcnuf rebmem :s

>maertsoi< edulcni#

>pinamoi< edulcni#

;dts ecapseman gnisu

)(niam tni

{

;)dleifesab::soi ,xeh::soi(ftes.tuoc

" << 001 << tuoc \ xeh ni 001 // ;"n

;)'?'(llif.tuoc

;)01(htdiw.tuoc

;0.3432 << tuoc

;0 nruter

}

fo egatnavda niam eht ,tseggus selpmaxe eht sA eht fo daetsni srotalupinam gnisu soi rebmem

eht esu nac uoY .nettirw eb ot edoc tcapmoc erom wolla ylnommoc yeht taht si snoitcnuf

Page 121: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 811

)(sgalfsoites ,elpmaxe roF .maerts a ot detaler sgalf tamrof suoirav eht tes yltcerid ot rotalupinam

sesu margorp siht oites )(sgalfs eht tes ot esabwohs dna sopwohs :sgalf

>maertsoi< edulcni#

>pinamoi< edulcni#

;dts ecapseman gnisu

)(niam tni

{

;)sopwohs::soi(sgalfsoites << tuoc

;)esabwohs::soi(sgalfsoites << tuoc

;321 << xeh << " " << 321 << tuoc

;0 nruter

}

rotalupinam ehT es )(sgalfsoit noitcnuf rebmem eht sa noitcnuf emas eht smrofrep )(ftes .

si srotalupinam gnitseretni erom eht fo enO ahpaloob tupni eb ot seulav eslaf dna eurt swolla tI .

.srebmun naht rehtar "eslaf" dna "eurt" sdrow eht gnisu tuptuo dna

,elpmaxe roF

dulcni# >maertsoi< e

;dts ecapseman gnisu

)(niam tni

{

;b loob

;eurt = b

;ldne << b << ahplaloob << " " << b << tuoc

;" :eulav naelooB a retnE" << tuoc

;b >> ahplaloob >> nic

;b << " :deretne uoy tahw si ereH" << tuoc

;0 nruter

}

.nur elpmas a si ereH

eurt 1

retnE eslaf :eulav naelooB a

Page 122: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 911

eslaf :deretne uoy tahw si ereH

sessalC eliF eht dna >maertsf<

redaeh eht edulcni tsum uoy ,O/I elif mrofrep oT >maertsf< lareves senifed tI .margorp ruoy ni

gnidulcni ,sessalc maertsfi , maertsfo dna , maertsf ed era sessalc esehT . morf devir maertsi ,

maertso dna , maertsoi ,rebmemeR .ylevitcepser , maertsi , maertso dna , maertsoi morf devired era

soi os , maertsfi , maertsfo dna , maertsf yb denifed snoitarepo lla ot ssecca evah osla soi dessucsid(

.)retpahc gnidecerp eht ni

ssalc rehtonA si metsys elif eht yb desu fubelif wol sedivorp hcihw , - elif a eganam ot seitilicaf level

esu t'nod uoy ,yllausU .maerts fubelif .sessalc elif rehto eht fo trap si ti tub ,yltcerid

eliF a gnisolC dna gninepO

s a ot ti gniknil yb elif a nepo uoy ,++C nI a niatbo tsrif tsum uoy ,elif a nepo nac uoy erofeB .maert

,maerts tupni na etaerc oT .tuptuo/tupni dna ,tuptuo ,tupni :smaerts fo sepyt eerht era erehT .maerts

ssalc fo eb ot maerts eht eralced tsum uoy maertsfi alced tsum uoy ,maerts tuptuo na etaerc oT . ti er

ssalc sa maertsfo eb tsum snoitarepo tuptuo dna tupni htob gnimrofrep eb lliw taht smaertS .

ssalc sa deralced maertsf ,maerts tuptuo eno ,maerts tupni eno setaerc tnemgarf siht ,elpmaxe roF .

:tuptuo dna tupni htob fo elbapac maerts eno dna

i maertsfi tupni // ;n

tuptuo // ;tuo maertsfo

tuptuo dna tupni // ;oi maertsf

gnisu yb si elif a htiw ti etaicossa ot yaw eno ,maerts a detaerc evah uoy ecnO )(nepo sihT .

ereh nwohs si hcae rof epytotorp ehT .sessalc maerts eerht eht fo hcae fo rebmem a si noitcnuf :

* rahc tsnoc(nepo::maertsfi diov emanelif edomnepo::soi , edom ;)ni::soi =

* rahc tsnoc(nepo::maertsfo diov emanelif edomnepo::soi , edom ;)cnurt::soi | tuo::soi =

* rahc tsnoc(nepo::maertsf diov emanelif edomnepo::soi , = edom ni::soi | ;)tuo::soi

Page 123: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 021

,ereH nelif ema fo eulav ehT .reificeps htap a edulcni nac ti ;elif eht fo eman eht si edom senimreted

yb denifed seulav gniwollof eht fo erom ro eno eb tsum tI .denepo si elif eht woh edomnepo hcihw ,

yb denifed noitaremune na si soi ssalc esab sti hguorht( esab_soi .) ppa::soi

eta::soi

yranib::soi

ni::soi

tuo::soi

cnurt::soi

.rehtegot meht gniRO yb seulav eseht fo erom ro owt enibmoc nac uoY

gnidulcnI ppa::soi desu eb nac eulav sihT .dne eht ot dedneppa eb ot elif taht ot tuptuo lla sesuac

uo fo elbapac selif htiw ylno gnidulcnI .tupt eta::soi rucco ot elif eht fo dne eht ot kees a sesuac

hguohtlA .denepo si elif eht nehw eta::soi dne ot kees laitini na sesuac - fo - nac snoitarepo O/I ,elif

.elif eht nihtiw erehwyna rucco llits

ehT ni::soi c si elif eht taht seificeps eulav ehT .tupni fo elbapa tuo::soi elif eht taht seificeps eulav

.tuptuo fo elbapac si

ehT yranib::soi ni denepo era selif lla ,tluafed yB .edom yranib ni denepo eb ot elif a sesuac eulav

s ,ecalp ekat yam snoitalsnart retcarahc suoirav ,edom txet nI .edom txet egairrac sa hcu

yranib ni denepo si elif a nehw ,revewoH .senilwen otni detrevnoc gnieb secneuqes deefenil/nruter

.rucco lliw snoitalsnart retcarahc hcus on ,edom

ie ni denepo eb nac ,atad war ro txet dettamrof sniatnoc ti rehtehw ,elif yna taht dnatsrednU reht

.ecalp ekat snoitalsnart retcarahc rehtehw si ecnereffid ylno ehT .edom txet ro yranib

ehT cnurt::soi dna ,deyortsed eb ot eman emas eht yb elif gnitsixeerp a fo stnetnoc eht sesuac eulav

s tuptuo na gnitaerc nehW .htgnel orez ot detacnurt si elif eht gnisu maert maertsfo gnitsixeerp yna ,

.detacnurt yllacitamotua si eman taht yb elif

.elif tuptuo lamron a snepo tnemgarf gniwollof ehT

;tuo maertsfo

;)tuo::soi ,"tset"(nepo.tuo

ees modles lliw uoy ,revewoH )(nepo eht esuaceb ,nwohs sa dellac edom retemarap sedivorp

rof ,wohs sepytotorp rieht sA .maerts fo epyt hcae rof seulav tluafed maertsfi , edom ot stluafed

ni::soi rof ; maertsfo si ti , cnurt::soi | tuo::soi rof dna ; maertsf si ti , tuo::soi | ni::soi ,eroferehT .

Page 124: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 121

l kool yllausu lliw tnemetats gnidecerp eht lamron dna tuptuo ot stluafed // ;)"tset"(nepo.tuo :siht eki

elif

rof retemarap edom eht ,relipmoc ruoy no gnidnepeD ) (nepo::maertsf ot tluafed ton yam tuo | ni .

.ylticilpxe siht yficeps ot deen thgim uoy ,eroferehT

etoN

fI )(nepo e lliw maerts eht ,sliaf ,eroferehT .noisserpxe naelooB a ni desu nehw eslaf ot etaulav

os od nac uoY .dedeeccus noitarepo nepo eht taht erus ekam ot tset dluohs uoy ,elif a gnisu erofeb

:siht ekil tnemetats a gnisu yb

{ )maertsym!(fi

.elif nepo tonnaC" << tuoc \ ;"n

rorre eldnah //

}

eht gnisu yb elif a nepo ot reporp yleritne si ti hguohtlA )(nepo lliw uoy emit eht fo tsom ,noitcnuf

eht esuaceb os od ton maertsfi , maertsfo dna , maertsf taht snoitcnuf rotcurtsnoc evah sessalc

ah snoitcnuf rotcurtsnoc ehT .elif eht nepo yllacitamotua eht sa stluafed dna sretemarap emas eht ev

)(nepo :ereh nwohs sa denepo elif a ees ylnommoc tsom lliw uoy ,eroferehT .noitcnuf

tupni rof elif nepo // ;)"elifym"(maertsym maertsfi

ssa eht fo eulav eht ,denepo eb tonnac elif eht nosaer emos rof fi ,detats sA elbairav maerts detaico

na ro elif eht nepo ot noitcnuf rotcurtsnoc a esu uoy rehtehw ,eroferehT .eslaf ot etaulave lliw

ot llac ticilpxe )(nepo eht gnitset yb denepo neeb yllautca sah elif eht taht mrifnoc ot tnaw lliw uoy ,

.maerts eht fo eulav

a nac uoY eht gnisu yb elif a denepo yllufsseccus evah uoy fi ees ot kcehc osl )(nepo_si ,noitcnuf

fo rebmem a si hcihw maertsf , maertsfi dna , maertsfo :epytotorp siht sah tI .

;) (nepo_si loob

iwrehto eslaf dna elif nepo na ot deknil si maerts eht fi eurt snruter tI gniwollof eht ,elpmaxe roF .es

fi skcehc maertsym :nepo yltnerruc si

{ ))(nepo_si.maertsym!(fi

.nepo ton si eliF" << tuoc \ ;"n

... //

noitcnuf rebmem eht esu ,elif a esolc oT )(esolc maerts a ot deknil elif eht esolc ot ,elpmaxe roF .

dellac maertsym t esu , :tnemetats sih

Page 125: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 221

;)(esolc.maertsym

ehT )(esolc .eulav on snruter dna sretemarap on sekat noitcnuf

seliF txeT gnitirW dna gnidaeR

eht esu ylpmiS .elif txet a ot etirw ro morf daer ot ysae yrev si tI << dna >> yaw emas eht srotarepo

oc gnimrofrep nehw od uoy gnisu fo daetsni taht tpecxe ,O/I elosn nic dna tuoc maerts a etutitsbus ,

hcae sniatnoc taht elif yrotnevni trohs a setaerc margorp siht ,elpmaxe roF .elif a ot deknil si taht

:tsoc sti dna eman s'meti

>maertsoi< edulcni#

>maertsf< edulcni#

ecapseman gnisu ;dts

)(niam tni

{

elif lamron ,tuptuo // ;)"YRTNVNI"(tuo maertsfo

{ )tuo!(fi

.elif YROTNEVNI nepo tonnaC" << tuoc \ ;"n

;1 nruter

}

;ldne << 59.93 << " soidaR" << tuo

;ldne << 59.91 << " sretsaoT" << tuo

;ldne << 08.42 << " srexiM" << tuo

;)(esolc.tuo

ruter ;0 n

}

sti syalpsid dna margorp suoiverp eht yb detaerc elif yrotnevni eht sdaer margorp gniwollof ehT

:neercs eht no stnetnoc

>maertsoi< edulcni#

>maertsf< edulcni#

;dts ecapseman gnisu

)(niam tni

Page 126: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 321

{

tupni // ;)"YRTNVNI"(ni maertsfi

{ )ni!(fi

nnaC" << tuoc .elif YROTNEVNI nepo to \ ;"n

;1 nruter

}

;]02[meti rahc

;tsoc taolf

;tsoc >> meti >> ni

" << tsoc << " " << meti << tuoc \ ;"n

;tsoc >> meti >> ni

" << tsoc << " " << meti << tuoc \ ;"n

;tsoc >> meti >> ni

" << tsoc << " " << meti << tuoc \ ;"n

;)(esolc.ni

nruter ;0

}

gnisu yb selif gnitirw dna gnidaer ,yaw a nI >> dna << C eht gnisu ekil si - snoitcnuf desab )(ftnirpf

dna )(fnacsf eb dluow ti sa tamrof emas eht ni elif eht ni derots si noitamrofni llA .snoitcnuf

.neercs eht no deyalpsid

elpmaxe rehtona si gniwolloF dna draobyek eht ta deretne sgnirts sdaer margorp sihT .O/I ksid fo

eht esu oT .tniop noitamalcxe na sretne resu eht nehw spots margorp ehT .ksid ot meht setirw

.enil dnammoc eht no elif tuptuo eht fo eman eht yficeps ,margorp

>maertsoi< edulcni#

edulcni# >maertsf<

;dts ecapseman gnisu

)][vgra* rahc ,cgra tni(niam tni

{

{ )2=!cgra(fi

>emanelif< tuptuo :egasU" << tuoc \ ;"n

;1 nruter

Page 127: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 421

}

elif lamron ,tuptuo // ;)]1[vgra(tuo maertsfo

{ )tuo!(fi

.elif tuptuo nepo tonnaC" << tuoc \ ;"n

;1 nruter

}

;]08[rts rahc

tuoc .pots ot ! retnE .ksid ot sgnirts etirW" << \ ;"n

{ od

;" :" << tuoc

;rts >> nic

;ldne << rts << tuo

;)'!' =! rts*( elihw }

;)(esolc.tuo

;0 nruter

}

eht gnisu selif txet gnidaer nehW >> lliw snoitalsnart retcarahc niatrec taht dnim ni peek ,rotarepo

.rucco etihw ,elpmaxe roF - retcarahc yna tneverp ot tnaw uoy fI .dettimo era sretcarahc ecaps

txen eht ni dessucsid snoitcnuf eht esu dna ssecca yranib rof elif a nepo tsum uoy ,snoitalsnart

.noitces

dne fi ,gnittupni nehW - fo - deknil maerts eht ,deretnuocne si elif .eslaf sa etaulave lliw elif taht ot

).tcaf siht setartsulli noitces txen ehT(

O/I yraniB dna dettamrofnU

ot yaw tneiciffe tsom eht syawla ton si ti ,ysae yrev si selif txet dettamrof gnitirw dna gnidaer elihW

nehw semit eb lliw ereht ,oslA .selif eldnah ton ,atad yranib )war( dettamrofnu erots ot deen uoy

.ereh debircsed era siht od ot uoy wolla taht snoitcnuf ehT .txet

eht gnisu ti nepo ot erus eb ,elif a no snoitarepo yranib gnimrofrep nehW yranib::soi edom

cnuf elif dettamrofnu eht hguohtlA .reificeps emos ,edom txet rof denepo selif no krow lliw snoit

.snoitarepo elif yranib fo esoprup eht etagen snoitalsnart retcarahC .rucco yam snoitalsnart retcarahc

Page 128: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 521

setyB .sv sretcarahC

yfiralc ot tnatropmi si ti ,O/I dettamrofnu fo noitanimaxe ruo gninnigeb erofeB tnatropmi na

sa fo thguoht saw ++C dna C ni O/I ,sraey ynam roF .tpecnoc detneiro etyb a esuaceb si sihT . rahc

erew elbaliava smaerts fo sepyt ylno eht dna etyb a ot tnelaviuqe si rahc eht htiw ,revewoH .smaerts

epyt fo( sretcarahc ediw fo tnevda t_rahcw ) taht yas regnol on nac ew ,smaerts tnadnetta rieht dna

si ti taht yas tsum ew ,daetsnI .detneiro etyb si O/I ++C detneiro retcarahc ,esruoc fO . rahc smaerts

gnitarepo nehw yllaicepse ,setyb fo smret ni kniht ot eunitnoc nac ew dna detneiro etyb llits era no

rof nekat eb regnol on nac retcarahc a dna etyb a neewteb ycnelaviuqe eht tuB .atad lautxetnon

.detnarg

era koob siht ni desu smaerts eht fo lla ,02 retpahC ni denialpxe sA rahc yb era yeht ecnis smaerts

f dettamrofnu ekam osla yehT .nommoc tsom eht raf a esuaceb reisae gnildnah eli rahc maerts

eno a sehsilbatse - ot - nehw tifeneb a si hcihw ,sretcarahc dna setyb neewteb ecnednopserroc eno

.atad yranib fo skcolb gnitirw ro gnidaer

) (teg dna ) (tup

yb si atad dettamrofnu etirw dna daer yam uoy taht yaw enO snoitcnuf rebmem eht gnisu )(teg dna

)(tup ,si tahT .sretcarahc no etarepo snoitcnuf esehT . )(teg dna retcarahc a daer lliw )(tup lliw

a no gnitarepo era dna snoitarepo yranib rof elif eht denepo evah uoy fi ,esruoc fO .retcarahc a etirw

rahc naht rehtar( a t_rahcw .atad fo setyb etirw dna daer snoitcnuf eseht neht ,)maerts

ehT )(teg htiw gnola ereh nwohs si noisrev desu ylnommoc tsom eht tub ,smrof ynam sah noitcnuf

)(tup :

& rahc(teg& maertsi hc ;)

rahc(tup& maertso hc ;)

ehT )(teg c elgnis a sdaer noitcnuf ni eulav taht stup dna maerts gnikovni eht morf retcarah hc tI .

ehT .maerts eht ot ecnerefer a snruter )(tup setirw noitcnuf hc ecnerefer a snruter dna maerts eht ot

.maerts eht ot

niatnoc ti rehtehw ,elif yna fo stnetnoc eht syalpsid margorp gniwollof ehT no ,atad yranib ro txet s

eht sesu tI .neercs eht )(teg .noitcnuf

>maertsoi< edulcni#

>maertsf< edulcni#

;dts ecapseman gnisu

Page 129: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 621

)][vgra* rahc ,cgra tni(niam tni

{

;hc rahc

{ )2=!cgra(fi

>emanelif< RP :egasU" << tuoc \ ;"n

;1 nruter

}

::soi ,]1[vgra(ni maertsfi ;)yranib::soi | ni

{ )ni!(fi

;".elif nepo tonnaC" << tuoc

e c n e r e f e R e t e l p m o C e h T : + + C 845

;1 nruter

}

dehcaer si foe nehw eslaf eb lliw ni // { )ni(elihw

;)hc(teg.ni

;hc << tuoc )ni(fi

}

;0 nruter

}

w ,noitces gnidecerp eht ni detats sA dne eht neh - fo - eht htiw detaicossa maerts eht ,dehcaer si elif

nehw ,eroferehT .eslaf semoceb elif ni eht gnisuac ,eslaf eb lliw ti ,elif eht fo dne eht sehcaer elihw

.pots ot pool

alpsid dna sdaer taht pool eht edoc ot yaw tcapmoc erom a yllautca si erehT :ereh nwohs sa ,elif a sy

))hc(teg.ni(elihw

;hc << tuoc

esuaceb skrow sihT )(teg maerts eht ot ecnerefer a snruter ni dna , ni fo dne eht nehw eslaf eb lliw

sesu margorp txen ehT .deretnuocne si elif eht )(tup f a ot 552 ot orez morf sretcarahc lla etirw ot eli

elbaliava eht flah tuoba ylno ypucco sretcarahc IICSA eht ,wonk ylbaborp uoy sA .SRAHC dellac

a yb dleh eb nac taht seulav rahc eht dellac yllareneg era seulav rehto ehT . tes retcarahc dednetxe

citamehtam dna egaugnal ngierof sa sgniht hcus edulcni dna eht troppus smetsys lla toN( .slobmys la

).od tsom tub ,tes retcarahc dednetxe

Page 130: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 721

>maertsoi< edulcni#

>maertsf< edulcni#

;dts ecapseman gnisu

)(niam tni

{

;i tni

;)yranib::soi | tuo::soi ,"SRAHC"(tuo maertsfo

{ )tuo!(fi

.elif tuptuo nepo tonnaC" << tuoc \ ;"n

r ;1 nrute

}

ksid ot sretcarahc lla etirw //

;)i )rahc((tup.tuo )++i ;652<i ;0=i(rof

;)(esolc.tuo

;0 nruter

}

dednetxe tahw ees ot elif SRAHC eht fo stnetnoc eht enimaxe ot gnitseretni ti dnif thgim uoY

.elbaliava sah retupmoc ruoy sretcarahc

irw dna ) (daer ) (et

s'++C esu ot si atad yranib fo skcolb etirw dna daer ot yaw rehtonA )(daer dna )(etirw .snoitcnuf

era sepytotorp riehT

rahc(daer& maertsi fub* ezismaerts , mun ;)

rahc tsnoc(etirw& maertso fub* ezismaerts , mun ;)

ehT )(daer sdaer noitcnuf mun sretcarahc reffub eht ni meht stup dna maerts gnikovni eht morf

yb ot detniop fub ehT . )(etirw setirw noitcnuf mun reffub eht morf maerts gnikovni eht ot sretcarahc

yb ot detniop fub ,retpahc gnidecerp eht ni denoitnem sA . ezismaerts ++C eht yb denifed epyt a si

bil eb nac taht sretcarahc fo rebmun tsegral eht gnidloh fo elbapac si tI .regetni fo mrof emos sa yrar

.noitarepo O/I eno yna ni derrefsnart

:ni kcab ti sdaer neht dna ksid ot erutcurts a setirw margorp txen ehT

>maertsoi< edulcni#

>maertsf< edulcni#

Page 131: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 821

edulcni# >gnirtsc<

;dts ecapseman gnisu

{ sutats tcurts

;]08[eman rahc

;ecnalab elbuod

;mun_tnuocca gnol dengisnu

;}

)(niam tni

{

;cca sutats tcurts

;)"rotnarT hplaR" ,eman.cca(ypcrts

;32.3211 = ecnalab.cca

;87653243 = mun_tnuocca.cca

atad etirw //

labtuo maertsfo ;)yranib::soi | tuo::soi ,"ecnalab"(

{ )labtuo!(fi

.elif nepo tonnaC" << tuoc \ ;"n

;1 nruter

}

;))sutats tcurts(foezis ,cca& )* rahc((etirw.labtuo

;)(esolc.labtuo

;kcab daer ,won //

;)yranib::soi | ni::soi ,"ecnalab"(labni maertsfi

{ )labni!(fi

naC" << tuoc .elif nepo ton \ ;"n

;1 nruter

}

;))sutats tcurts(foezis ,cca& )* rahc((daer.labni

;ldne << eman.cca << tuoc

;mun_tnuocca.cca << " # tnuoccA" << tuoc

;)2(noisicerp.tuoc

Page 132: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 921

;)dexif::soi(ftes.tuoc

;ecnalab.cca << "$ :ecnalaB" << ldne << tuoc

;)(esolc.labni

nruter ;0

}

ot llac elgnis a ylno ,ees nac uoy sA )(daer ro )(etirw eritne eht etirw ro daer ot yrassecen si

,setartsulli elpmaxe siht sA .yletarapes nettirw ro daer eb ton deen dleif laudividni hcaE .erutcurts

.tcejbo fo epyt yna eb nac reffub eht

tsac epyt ehT ot sllac eht edisni s ) (daer dna ) (etirw taht reffub a no gnitarepo nehw yrassecen era

epyt eno fo retniop a ,gnikcehc epyt gnorts s'++C fo esuaceB .yarra retcarahc a sa denifed ton si

.epyt rehtona fo retniop a otni detrevnoc eb yllacitamotua ton lliw

N eto

erofeb dehcaer si elif eht fo dne eht fI mun neht ,daer neeb evah sretcarahc )(daer dna ,spots ylpmis

sretcarahc ynam woh tuo dnif nac uoY .elbaliava erew sa sretcarahc ynam sa sniatnoc reffub eht

dellac ,noitcnuf rebmem rehtona gnisu yb daer neeb evah )(tnuocg :epytotorp siht sah hcihw ,

;)(tnuocg ezismaerts

margorp gniwollof ehT .noitarepo tupni yranib tsal eht yb daer sretcarahc fo rebmun eht snruter tI

fo elpmaxe rehtona swohs )(daer dna )(etirw fo esu eht setartsulli dna )(tnuocg :

rtsoi< edulcni# >mae

>maertsf< edulcni#

;dts ecapseman gnisu

)(niam tni

{

,57.99{ = ]4[munf elbuod - ;}1.002 ,0.6771 ,4.43

;i tni

;)yranib::soi | tuo::soi ,"srebmun"(tuo maertsfo

{ )tuo!(fi

;".elif nepo tonnaC" << tuoc

;1 nruter

}

;)munf foezis ,munf& )* rahc((etirw.tuo

Page 133: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 031

uo ;)(esolc.t

yarra raelc // )++i ;4<i ;0=i(rof

;0.0 = ]i[munf

;)yranib::soi | ni::soi ,"srebmun"(ni maertsfi

;)munf foezis ,munf& )* rahc((daer.ni

daer neeb evah setyb ynam woh ees //

daer setyb " << )(tnuocg.ni << tuoc \ ;"n

seulav wohs // )++i ;4<i ;0=i(rof elif morf daer

;" " << ]i[munf << tuoc

;)(esolc.ni

;0 nruter

}

gnitaolf fo yarra na setirw margorp gnidecerp ehT - .kcab meht sdaer neht dna ksid ot seulav tniop

ot llac eht retfA )(daer , )(tnuocg .daer tsuj erew setyb ynam woh enimreted ot desu si

Page 134: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 131

TINU – IIIV

LTS ,GNILDNAH NOITPECXE

.metsysbus gnildnah noitpecxe eht sessucsid retpahc sihT gnildnah noitpecxE eganam ot uoy swolla

nur - yllacitamotua nac margorp ruoy ,gnildnah noitpecxe gnisU .noihsaf ylredro na ni srorre emit

rorre na ekovni - nah noitpecxe fo egatnavda lapicnirp ehT .srucco rorre na nehw enituor gnild

rorre eht fo hcum setamotua ti taht si gnildnah - yb" dedoc eb ot dah ylsuoiverp taht edoc gnildnah

.margorp egral yna ni "dnah

slatnemadnuF gnildnaH noitpecxE

i gnildnah noitpecxe ++C :sdrowyek eerht nopu tliub s yrt , hctac dna , worht lareneg tsom eht nI .

a ni deniatnoc era snoitpecxe rof rotinom ot tnaw uoy taht stnemetats margorp ,smret yrt fI .kcolb

eht nihtiw srucco )rorre na ,.e.i( noitpecxe na yrt gnisu( nworht si ti ,kcolb worht ) si noitpecxe ehT .

gnisu ,thguac hctac lareneg siht nopu setarobale noissucsid gniwollof ehT .dessecorp dna ,

.noitpircsed

a nihtiw morf detucexe neeb evah tsum snoitpecxe rof rotinom ot tnaw uoy taht edoC yrt .kcolb

a nihtiw morf dellac snoitcnuF( yrt olb eb nac taht snoitpecxE ).noitpecxe na worht osla yam kc

a yb thguac era edoc derotinom eht yb nworht hctac eht swollof yletaidemmi hcihw ,tnemetats yrt

fo mrof lareneg ehT .nworht saw noitpecxe eht hcihw ni tnemetats yrt dna hctac .ereh nwohs era

{ yrt

// kcolb yrt

}

( hctac gra 1epyt { )

// kcolb hctac

}

( hctac gra 2epyt { )

// kcolb hctac

}

( hctac gra 3epyt { )

// kcolb hctac

}

Page 135: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 231

..

.

( hctac gra Nepyt { )

// kcolb hctac

}

ehT yrt e sa gnissapmocnella sa ro noitcnuf eno nihtiw stnemetats wef a sa trohs sa eb nac gnisolcn

eht )(niam a nihtiw edoc noitcnuf yrt eb ot margorp eritne eht sesuac ylevitceffe hcihw( kcolb

.)derotinom

gnidnopserroc sti yb thguac si ti ,nworht si noitpecxe na nehW hctac eht sessecorp hcihw ,tnemetats

eno naht erom eb nac erehT .noitpecxe c hcta a htiw detaicossa tnemetats yrt hcihW . hctac

a yb deificeps epyt atad eht fi ,si tahT .noitpecxe eht fo epyt eht yb denimreted si desu si tnemetats

hctac taht neht ,noitpecxe eht fo taht sehctam hctac era srehto lla dna( detucexe si tnemetats

dessapyb ,thguac si noitpecxe na nehW .) gra ,thguac eb yam atad fo epyt ynA .eulav sti eviecer lliw

eht nihtiw srucco rorre on ,si taht( nworht si noitpecxe on fI .etaerc uoy taht sessalc gnidulcni yrt

on neht ,)kcolb hctac .detucexe si tnemetats

mrof lareneg ehT eht fo worht :ereh nwohs si tnemetats

worht noitpecxe ;

worht yb deificeps noitpecxe eht setareneg noitpecxe neht ,thguac eb ot si noitpecxe siht fI . worht

a nihtiw morf rehtie detucexe eb tsum yrt ht nihtiw morf dellac noitcnuf yna morf ro ,flesti kcolb e

yrt .)yltceridni ro yltcerid( kcolb

elbacilppa on si ereht hcihw rof noitpecxe na worht uoy fI hctac margorp lamronba na ,tnemetats

noitcnuf yrarbil dradnats eht sesuac noitpecxe deldnahnu na gniworhT .rucco yam noitanimret

)(etanimret yB .dekovni eb ot ,tluafed )(etanimret sllac )(troba nac uoy tub ,margorp ruoy pots ot

.reldnah noitanimret nwo ruoy yficeps

Page 136: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 331

.setarepo gnildnah noitpecxe ++C yaw eht swohs taht elpmaxe elpmis a si ereH

.elpmaxe gnildnah noitpecxe elpmis A //

>maertsoi< edulcni#

an gnisu ;dts ecapsem

)(niam tni

{

tratS" << tuoc \ ;"n

kcolb yrt a trats // { yrt

kcolb yrt edisnI" << tuoc \ ;"n

rorre na worht // ;001 worht

;"etucexe ton lliw sihT" << tuoc

}

rorre na hctac // { )i tni( hctac

noitpecxe na thguaC" << tuoc -- ;" :si eulav

< i << tuoc " < \ ;"n

}

;"dnE" << tuoc

;0 nruter

}

:tuptuo gniwollof eht syalpsid margorp sihT

tratS

kcolb yrt edisnI

noitpecxe na thguaC -- 001 :si eulav

dnE

a si ereht ,ees nac uoy sA .margorp siht ta ylluferac kooL yrt dna stnemetats eerht gniniatnoc kcolb

a i(hctac )i tn eht nihtiW .noitpecxe regetni na sessecorp taht tnemetats yrt eht fo owt ylno ,kcolb

tsrif eht :etucexe lliw stnemetats eerht tuoc eht dna tnemetats worht neeb sah noitpecxe na ecnO .

eht ot sessap lortnoc ,nworht hctac eht dna noisserpxe yrt si kcolb ,si tahT .detanimret hctac si ton

Page 137: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 431

sa teser yllacitamotua si kcats s'margorp ehT( .ti ot derrefsnart si noitucexe margorp ,rehtaR .dellac

eht ,suhT ).siht hsilpmocca ot dedeen tuoc eht gniwollof tnemetats worht .etucexe reven lliw

nihtiw edoc eht ,yllausU a hctac .noitca etairporppa gnikat yb rorre na ydemer ot stpmetta tnemetats

eht gniwollof stnemetats eht htiw eunitnoc lliw noitucexe ,dexif eb nac rorre eht fI hctac ,revewoH .

a dna dexif eb tonnac rorre na netfo hctac iw margorp eht etanimret lliw kcolb ot llac a ht )(tixe ro

)(troba .

a ni deificeps epyt eht hctam tsum noitpecxe eht fo epyt eht ,denoitnem sA hctac roF .tnemetats

eht ni epyt eht egnahc uoy fi ,elpmaxe gnidecerp eht ni ,elpmaxe hctac ot tnemetats elbuod eht ,

a thguac eb ton lliw noitpecxe lliw noitanimret lamronba dn .ereh nwohs si egnahc sihT .rucco

.krow ton lliw elpmaxe sihT //

>maertsoi< edulcni#

;dts ecapseman gnisu

)(niam tni

{

tratS" << tuoc \ ;"n

kcolb yrt a trats // { yrt

kcolb yrt edisnI" << tuoc \ ;"n

rorre na worht // ;001 worht

oc ;"etucexe ton lliw sihT" << tu

}

noitpecxe tni na rof krow t'now // { )i elbuod( hctac

noitpecxe na thguaC" << tuoc -- ;" :si eulav

" << i << tuoc \ ;"n

}

;"dnE" << tuoc

;0 nruter

}

Page 138: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 531

iw noitpecxe regetni eht esuaceb tuptuo gniwollof eht secudorp margorp sihT eht yb thguac eb ton ll

)i elbuod(hctac .tnemetats

tratS

kcolb yrt edisnI

noitanimret margorp lamronbA

eht edistuo morf nworht eb nac noitpecxe nA yrt si taht noitcnuf a yb nworht si ti sa gnol sa kcolb

nihtiw morf dellac yrt si siht ,elpmaxe roF .kcolb .margorp dilav a

eht edistuo noitcnuf a morf noitpecxe na gniworhT */

.kcolb yrt

/*

>maertsoi< edulcni#

;dts ecapseman gnisu

)tset tni(tsetX diov

{

" << tset << " :si tset ,tsetX edisnI" << tuoc \ ;"n

;tset worht )tset(fi

}

)(niam tni

{

tratS" << tuoc \ ;"n

t kcolb yrt a trats // { yr

kcolb yrt edisnI" << tuoc \ ;"n

;)0(tsetX

;)1(tsetX

;)2(tsetX

}

rorre na hctac // { )i tni( hctac

394 g n i l d n a H n o i t p e c x E : 9 1 r e t p a h C

Page 139: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 631

noitpecxe na thguaC" << tuoc -- ;" :si eulav

" << i << tuoc \ ;"n

}

E" << tuoc ;"dn

;0 nruter

}

:tuptuo gniwollof eht secudorp margorp sihT

tratS

kcolb yrt edisnI

0 :si tset ,tsetX edisnI

1 :si tset ,tsetX edisnI

noitpecxe na thguaC -- 1 :si eulav

dnE

A yrt eht emit hcae ,esac eht si siht nehW .noitcnuf a ot dezilacol eb nac kcolb ,deretne si noitcnuf

.margorp siht enimaxe ,elpmaxe roF .teser si noitcnuf taht ot evitaler gnildnah noitpecxe eht

>maertsoi< edulcni#

;dts ecapseman gnisu

.noitcnuf a ot hctac/yrt a ezilacoL //

)tset tni(reldnahX diov

{

{yrt

;tset worht )tset(fi

}

hctac { )i tni(

' << i << " :# noitpecxE thguaC" << tuoc \ ;'n

}

}

Page 140: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 731

)(niam tni

{

tratS" << tuoc \ ;"n

;)1(reldnahX

;)2(reldnahX

;)0(reldnahX

;)3(reldnahX

;"dnE" << tuoc

;0 nruter

}

:tuptuo siht syalpsid margorp sihT

tratS

1 :# noitpecxE thguaC

2 :# noitpecxE thguaC

3 :# noitpecxE thguaC

dnE

eht nehW .snruter noitcnuf eht ,noitpecxe hcae retfA .nworht era snoitpecxe eerht ,ees nac uoy sA

.teser si gnildnah noitpecxe eht ,niaga dellac si noitcnuf

a htiw detaicossa edoc eht taht dnatsrednu ot tnatropmi si tI hctac s fi ylno detucexe eb lliw tnemetat

eht sessapyb ylpmis noitucexe ,esiwrehtO .noitpecxe na sehctac ti hctac ,si tahT( .rehtegotla

a otni swolf reven noitucexe hctac noitpecxe on ,margorp gniwollof eht ni ,elpmaxe roF ).tnemetats

eht os ,nworht si hctac etats .etucexe ton seod tnem

>maertsoi< edulcni#

;dts ecapseman gnisu

)(niam tni

{

Page 141: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 831

tratS" << tuoc \ ;"n

kcolb yrt a trats // { yrt

kcolb yrt edisnI" << tuoc \ ;"n

kcolb yrt edisni llitS" << tuoc \ ;"n

}

rorre na hctac // { )i tni( hctac

noitpecxe na thguaC" << tuoc -- ;" :si eulav

" << i << tuoc \ ;"n

}

;"dnE" << tuoc

;0 nruter

}

.tuptuo gniwollof eht secudorp margorp gnidecerp ehT

tratS

kcolb yrt edisnI

kcolb yrt edisni llitS

dnE

ehT hctac .noitucexe fo wolf eht yb dessapyb si tnemetats

sepyT ssalC gnihctaC

cxe nA laer ni ,yllautcA .etaerc uoy taht sepyt ssalc gnidulcni ,epyt yna fo eb nac noitpe - dlrow

tliub naht rehtar sepyt ssalc eb lliw snoitpecxe tsom ,smargorp - nommoc tsom eht spahreP .sepyt ni

si noitpecxe na rof epyt ssalc a enifed ot tnaw lliw uoy taht nosaer sebircsed taht tcejbo na etaerc ot

eht ssecorp ti pleh ot reldnah noitpecxe eht yb desu eb nac noitamrofni sihT .derrucco taht rorre eht

.siht setartsnomed elpmaxe gniwollof ehT .rorre

.snoitpecxe epyt ssalc gnihctaC //

Page 142: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 931

>maertsoi< edulcni#

rtsc< edulcni# >gni

;dts ecapseman gnisu

{ noitpecxEyM ssalc

:cilbup

;]08[tahw_rts rahc

;tahw tni

} ;0 = tahw ;0 = tahw_rts* { )(noitpecxEyM

{ )e tni ,s* rahc(noitpecxEyM

;)s ,tahw_rts(ypcrts

;e = tahw

}

;}

)(niam tni

{

;i tni

{ yrt

;" :rebmun evitisop a retnE" << tuoc

c ;i >> ni

)0<i(fi

;)i ,"evitisoP toN"(noitpecxEyM worht

}

rorre na hctac // { )e noitpecxEyM( hctac

;" :" << tahw_rts.e << tuoc

" << tahw.e << tuoc \ ;"n

}

;0 nruter

}

:nur elpmas a si ereH

Page 143: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 041

:rebmun evitisop a retnE -4

:evitisoP toN -4

t stpmorp margorp ehT fo tcejbo na ,deretne si rebmun evitagen a fI .rebmun evitisop a rof resu eh

ssalc eht noitpecxEyM ,suhT .rorre eht sebircsed taht detaerc si noitpecxEyM setaluspacne

g nI .reldnah noitpecxe eht yb desu neht si noitamrofni sihT .rorre eht tuoba noitamrofni uoy ,larene

eht elbane ot rorre na tuoba noitamrofni etaluspacne lliw taht sessalc noitpecxe etaerc ot tnaw lliw

.ylevitceffe dnopser ot reldnah noitpecxe

stnemetatS hctac elpitluM gnisU

eno naht erom evah nac uoY hctac a htiw detaicossa yrt ti ,tcaf nI . ,revewoH .os od ot nommoc si

hcae hctac htob sehctac margorp siht ,elpmaxe roF .noitpecxe fo epyt tnereffid a hctac tsum

.sgnirts dna sregetni

>maertsoi< edulcni#

;dts ecapseman gnisu

.thguac eb nac snoitpecxe fo sepyt tnereffiD //

tset tni(reldnahX diov )

{

{yrt

;tset worht )tset(fi

;"orez si eulaV" worht esle

}

{ )i tni(hctac

' << i << " :# noitpecxE thguaC" << tuoc \ ;'n

}

{ )rts* rahc tsnoc(hctac

;" :gnirts a thguaC" << tuoc

' << rts << tuoc \ ;'n

}

Page 144: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 141

}

)(niam tni

{

tratS" << tuoc \ ;"n

;)1(reldnahX

2(reldnahX ;)

;)0(reldnahX

;)3(reldnahX

;"dnE" << tuoc

;0 nruter

}

:tuptuo gniwollof eht secudorp margorp sihT

tratS

1 :# noitpecxE thguaC

2 :# noitpecxE thguaC

orez si eulaV :gnirts a thguaC

3 :# noitpecxE thguaC

dnE

hcae ,ees nac uoy sA hctac sdnopser tnemetats ,lareneg nI .epyt nwo sti ot ylno hctac snoisserpxe

.detucexe si tnemetats gnihctam a ylnO .margorp a ni rucco yeht hcihw ni redro eht ni dekcehc era

rehto llA hctac .derongi era skcolb

snoitpO gnildnaH noitpecxE

dna serutaef lanoitidda lareves era erehT dna reisae ti ekam taht gnildnah noitpecxe ++C ot secnaun

.ereh dessucsid era setubirtta esehT .esu ot tneinevnoc erom

snoitpecxE llA gnihctaC

Page 145: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 241

a tsuj fo daetsni snoitpecxe lla hctac ot reldnah noitpecxe na tnaw lliw uoy secnatsmucric emos nI

pyt niatrec fo mrof siht esu ylpmiS .hsilpmocca ot ysae si sihT .e hctac .

{ )...(hctac

// snoitpecxe lla ssecorp

}

setartsulli margorp gniwollof ehT .atad fo epyt yna sehctam sispille eht ,ereH )...(hctac .

.snoitpecxe lla sehctac elpmaxe sihT //

>maertsoi< edulcni#

u ;dts ecapseman gnis

)tset tni(reldnahX diov

{

{yrt

tni worht // ;tset worht )0==tset(fi

rahc worht // ;'a' worht )1==tset(fi

elbuod worht // ;32.321 worht )2==tset(fi

}

snoitpecxe lla hctac // { )...(hctac

!enO thguaC" << tuoc \ ;"n

}

}

)(niam tni

{

<< tuoc tratS" \ ;"n

;)0(reldnahX

;)1(reldnahX

;)2(reldnahX

;"dnE" << tuoc

;0 nruter

}

Page 146: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 341

.tuptuo gniwollof eht syalpsid margorp sihT

tratS

!enO thguaC

!enO thguaC

!enO thguaC

dnE

eerht lla ,ees nac uoy sA worht eno eht gnisu thguac erew s hctac .tnemetats

yrev enO rof esu doog )...(hctac tsal eht sa si hctac ti yticapac siht nI .sehctac fo retsulc a fo

eht fo noisrev tnereffid ylthgils siht ,elpmaxe roF .tnemetats "lla hctac" ro tluafed lufesu a sedivorp

er tub snoitpecxe regetni sehctac yticilpxe margorp gnidecerp nopu seil )...(hctac .srehto lla hctac ot

.tluafed a sa )...(hctac sesu elpmaxe sihT //

>maertsoi< edulcni#

;dts ecapseman gnisu

)tset tni(reldnahX diov

{

{yrt

tni worht // ;tset worht )0==tset(fi

rahc worht // ;'a' worht )1==tset(fi

321 worht )2==tset(fi elbuod worht // ;32.

}

noitpecxe tni na hctac // { )i tni(hctac

regetni na thguaC" << tuoc \ ;"n

}

snoitpecxe rehto lla hctac // { )...(hctac

!enO thguaC" << tuoc \ ;"n

}

Page 147: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 441

}

)(niam tni

{

tratS" << tuoc \ ;"n

;)0(reldnahX

;)1(reldnahX

;)2(reldnahX

;"dnE" << tuoc

r ;0 nrute

}

.ereh nwohs si margorp siht yb decudorp tuptuo ehT

tratS

regetni na thguaC

!enO thguaC

!enO thguaC

dnE

gnisu ,stseggus elpmaxe siht sA )...(hctac uoy taht snoitpecxe lla hctac ot yaw doog a si tluafed a sa

slA .ylticilpxe eldnah ot tnaw t'nod deldnahnu na tneverp uoy ,snoitpecxe lla gnihctac yb ,o

.noitanimret margorp lamronba na gnisuac morf noitpecxe

snoitpecxE gnitcirtseR

nac uoy ,tcaf nI .flesti fo edistuo worht nac noitcnuf a taht snoitpecxe fo epyt eht tcirtser nac uoY

uf a tneverp osla ,snoitcirtser eseht hsilpmocca oT .reveostahw snoitpecxe yna gniworht morf noitcn

a dda tsum uoy worht .noitinifed noitcnuf a ot esualc

:ereh nwohs si siht fo mrof lareneg ehT

Page 148: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 541

ter - cnuf epyt - eman ( gra - tsil (worht ) epyt - tsil )

{

... //

}

ad esoht ylno ,ereH ammoc eht ni deniatnoc sepyt at - detarapes epyt - tsil eht yb nworht eb yam

uoy fI .noitanimret margorp lamronba esuac lliw noisserpxe fo epyt rehto yna gniworhT .noitcnuf

worht ot elba eb ot noitcnuf a tnaw t'nod yna .tsil ytpme na esu neht ,snoitpecxe

ettA yrarbil dradnats eht esuac lliw noitcnuf a yb detroppus ton si taht noitpecxe na worht ot gnitpm

noitcnuf )(detcepxenu sesuac siht ,tluafed yB .dellac eb ot )(troba sesuac hcihw ,dellac eb ot

nwo ruoy yficeps nac uoy ,revewoH .noitanimret margorp lamronba .ekil uoy fi reldnah detcepxenu

a morf nworht eb nac taht snoitpecxe fo sepyt eht tcirtser ot woh swohs margorp gniwollof ehT

.noitcnuf

.sepyt worht noitcnuf gnitcirtseR //

>maertsoi< edulcni#

;dts ecapseman gnisu

c ,stni worht ylno nac noitcnuf sihT // .selbuod dna ,srah

)elbuod ,rahc ,tni(worht )tset tni(reldnahX diov

{

tni worht // ;tset worht )0==tset(fi

rahc worht // ;'a' worht )1==tset(fi

elbuod worht // ;32.321 worht )2==tset(fi

}

)(niam tni

{

trats" << tuoc \ ;"n

{yrt

issap yrt ,osla // ;)0(reldnahX )(reldnahX ot 2 dna 1 gn

Page 149: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 641

}

{ )i tni(hctac

regetni na thguaC" << tuoc \ ;"n

}

{ )c rahc(hctac

rahc thguaC" << tuoc \ ;"n

}

{ )d elbuod(hctac

elbuod thguaC" << tuoc \ ;"n

}

;"dne" << tuoc

;0 nruter

}

noitcnuf eht ,margorp siht nI )(reldnahX regetni worht ylno yam dna ,retcarahc , elbuod .snoitpecxe

.rucco lliw noitanimret margorp lamronba na ,noitpecxe fo epyt rehto yna worht ot stpmetta ti fI

,si tahT( )(detcepxenu evomer ,siht fo elpmaxe na ees oT ).dellac eb lliw tni yrter dna tsil eht morf

.margorp eht

i si tI ti snoitpecxe fo sepyt tahw ni ylno detcirtser eb nac noitcnuf a taht dnatsrednu ot tnatropm

eht ot kcab sworht yrt a ,si tahT .ti dellac taht kcolb yrt kcolb nihtiw epyt yna worht yam noitcnuf a

thguac si ti sa gnol os noitpecxe fo nihtiw T .noitcnuf taht gniworht nehw ylno seilppa noitcirtser eh

.noitcnuf eht fo edistuo noitpecxe na

ot egnahc gniwollof ehT )(reldnahX .snoitpecxe yna gniworht morf ti stneverp

!snoitpecxe ON worht nac noitcnuf sihT //

)(worht )tset tni(reldnahX diov

{

tats gniwollof ehT */ ,daetsnI .krow regnol on stneme

/* .noitanimret margorp lamronba na esuac lliw yeht

Page 150: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 741

;tset worht )0==tset(fi

;'a' worht )1==tset(fi

;32.321 worht )2==tset(fi

}

noitpecxE na gniworhteR

,reldnah noitpecxe na nihtiw morf noisserpxe na worhter ot hsiw uoy fI gnillac yb os od yam uoy

worht retuo na ot no dessap eb ot noitpecxe tnerruc eht sesuac sihT .noitpecxe on htiw ,flesti yb ,

hctac/yrt eht ot ssecca sreldnah elpitlum wolla ot si os gniod rof nosaer ylekil tsom ehT .ecneuqes

spahrep ,elpmaxe roF .noitpecxe a dna noitpecxe na fo tcepsa eno seganam reldnah noitpecxe eno

a nihtiw morf nworhter eb ylno nac noitpecxe nA .rehtona htiw sepoc reldnah dnoces hctac kcolb

b ton lliw ti ,noitpecxe na worhter uoy nehW .)kcolb taht nihtiw morf dellac noitcnuf yna morf ro( e

emas eht yb thguacer hctac txen eht ot drawtuo etagaporp lliw tI .tnemetats hctac ehT .tnemetats

a esac siht ni ,noitpecxe na gniworhter setartsulli margorp gniwollof * rahc .noitpecxe

.noitpecxe na "gniworhter" fo elpmaxE //

>maertsoi< edulcni#

n gnisu ;dts ecapsema

)(reldnahX diov

{

{ yrt

* rahc a worht // ;"olleh" worht

}

* rahc a hctac // { )* rahc tsnoc(hctac

reldnahX edisni * rahc thguaC" << tuoc \ ;"n

noitcnuf fo tuo * rahc worhter // ; worht

}

}

)(niam tni

{

Page 151: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 841

tratS" << tuoc \ ;"n

{yrt

;)(reldnahX

}

tac { )* rahc tsnoc(hc

niam edisni * rahc thguaC" << tuoc \ ;"n

}

;"dnE" << tuoc

;0 nruter

}

:tuptuo siht syalpsid margorp sihT

tratS

reldnahX edisni * rahc thguaC

niam edisni * rahc thguaC

dnE

ehT yrarbil etalpmet dradnats ( LTS .) o saw LTS eht fo noisulcni ehT taht stroffe rojam eht fo en

lareneg sedivorp tI .++C fo noitazidradnats eht gnirud ecalp koot - dna sessalc dezitalpmet ,esoprup

,serutcurts atad dna smhtirogla desu ylnommoc dna ralupop ynam tnemelpmi taht snoitcnuf

tcev rof troppus ,elpmaxe rof ,gnidulcni senituor suoirav senifed osla tI .skcats dna ,seueuq ,stsil ,sro

atad dna smhtirogla eht ,sessalc etalpmet morf detcurtsnoc si LTS eht esuaceB .meht ssecca taht

.atad fo epyt yna ylraen ot deilppa eb nac serutcurts

erawtfos fo eceip xelpmoc a si LTS ehT detacitsihpos tsom s'++C fo emos sesu taht gnireenigne

++C eht fo gnidnatsrednu etelpmoc a evah tsum uoy ,LTS eht esu dna dnatsrednu oT .serutaef

sebircsed taht xatnys etalpmet eht ,ylknarF .setalpmet dna ,secnerefer ,sretniop gnidulcni ,egaugnal

c LTS eht elihW .si yllautca ti naht detacilpmoc erom skool ti hguohtla gnitadimitni etiuq mees na

,koob siht fo tser eht ni lairetam eht naht tluciffid erom yna si taht retpahc siht ni gnihton si ereht

ta gnisufnoc LTS eht dnif uoy fi deyamsid ro desirprus eb t'nod eht yduts ,tneitap eb tsuJ .tsrif

.yticilpmis cisab s'LTS eht edirrevo xatnys railimafnu eht tel t'nod dna ,selpmaxe

Page 152: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 941

,yhposolihp ngised sti gnidulcni ,LTS eht fo weivrevo na tneserp ot si retpahc siht fo esoprup ehT

rp eht dna ,stneutitsnoc ,noitazinagro a si LTS eht esuaceB .ti esu ot dedeen seuqinhcet gnimmargo

ot ecnerefer etelpmoc a ,revewoH .ereh serutaef sti fo lla ssucsid ot elbissop ton si ti ,yrarbil egral

.ruoF traP ni dedivorp si LTS eht

n tnatropmi tsom s'++C fo eno sebircsed osla retpahc sihT :sessalc we gnirts ehT . gnirts ssalc

atad rehto od uoy sa hcum sgnirts retcarahc htiw krow ot uoy swolla taht epyt atad gnirts a senifed

ehT .srotarepo gnisu :sepyt gnirts .LTS eht ot detaler ylesolc si ssalc

LTS eht fo weivrevO nA

dradnats eht hguohtlA etiuq yllautca si ti ,gnitadimitni eb nac xatnys sti dna egral si yrarbil etalpmet

,eroferehT .syolpme ti stnemele tahw dna detcurtsnoc si ti woh dnatsrednu uoy ecno esu ot ysae

.detnarraw si LTS eht fo weivrevo na ,selpmaxe edoc yna ta gnikool erofeb

tA :smeti lanoitadnuof eerht era yrarbil etalpmet dradnats eht fo eroc eht sreniatnoc , smhtirogla ,

dna srotareti ffo edivorp ot rehtona eno htiw noitcnujnoc ni krow smeti esehT . - eht - ot snoitulos flehs

.smelborp gnimmargorp fo yteirav a

sreniatnoC

sreniatnoC ,elpmaxe roF .sepyt tnereffid lareves era ereht dna ,stcejbo rehto dloh taht stcejbo era

eht rotcev ,yarra cimanyd a senifed ssalc euqed elbuod a setaerc - dna ,eueuq dedne tsil a sedivorp

dellac era sreniatnoc esehT .tsil raenil sreniatnoc ecneuqes esuaceb ecneuqes a ,ygolonimret LTS ni

senifed osla LTS eht ,sreniatnoc cisab eht ot noitidda nI .tsil raenil a si ,sreniatnoc evitaicossa

a ,elpmaxe roF .syek no desab seulav fo laveirter tneiciffe wolla hcihw pam ot ssecca sedivorp

suhT .syek euqinu htiw seulav a , pam deveirter eb ot eulav a swolla dna riap eulav/yek a serots

.yek sti nevig

Page 153: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 051

a ,elpmaxe roF .reniatnoc eht ot deilppa eb yam taht snoitcnuf fo tes a senifed ssalc reniatnoc hcaE

tnemele egrem dna ,eteled ,tresni taht snoitcnuf sedulcni reniatnoc tsil snoitcnuf sedulcni kcats A .s

.seulav pop dna hsup taht

smhtiroglA

smhtiroglA fo stnetnoc eht etalupinam lliw uoy hcihw yb snaem eht edivorp yehT .sreniatnoc no tca

imrofsnart dna ,gnihcraes ,gnitros ,noitazilaitini edulcni seitilibapac riehT .sreniatnoc stnetnoc eht gn

a no etarepo smhtirogla ynaM .sreniatnoc fo egnar .reniatnoc a nihtiw stnemele fo

srotaretI

srotaretI eht hguorht elcyc ot ytiliba eht uoy evig yehT .sretniop ,ssel ro erom ,era taht stcejbo era

aw emas eht hcum ni reniatnoc a fo stnetnoc .yarra na hguorht elcyc ot retniop a esu dluow uoy taht y

:srotareti fo sepyt evif era erehT

rotaretI dewollA sseccA

sseccA modnaR .ylmodnar dessecca eb yam stnemelE .seulav eveirter dna erotS

lanoitceridiB b dna drawroF .seulav eveirter dna erotS .gnivom drawkca

drawroF .ylno gnivom drawroF .seulav eveirter dna erotS

tupnI .ylno gnivom drawroF .seulav erots ton tub ,eveirteR

tuptuO .ylno gnivom drawroF .seulav eveirter ton tub ,erotS

bapac ssecca retaerg sah taht rotareti na ,lareneg nI ressel sah taht eno fo ecalp ni desu eb nac seitili

.rotareti tupni na fo ecalp ni desu eb nac rotareti drawrof a ,elpmaxe roF .seitilibapac

eht ylppa nac uoY .meht tnemerced dna tnemercni nac uoY .sretniop ekil tsuj deldnah era srotaretI *

t ot rotarepo eht gnisu deralced era srotaretI .meh rotareti .sreniatnoc suoirav eht yb denifed epyt

Page 154: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 151

stroppus osla LTS ehT srotareti esrever modnar ro lanoitceridib rehtie era srotareti esreveR . - ssecca

hT .noitcerid esrever eht ni ecneuqes a hguorht evom taht srotareti ot stniop rotareti esrever a fi ,su

.dne eht erofeb tnemele eno ot tniop ot ti esuac lliw rotareti taht gnitnemercni ,ecneuqes a fo dne eht

eht esu lliw koob siht ,snoitpircsed etalpmet ni sepyt rotareti suoirav eht ot gnirrefer nehW

:smret gniwollof

eT mr stneserpeR

retIiB rotareti lanoitceridiB

retIroF rotareti drawroF

retInI rotareti tupnI

retItuO rotareti tuptuO

retIdnaR rotareti ssecca modnaR

srotceV

lareneg tsom eht spahreP - si sreniatnoc eht fo esoprup rotcev ehT . rotcev a stroppus ssalc cimanyd

ta dexif si yarra na fo ezis eht ++C ni ,wonk uoy sA .dedeen sa worg nac taht yarra na si sihT .yarra

tsom eht osla si ti ,syarra tnemelpmi ot yaw tneiciffe tsom eht raf yb si siht elihW .emit elipmoc

nnac yarra eht fo ezis eht esuaceb evitcirtser gnignahc etadommocca ot emit nur ta detsujda eb to

a hguohtlA .dedeen sa yromem gnitacolla yb melborp siht sevlos rotcev A .snoitidnoc margorp

.stnemele sti ssecca ot noitaton tpircsbus yarra dradnats eht esu llits nac uoy ,cimanyd si rotcev

etalpmet ehT rof noitacificeps rotcev :ereh nwohs si

rotcev ssalc >>T<rotacolla = rotacollA ssalc ,T ssalc< etalpmet

,ereH T dna derots gnieb atad fo epyt eht si rotacollA eht ot stluafed hcihw ,rotacolla eht seificeps

.rotacolla dradnats rotcev noc gniwollof eht sah :srotcurts

& rotacollA tsnoc(rotcev ticilpxe a ;) ) (rotacollA =

Page 155: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 251

epyt_ezis(rotcev ticilpxe mun & T tsnoc , lav ,) ( T =

& rotacollA tsnoc a ;)) (rotacollA =

& >rotacollA ,T<rotcev tsnoc(rotcev bo ;)

retInI(rotcev >retInI ssalc< etalpmet trats retInI , dne ,

tsnoc & rotacollA a ;)) (rotacollA =

sah taht rotcev a stcurtsnoc mrof dnoces ehT .rotcev ytpme na stcurtsnoc mrof tsrif ehT mun

eulav eht htiw stnemele lav fo eulav ehT . lav a stcurtsnoc mrof driht ehT .tluafed ot dewolla eb yam

e emas eht sniatnoc taht rotcev sa stnemel bo eht sniatnoc taht rotcev a stcurtsnoc mrof htruof ehT .

srotareti eht yb deificeps egnar eht ni stnemele trats dna dne .

a ni derots eb lliw taht tcejbo ynA rotcev < eht enifed osla tsum tI .rotcurtsnoc tluafed a enifed tsum

.snoitarepo == dna ecniS( .denifed eb srotarepo nosirapmoc rehto taht eriuqer yam srelipmoc emoS

eht fo llA ).noitamrofni esicerp rof noitatnemucod s'relipmoc ruoy tlusnoc ,yrav snoitatnemelpmi

tliub - .stnemeriuqer eseht yfsitas yllacitamotua sepyt ni

etalpmet eht hguohtlA a gniralced tuoba tluciffid gnihton si ereht ,xelpmoc rehtar skool xatnys

:selpmaxe emos era ereH .rotcev

orez etaerc // ;vi >tni<rotcev - rotcev tni htgnel

5 etaerc // ;)5(vc >rahc<rotcev - rotcev rahc tnemele

5 a ezilaitini // ;)'x' ,5(vc >rahc<rotcev - emele rotcev rahc tn

rotcev tni na morf rotcev tni etaerc // ;)vi(2vi >tni<rotcev

rof denifed era srotarepo nosirapmoc gniwollof ehT rotcev :

=> ,> ,=! ,=< ,< ,==

rof denifed osla si ] [ rotarepo gnitpircsbus ehT rotcev stnemele eht ssecca ot uoy swolla sihT . a fo

.noitaton gnitpircsbus yarra dradnats gnisu rotcev

Page 156: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 351

yb denifed snoitcnuf rebmem eht fo lareveS rotcev ruoF traP ,rebmemeR( 1.8 elbaT ni nwohs era

rebmem desu ylnommoc tsom eht fo emoS ).sessalc LTS eht ot ecnerefer etelpmoc a sniatnoc

era snoitcnuf is )(ez , )(nigeb , )(dne , )(kcab_hsup , )(tresni dna , )(esare ehT . )(ezis noitcnuf

ot uoy swolla ti esuaceb lufesu etiuq si noitcnuf sihT .rotcev eht fo ezis tnerruc eht snruter

i esaercni lliw srotcev ,rebmemeR .emit nur ta rotcev a fo ezis eht enimreted eht os ,dedeen sa ezis n

.noitalipmoc gnirud ton ,noitucexe gnirud denimreted eb tsum rotcev a fo ezis

ehT )(nigeb ehT .rotcev eht fo trats eht ot rotareti na snruter noitcnuf )(dne na snruter noitcnuf

limis era srotaretI .rotcev eht fo dne eht ot rotareti ra eht fo esu eht hguorht si ti dna ,sretniop ot

)(nigeb dna )(dne uoy taht snoitcnuf .rotcev a fo dne dna gninnigeb eht ot rotareti na niatbo

ehT )(kcab_hsup si rotcev eht ,yrassecen fI .rotcev eht fo dne eht otno eulav a stup noitcnuf

gnel ni desaercni elddim eht ot stnemele dda osla nac uoY .tnemele wen eht etadommocca ot ht

gnisu )(tresni uoy ,stnemele sniatnoc rotcev a ecno ,tneve yna nI .dezilaitini eb osla nac rotcev A .

e evomer nac uoY .stnemele esoht yfidom ro ssecca ot gnitpircsbus yarra esu nac a morf stnemel

gnisu rotcev )(esare .

rebmeM noitpircseD

;) (kcab ecnerefer tnemele tsal eht ot ecnerefer a snruteR

;tsnoc ) (kcab ecnerefer_tsnoc .rotcev eht ni

;) (nigeb rotareti tnemele tsrif eht ot rotareti na snruteR

ti_tsnoc ;tsnoc ) (nigeb rotare .rotcev eht ni

;) (raelc diov .rotcev eht morf stnemele lla sevomeR

;tsnoc ) (ytpme loob si rotcev gnikovni eht fi eurt snruteR

.esiwrehto eslaf dna ytpme

;) (dne rotareti t fo dne eht ot rotareti na snruteR eh

;tsnoc ) (dne rotareti_tsnoc .rotcev

Page 157: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 451

rotareti(esare rotareti i ;) ot detniop tnemele eht sevomeR

yb i.

retfa tnemele eht ot rotareti na snruteR

.devomer eno eht

rotareti(esare rotareti trats rotareti , dne ;) gnar eht ni stnemele eht sevomeR e

trats ot dne eht ot rotareti na snruteR .

.devomer tnemele tsal eht retfa tnemele

;) (tnorf ecnerefer tnemele tsrif eht ot ecnerefer a snruteR

;tsnoc ) (tnorf ecnerefer_tsnoc .rotcev eht ni

rotareti(tresni rotareti i, stresnI lav etaidemmi erofeb yl

eht

& T tsnoc lav ;) yb deificeps tnemele .i ot rotareti nA

.denruter si tnemele eht

rotareti(tresni diov i epyt_ezis , mun , stresnI mun fo seipoc lav yletaidemmi

& T tsnoc lav ) yb deificeps tnemele eht erofeb i.

alc< etalpmet >retInI ss yb denifed ecneuqes eht stresnI

trats

rotareti(tresni diov i retInI , trats , dna dne eht erofeb yletaidemmi

retInI dne ;) yb deificeps tnemele i.

epyt_ezis(] [rotarepo ecnerefer i ;tsnoc ) eht ot ecnerefer a snruteR

tnemele

tsnoc epyt_ezis(] [rotarepo ecnerefer_ i) yb deificeps i.

Page 158: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 551

;tsnoc

;) (kcab_pop diov .rotcev eht ni tnemele tsal eht sevomeR

& T tsnoc(kcab_hsup diov lav ;) eulav eht htiw tnemele na sddA

deificeps

yb lav .rotcev eht fo dne eht ot

) (ezis epyt_ezis ;tsnoc stnemele fo rebmun eht snruteR

.rotcev eht ni yltnerruc

rotcev yb denifeD snoitcnuF rebmeM desU ylnommoC emoS .1.8 elbaT

.rotcev a fo noitarepo cisab eht setartsulli taht elpmaxe trohs a si ereH

.rotcev a etartsnomeD //

>maertsoi< edulcni#

>rotcev< edulcni#

>epytcc< edulcni#

;dts ecapseman gnisu

)(niam tni

{

01 htgnel fo rotcev a etaerc // ;)01(v >rahc<rotcev

;i tni

v fo ezis lanigiro yalpsid //

;ldne << )(ezis.v << " = eziS" << tuoc

seulav emos rotcev eht fo stnemele eht ngissa //

;0=i(rof ;'a' + i = ]i[v )++i ;01<i

rotcev fo stnetnoc yalpsid //

:stnetnoC tnerruC" << tuoc \ ;"n

;" " << ]i[v << tuoc )++i ;)(ezis.v<i ;0=i(rof

Page 159: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 651

" << tuoc \n\ ;"n

rotcev gnidnapxE" << tuoc \ ;"n

,rotcev eht fo dne eht otno seulav erom tup */

/* dedeen sa worg lliw ti

of ;)'a' + 01 + i(kcab_hsup.v )++i ;01<i ;0=i(r

v fo ezis tnerruc yalpsid //

;ldne << )(ezis.v << " = won eziS" << tuoc

rotcev fo stnetnoc yalpsid //

:stnetnoc tnerruC" << tuoc \ ;"n

;" " << ]i[v << tuoc )++i ;)(ezis.v<i ;0=i(rof

" << tuoc \n\ ;"n

etnoc egnahc // rotcev fo stn

;)]i[v(reppuot = ]i[v )++i ;)(ezis.v<i ;0=i(rof

:stnetnoC deifidoM" << tuoc \ ;"n

;" " << ]i[v << tuoc )++i ;)(ezis.v<i ;0=i(rof

;ldne << tuoc

;0 nruter

}

:ereh nwohs si margorp siht fo tuptuo ehT

01 = eziS

:stnetnoC tnerruC

i h g f e d c b a j

rotcev gnidnapxE

02 = won eziS

:stnetnoc tnerruC

t s r q p o n m l k j i h g f e d c b a

:stnetnoC deifidoM

T S R Q P O N M L K J I H G F E D C B A

Page 160: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 751

nI .ylluferac margorp siht ta kool s'teL )(niam dellac rotcev retcarahc a , v laitini na htiw detaerc si

,si tahT .01 fo yticapac v eht gnillac yb demrifnoc si sihT .stnemele 01 sniatnoc yllaitini )(ezis

eht dna j hguorht a sretcarahc eht ot dezilaitini era stnemele 01 eseht ,txeN .noitcnuf rebmem

fo stnetnoc v s yarra dradnats eht taht ecitoN .deyalpsid era ,txeN .deyolpme si noitaton gnitpircsbu

fo dne eht ot dedda era stnemele erom 01 v eht gnisu )(kcab_hsup sesuac sihT .noitcnuf v worg ot

.02 si snoitidda eseht retfa ezis sti ,swohs tuptuo eht sA .stnemele wen eht etadommocca ot redro ni

eulav eht ,yllaniF fo s v .noitaton gnitpircsbus dradnats gnisu deretla era stnemele s'

fo stnetnoc eht yalpsid taht spool eht taht ecitoN .margorp siht ni tseretni fo tniop rehto eno si erehT

v eulav tegrat rieht sa esu )(ezis.v evo evah srotcev taht segatnavda eht fo enO . si ti taht si syarra r

yteirav a ni lufesu etiuq eb nac siht ,enigami nac uoy sA .rotcev a fo ezis tnerruc eht dnif ot elbissop

.snoitautis fo

rotaretI na hguorhT rotceV a gnisseccA

dessecca eb nac yarra nA .++C ni deknil ylthgit era sretniop dna syarrA gnitpircsbus hguorht rehtie

uoY .srotareti dna srotcev neewteb knil eht si LTS eht ni siht ot lellarap ehT .retniop a hguorht ro

ehT .rotareti na fo esu eht hguorht ro gnitpircsbus gnisu rotcev a fo srebmem eht ssecca nac

.woh swohs elpmaxe gniwollof

// .rotareti na hguorht rotcev a fo stnemele eht sseccA

>maertsoi< edulcni#

>rotcev< edulcni#

>epytcc< edulcni#

;dts ecapseman gnisu

)(niam tni

{

01 htgnel fo rotcev a etaerc // ;)01(v >rahc<rotcev

rotareti na etaerc // ;p rotareti::>rahc<rotcev

;i tni

ssa // eulav a rotcev ni stnemele ngi

Page 161: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 851

;)(nigeb.v = p

;0 = i

{ ))(dne.v =! p(elihw

;'a' + i = p*

;++p

;++i

}

rotcev fo stnetnoc yalpsid //

:stnetnoc lanigirO" << tuoc \ ;"n

;)(nigeb.v = p

{ ))(dne.v =! p(elihw

;" " << p* << tuoc

;++p

}

" << tuoc \n\ ;"n

tnoc egnahc // rotcev fo stne

;)(nigeb.v = p

{ ))(dne.v =! p(elihw

;)p*(reppuot = p*

;++p

}

rotcev fo stnetnoc yalpsid //

:stnetnoC deifidoM" << tuoc \ ;"n

;)(nigeb.v = p

{ ))(dne.v =! p(elihw

;" " << p* << tuoc

;++p

}

;ldne << tuoc

;0 nruter

}

Page 162: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 951

argorp siht morf tuptuo ehT si m

:stnetnoc lanigirO

j i h g f e d c b a

:stnetnoC deifidoM

J I H G F E D C B A

rotareti eht woh eciton ,margorp eht nI p epyt ehT .deralced si rotareti reniatnoc eht yb denifed si

w uoy ,reniatnoc ralucitrap a rof rotareti na niatbo ot ,suhT .sessalc ot ralimis noitaralced a esu lli

yfilauq ylpmis :elpmaxe eht ni nwohs taht rotareti ,margorp eht nI .reniatnoc eht fo eman eht htiw

p eht gnisu yb rotcev eht fo trats eht ot tniop ot dezilaitini si )(nigeb noitcnuf sihT .noitcnuf rebmem

rotareti na snruter na rotcev eht ssecca ot desu eb neht nac rotareti sihT .rotcev eht fo trats eht ot

retniop a yaw eht ot lellarap yltcerid si ssecorp sihT .dedeen sa ti gnitnemercni yb emit a ta tnemele

eht nehw enimreted oT .yarra na fo stnemele eht ssecca ot desu eb nac neeb sah rotcev eht fo dne

eht ,dehcaer )(dne noitacol eht ot rotareti na snruter noitcnuf sihT .deyolpme si noitcnuf rebmem

nehw ,suhT .rotcev eht ni tnemele tsal eht tsap eno si taht p slauqe )(dne.v rotcev eht fo dne eht ,

.dehcaer neeb sah

gnitresnI rotceV a ni stnemelE gniteleD dna

elddim eht otni stnemele tresni nac uoy ,rotcev a fo dne eht no seulav wen gnittup ot noitidda nI

eht gnisu )(tresni gnisu stnemele evomer osla nac uoY .noitcnuf )(esare margorp gniwollof ehT .

setartsnomed )(tresni dna e )(esar .

.esare dna tresni etartsnomeD //

>maertsoi< edulcni#

>rotcev< edulcni#

;dts ecapseman gnisu

)(niam tni

{

Page 163: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 061

;)01(v >rahc<rotcev

;2v >rahc<rotcev

;">rotceV<" = ][rts rahc

;i tni

v ezilaitini //

;'a' + i = ]i[v )++i ;01<i ;0=i(rof

i sretcarahc ypoc // 2v otni rts n

;)]i[rts(kcab_hsup.2v )++i ;]i[rts ;0=i(rof

rotcev fo stnetnoc lanigiro yalpsid //

:v fo stnetnoc lanigirO" << tuoc \ ;"n

;" " << ]i[v << tuoc )++i ;)(ezis.v<i ;0=i(rof

" << tuoc \n\ ;"n

;)(nigeb.v = p rotareti::>rahc<rotcev

3 ot tniop // ;2 =+ p tnemele dr

v otni s'X 01 tresni //

;)'X' ,01 ,p(tresni.v

noitresni retfa stnetnoc yalpsid //

;ldne << )(ezis.v << " = s'X gnitresni retfa eziS" << tuoc

:tresni retfa stnetnoC" << tuoc \ ;"n

;" " << ]i[v << tuoc )++i ;)(ezis.v<i ;0=i(rof

" << tuoc \n\ ;"n

er // stnemele esoht evom

;)(nigeb.v = p

tnemele dr3 ot tniop // ;2 =+ p

stnemele 01 txen evomer // ;)01+p ,p(esare.v

noiteled retfa stnetnoc yalpsid //

;ldne << )(ezis.v << " = esare retfa eziS" << tuoc

:esare retfa stnetnoC" << tuoc \ ;"n

+i ;)(ezis.v<i ;0=i(rof ;" " << ]i[v << tuoc )+

" << tuoc \n\ ;"n

v otni 2v tresnI //

Page 164: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 161

;))(dne.2v ,)(nigeb.2v ,p(tresni.v

;" = noitresni s'2v retfa eziS" << tuoc

;ldne << )(ezis.v << tuoc

:tresni retfa stnetnoC" << tuoc \ ;"n

;" " << ]i[v << tuoc )++i ;)(ezis.v<i ;0=i(rof

ldne << tuoc ;

e c n e r e f e R e t e l p m o C e h T : + + C 836

;0 nruter

}

:tuptuo gniwollof eht secudorp margorp sihT

:v fo stnetnoc lanigirO

j i h g f e d c b a

02 = s'X gnitresni retfa eziS

:tresni retfa stnetnoC

j i h g f e d c X X X X X X X X X X b a

a eziS 01 = esare retf

:esare retfa stnetnoC

j i h g f e d c b a

81 = noitresni s'2v retfa eziS

:tresni retfa stnetnoC

j i h g f e d c > r o t c e V < b a

fo smrof owt setartsnomed margorp sihT )(tresni otni s'X 01 stresni ti ,desu si ti emit tsrif ehT . v .

ehT ,rotcev dnoces a fo stnetnoc eht stresni ti ,emit dnoces 2v otni , v tsom eht si esu dnoces sihT .

lliw noitresni eht hcihw ta tniop eht seificeps tsrif ehT .stnemugra rotareti eerht sekat tI .gnitseretni

op owt tsal ehT .reniatnoc gnikovni eht nihtiw rucco ecneuqes eht fo gnidne dna gninnigeb eht ot tni

.detresni eb ot

Page 165: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 261

rotceV a ni stcejbO ssalC gnirotS

tliub eht fo stcejbo derots ylno evah selpmaxe gnidecerp eht hguohtlA - ,rotcev a ni sepyt ni rotcev s

ejbo fo epyt yna erots nac yehT .siht ot detimil ton era .etaerc uoy taht sessalc fo esoht gnidulcni ,stc

a sesu taht elpmaxe na si ereH rotcev a rof shgih erutarepmet yliad eht dloh taht stcejbo erots ot

taht ecitoN .keew pmeTyliaD dna < fo snoisrev dedaolrevo taht dna rotcurtsnoc tluafed eht senifed

orp era == rehto ,LTS eht stnemelpmi relipmoc ruoy woh nopu gnidneped ,rebmemeR .dediv

.denifed eb ot deen yam srotarepo nosirapmoc

.rotcev a ni tcejbo ssalc a erotS //

>maertsoi< edulcni#

>rotcev< edulcni#

>bildtsc< edulcni#

;dts ecapseman gnisu

{ pmeTyliaD ssalc

i ;pmet tn

:cilbup

} ;0 = pmet { )(pmeTyliaD

} ;x = pmet { )x tni(pmeTyliaD

{ )x tni(=rotarepo& pmeTyliaD

;siht* nruter ;x = pmet

}

} ;pmet nruter { )(pmet_teg elbuod

;}

)b pmeTyliaD ,a pmeTyliaD(<rotarepo loob

{

;)(pmet_teg.b < )(pmet_teg.a nruter

}

po loob )b pmeTyliaD ,a pmeTyliaD(==rotare

{

Page 166: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 361

;)(pmet_teg.b == )(pmet_teg.a nruter

}

)(niam tni

{

;v >pmeTyliaD<rotcev

;i tni

)++i ;7<i ;0=i(rof

;))03%)(dnar + 06(pmeTyliaD(kcab_hsup.v

:serutarepmet tiehneraF" << tuoc \ ;"n

)++i ;)(ezis.v<i ;0=i(rof

_teg.]i[v << tuoc ;" " << )(pmet

;ldne << tuoc

edargitneC ot tiehneraF morf trevnoc //

)++i ;)(ezis.v<i ;0=i(rof

)(pmet_teg.]i[v( = ]i[v - ; 9/5 * )23

:serutarepmet edargitneC" << tuoc \ ;"n

)++i ;)(ezis.v<i ;0=i(rof

;" " << )(pmet_teg.]i[v << tuoc

;0 nruter

}

morf tuptuo ehT :ereh nwohs si margorp siht

:serutarepmet tiehneraF

87 46 98 07 46 77 17

:serutarepmet edargitneC

52 71 13 12 71 52 12

,suhT .syarra lamron naht tneiciffe ssel era yeht tub ,ytilibixelf dna ,ytefas ,rewop taerg reffo srotceV

n ,sksat gnimmargorp tsom rof ni snoitautis rof hctaw tuB .eciohc tsrif ruoy eb llits lliw syarra lamro

a gnisu fo stifeneb eht hcihw rotcev .stsoc sti hgiewtuo

Page 167: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 461

stsiL

ehT tsil a ,ssecca modnar stroppus hcihw ,rotcev a ekilnU .tsil raenil ,lanoitceridib a stroppus ssalc

ca eb nac tsil ot tnorf dessecca eb yam yeht ,lanoitceridib era stsil ecniS .ylno yllaitneuqes dessec

.tnorf ot kcab ro kcab

A tsil :noitacificeps etalpmet siht sah

tsil ssalc >>T<rotacolla = rotacollA ssalc ,T ssalc< etalpmet

,ereH T eht ni derots atad fo epyt eht si yb deificeps si rotacolla ehT .tsil rotacollA stluafed hcihw ,

:srotcurtsnoc gniwollof eht sah tI .rotacolla dradnats eht ot

& rotacollA tsnoc(tsil ticilpxe a ;) ) (rotacollA =

epyt_ezis(tsil ticilpxe mun & T tsnoc , lav ,) ( T =

& rotacollA tsnoc a tacollA = ;)) (ro

& >rotacollA ,T<tsil tsnoc(tsil bo ;)

retInI(tsil>retInI ssalc< etalpmet trats retInI , dne ,

& rotacollA tsnoc a ;)) (rotacollA =

sah taht tsil a stcurtsnoc mrof dnoces ehT .tsil ytpme na stcurtsnoc mrof tsrif ehT mun stnemele

eulav eht htiw lav cihw , stcurtsnoc mrof driht ehT .tluafed ot dewolla eb nac h eht sniatnoc taht tsil a

sa stnemele emas bo taht tsil a stcurtsnoc mrof htruof ehT . egnar eht ni stnemele eht sniatnoc

srotareti eht yb deificeps trats dna dne .

era srotarepo nosirapmoc gniwollof ehT rof denifed tsil :

=> ,> ,=! ,=< ,< ,==

Page 168: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 561

desu ylnommoc eht fo emoS tsil stnemele ,srotcev ekiL .2.8 elbaT ni nwohs era snoitcnuf rebmem

eht gnisu yb tsil a otni tup eb yam )(kcab_hsup .noitcnuf nac uoY

rebmeM noitpircseD

;) (kcab ecnerefer teR ni tnemele tsal eht ot ecnerefer a snru

;tsnoc ) (kcab ecnerefer_tsnoc .tsil eht

;) (nigeb rotareti tnemele tsrif eht ot rotareti na snruteR

ni

;tsnoc ) (nigeb rotareti_tsnoc .tsil eht

;) (raelc diov .tsil eht morf stnemele lla sevomeR

;tsnoc ) (ytpme loob ytpme si tsil gnikovni eht fi eurt snruteR

.esiwrehto eslaf dna

;) (dne rotareti .tsil eht fo dne eht ot rotareti na snruteR

;tsnoc ) (dne rotareti_tsnoc

rotareti(esare rotareti i ;) yb ot detniop tnemele eht sevomeR i.

retfa tnemele eht ot rotareti na snruteR

.devomer eno eht

rotareti(esare rotareti trats rotareti , dne ;) egnar eht ni stnemele eht sevomeR trats

ot dne tnemele eht ot rotareti na snruteR .

.devomer tnemele tsal eht retfa

;) (tnorf ecnerefer snruteR ni tnemele tsrif eht ot ecnerefer a

;tsnoc ) (tnorf ecnerefer_tsnoc .tsil eht

rotareti(tresni rotareti i,

Page 169: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 661

& T tsnoc lav ;)

stresnI lav eht erofeb yletaidemmi

yb deificeps tnemele .i eht ot rotareti nA

.denruter si tnemele

rotareti(tresni diov i pyt_ezis , e mun ,

& T tsnoc lav )

stresnI mun fo seipoc lav yletaidemmi

yb deificeps tnemele eht erofeb i.

>retInI ssalc< etalpmet

rotareti(tresni diov i,

retInI trats retInI , dne ;)

yb denifed ecneuqes eht stresnI trats dna

dne tnemele eht erofeb yletaidemmi

deificeps yb i.

& >rotacollA ,T<tsil(egrem diov bo ;)

>pmoC ssalc< etalpmet

& >rotacollA ,T<tsil<(egrem diov bo ,

pmoC nfpmc ;)

ni deniatnoc tsil deredro eht segreM bo

tluser ehT .tsil gnikovni deredro eht htiw

tsil eht ,egrem eht retfA .deredro si

ni deniatnoc bo pme si dnoces eht nI .yt

eb nac noitcnuf nosirapmoc a ,mrof

eno nehw senimreted taht deificeps

.rehtona naht ssel si tnemele

.tsil eht ni tnemele tsal eht sevomeR ;) (kcab_pop diov

.tsil eht ni tnemele tsrif eht sevomeR ;) (tnorf_pop diov

& T tsnoc(kcab_hsup diov lav deificeps eulav eht htiw tnemele na sddA ;)

yb lav .tsil eht fo dne eht ot

& T tsnoc(tnorf_hsup diov lav deificeps eulav eht htiw tnemele na sddA ;)

yb lav .tsil eht fo tnorf eht ot

Page 170: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 761

& T tsnoc(evomer diov lav eulav eht htiw stnemele sevomeR ;) lav morf

l eht .tsi

.tsil gnikovni eht sesreveR ;) (esrever diov

yltnerruc stnemele fo rebmun eht snruteR ;tsnoc ) (ezis epyt_ezis

.tsil eht ni

;) (tros diov

>pmoC ssalc< etalpmet

pmoC(tros diov nfpmc ;)

eht stros mrof dnoces ehT .tsil eht stroS

nosirapmoc eht gnisu tsil noitcnuf nf ot

naht ssel si tnemele eno nehw enimreted

.rehtona

rotareti(ecilps diov i,

& >rotacollA ,T<tsil bo ;)

fo stnetnoc ehT bo eht otni detresni era

yb ot detniop noitacol eht ta tsil gnikovni

i ,noitarepo eht retfA . bo .ytpme si

rotareti(ecilps diov i,

& >rotacollA ,T<tsil bo ,

rotareti le ;)

yb ot detniop tnemele ehT le devomer si

tsil eht morf bo gnikovni eht ni derots dna

yb ot detniop noitacol eht ta tsil i.

rotareti(ecilps diov i,

& >rotacollA ,T<tsil bo ,

rotareti trats rotareti , dne ;)

ifed egnar ehT yb den trats dna dne si

morf devomer bo eht ni derots dna

noitacol eht ta gninnigeb tsil gnikovni

yb ot detniop i.

snoitcnuF rebmeM tsil desU ylnommoC emoS .2.8 elbaT

Page 171: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 861

gnisu yb tsil eht fo tnorf eht no stnemele tup )(tnorf_hsup eb osla nac tnemele nA .

sni gnisu yb tsil a fo elddim eht otni detre )(tresni gnisu denioj eb yam stsil owT .

)(ecilps gnisu rehtona otni degrem eb yam tsil enO . )(egrem .

tsum tI .rotcurtsnoc tluafed a enifed tsum tsil a ni dleh eb lliw taht epyt atad ynA

oc suoirav eht enifed osla esicerp eht ,gnitirw siht fo emit eht tA .srotarepo nosirapm

,relipmoc ot relipmoc morf yrav tsil a ni derots eb lliw taht tcejbo na rof stnemeriuqer

.noitatnemucod s'relipmoc ruoy kcehc ot deen lliw uoy os

a fo elpmaxe elpmis a si ereH tsil .

cisab tsiL // .s

>maertsoi< edulcni#

>tsil< edulcni#

;dts ecapseman gnisu

)(niam tni

{

tsil ytpme na etaerc // ;tsl >tni<tsil

;i tni

;)i(kcab_hsup.tsl )++i ;01<i ;0=i(rof

;ldne << )(ezis.tsl << " = eziS" << tuoc

;" :stnetnoC" << tuoc

;)(nigeb.tsl = p rotareti::>tni<tsil

{ ))(dne.tsl =! p(elihw

;" " << p* << tuoc

;++p

}

" << tuoc \n\ ;"n

tsil fo stnetnoc egnahc //

;)(nigeb.tsl = p

{ ))(dne.tsl =! p(elihw

;001 + p* = p*

;++p

Page 172: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 961

}

;" :deifidom stnetnoC" << tuoc

;)(nigeb.tsl = p

{ ))(dne.tsl =! p(elihw

;" " << p* << tuoc

;++p

}

r ;0 nrute

}

:ereh nwohs si margorp siht yb decudorp tuptuo ehT

01 = eziS

9 8 7 6 5 4 3 2 1 0 :stnetnoC

901 801 701 601 501 401 301 201 101 001 :deifidom stnetnoC

ytpme na ,tsriF .sregetni fo tsil a setaerc margorp sihT tsil 01 ,txeN .detaerc si tcejbo

getni eht gnisu dehsilpmocca si sihT .tsil eht otni tup era sre )(kcab_hsup ,noitcnuf

dna tsil eht fo ezis eht ,txeN .tsil gnitsixe eht fo dne eht no eulav wen hcae stup hcihw

iwollof eht gnisu ,rotareti na aiv deyalpsid si tsil ehT .deyalpsid si flesti tsil eht :edoc gn

;)(nigeb.tsl = p rotareti::>tni<tsil

{ ))(dne.tsl =! p(elihw

;" " << p* << tuoc

;++p

}

rotareti eht ,ereH p eht hguorht emit hcaE .tsil eht fo trats eht ot tniop ot dezilaitini si

,pool p T .tnemele txen eht ot tniop ot ti gnisuac ,detnemercni si nehw sdne pool eh p

elcyc ot desu saw sa emas eht yllaitnesse si edoc sihT .tsil eht fo dne eht ot stniop

eht dna ,edoc LTS ni nommoc era siht ekil spooL .rotareti na gnisu rotcev a hguorht

epyt tnereffid ssecca ot desu eb nac stcurtsnoc emas eht taht tcaf trap si sreniatnoc fo s

.LTS eht fo rewop eht fo

) (dne gnidnatsrednU

Page 173: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 071

eht fo etubirtta detcepxenu tahwemos a ezisahpme ot emit doog a si woN )(dne

.noitcnuf reniatnoc )(dne .reniatnoc a ni tnemele tsal eht ot retniop a nruter ton seod

snruter ti ,daetsnI retniop a tsap eno a ni tnemele tsal eht ,suhT .tnemele tsal eht

yb ot detniop si reniatnoc )(dne - 1 tneiciffe yrev etirw ot su swolla erutaef sihT .

,eno tsal eht gnidulcni ,reniatnoc a fo stnemele eht fo lla hguorht elcyc taht smhtirogla

tareti na gnisu yb denruter eno eht sa eulav emas eht sah rotareti eht nehW .ro )(dne ,

ni erutaef siht peek tsum uoy ,revewoH .dessecca neeb evah stnemele lla taht wonk ew

gniwollof eht redisnoc ,elpmaxe roF .evitiutniretnuoc tib a mees yam ti ecnis dnim

d hcihw ,margorp .drawkcab dna drawrof tsil a syalpsi

.)(dne gnidnatsrednU //

>maertsoi< edulcni#

>tsil< edulcni#

;dts ecapseman gnisu

)(niam tni

{

tsil ytpme na etaerc // ;tsl >tni<tsil

;i tni

;)i(kcab_hsup.tsl )++i ;01<i ;0=i(rof

:sdrawrof detnirp tsiL" << tuoc \ ;"n

<tsil ;)(nigeb.tsl = p rotareti::>tni

{ ))(dne.tsl =! p(elihw

;" " << p* << tuoc

;++p

}

" << tuoc \n\ ;"n

:sdrawkcab detnirp tsiL" << tuoc \ ;"n

;)(dne.tsl = p

{ ))(nigeb.tsl =! p(elihw

p -- gnisu erofeb retniop tnemerced // ;

;" " << p* << tuoc

Page 174: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 171

}

;0 nruter

}

ptuo ehT :ereh nwohs si margorp siht yb decudorp tu

:sdrawrof detnirp tsiL

9 8 7 6 5 4 3 2 1 0

:sdrawkcab detnirp tsiL

0 1 2 3 4 5 6 7 8 9

neeb evah ew sa emas eht si noitcerid drawrof eht ni tsil eht syalpsid taht edoc ehT

c eht ot noitnetta laiceps yap tuB .gnisu ehT .redro esrever ni tsil eht syalpsid taht edo

rotareti p eht fo esu eht hguorht tsil eht fo dne eht ot tes yllaitini si )(dne .noitcnuf

ecniS )(dne yllautca tcejbo tsal eht tsap eno si taht tcejbo na ot rotareti na snruter

,tsil eht ni derots p eb tsum yhw si sihT .desu si ti erofeb detnemerced p detnemerced si

eht erofeb tuoc :rebmemeR .retfa naht rehtar ,pool eht edisni tnemetats )(dne ton seod

tsal eht tsap eno si taht retniop a snruter ti ;tsil eht ni tcejbo tsal eht ot retniop a nruter

eht ni eulav .tsil

) (kcab_hsup sv ) (tnorf_hsup

,raf oS .tsil eht fo trats eht ro dne eht rehtie ot stnemele gnidda yb tsil a dliub nac uoY

gnisu yb dne eht ot stnemele gnidda neeb evah ew )(kcab_hsup ot stnemele dda oT .

esu ,trats eht )(tnorf_hsup ,elpmaxe roF .

/ neewteb ecnereffid eht gnitartsnomeD *

/* .)(tnorf_hsup dna )(kcab_hsup

>maertsoi< edulcni#

>tsil< edulcni#

;dts ecapseman gnisu

)(niam tni

{

;2tsl ,1tsl >tni<tsil

;i tni

Page 175: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 271

;)i(kcab_hsup.1tsl )++i ;01<i ;0=i(rof

;)i(tnorf_hsup.2tsl )++i ;01<i ;0=i(rof

i<tsil ;p rotareti::>tn

:1tsl fo stnetnoC" << tuoc \ ;"n

;)(nigeb.1tsl = p

{ ))(dne.1tsl =! p(elihw

;" " << p* << tuoc

;++p

}

" << tuoc \n\ ;"n

:2tsl fo stnetnoC" << tuoc \ ;"n

;)(nigeb.2tsl = p

{ ))(dne.2tsl =! p(elihw

;" " << p* << tuoc

;++p

}

;0 nruter

}

tuptuo ehT :ereh nwohs si margorp siht yb decudorp

:1tsl fo stnetnoC

9 8 7 6 5 4 3 2 1 0

:2tsl fo stnetnoC

0 1 2 3 4 5 6 7 8 9

ecniS 2tsl esrever eht ni si tsil gnitluser eht ,tnorf sti otno stnemele gnittup yb tliub si

fo redro 1tsl nemele gnittup yb tliub si hcihw , .dne sti otno st

tsiL a troS

eht gnillac yb detros eb yam tsil A )(tros margorp gniwollof ehT .noitcnuf rebmem

.redro detros otni tsil eht stup neht dna sregetni modnar fo tsil a setaerc

.tsil a troS //

Page 176: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 371

>maertsoi< edulcni#

>tsil< edulcni#

ldtsc< edulcni# >bi

;dts ecapseman gnisu

)(niam tni

{

;tsl >tni<tsil

;i tni

sregetni modnar fo tsil a etaerc //

)++i ;01<i ;0=i(rof

;))(dnar(kcab_hsup.tsl

:stnetnoc lanigirO" << tuoc \ ;"n

;)(nigeb.tsl = p rotareti::>tni<tsil

{ ))(dne.tsl =! p(elihw

;" " << p* << tuoc

;++p

}

;ldne << ldne << tuoc

tsil eht tros //

;)(tros.tsl

:stnetnoc detroS" << tuoc \ ;"n

;)(nigeb.tsl = p

{ ))(dne.tsl =! p(elihw

;" " << p* << tuoc

;++p

}

;0 nruter

}

:margorp eht yb decudorp tuptuo elpmas si ereH

:stnetnoc lanigirO

51 96191 00562 4336 76481 14 46442 26962 85392 87411 427

Page 177: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 471

:stnetnoc detroS

85392 26962 00562 46442 96191 76481 42751 87411 4336 14

rehtonA htiw tsiL enO gnigreM

taht tsil deredro na si tluser ehT .rehtona htiw degrem eb yam tsil deredro enO

l lanigiro owt eht fo stnetnoc eht sniatnoc ,tsil gnikovni eht ni tfel si tsil wen ehT .stsi

sniatnoc tsrif ehT .stsil owt segrem elpmaxe txen ehT .ytpme tfel si tsil dnoces eht dna

stsil esehT .srebmun ddo eht sniatnoc dnoces ehT .9 dna 0 neewteb srebmun neve eht

uqes eht ecudorp ot degrem neht era .9 8 7 6 5 4 3 2 1 0 ecne

.stsil owt egreM //

>maertsoi< edulcni#

>tsil< edulcni#

;dts ecapseman gnisu

)(niam tni

{

;2tsl ,1tsl >tni<tsil

;i tni

;)i(kcab_hsup.1tsl )2=+i ;01<i ;0=i(rof

;)i(kcab_hsup.2tsl )2=+i ;11<i ;1=i(rof

:1tsl fo stnetnoC" << tuoc \ ;"n

;)(nigeb.1tsl = p rotareti::>tni<tsil

{ ))(dne.1tsl =! p(elihw

;" " << p* << tuoc

;++p

}

;ldne << ldne << tuoc

:2tsl fo stnetnoC" << tuoc \ ;"n

;)(nigeb.2tsl = p

{ ))(dne.2tsl =! p(elihw

;" " << p* << tuoc

Page 178: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 571

;++p

}

;ldne << ldne << tuoc

l owt eht egrem ,won // stsi

;)2tsl(egrem.1tsl

))(ytpme.2tsl(fi

ytpme won si 2tsl" << tuoc \ ;"n

:egrem retfa 1tsl fo stnetnoC" << tuoc \ ;"n

;)(nigeb.1tsl = p

{ ))(dne.1tsl =! p(elihw

;" " << p* << tuoc

;++p

}

;0 nruter

}

:ereh nwohs si margorp siht yb decudorp tuptuo ehT

o stnetnoC :1tsl f

8 6 4 2 0

:2tsl fo stnetnoC

9 7 5 3 1

e c n e r e f e R e t e l p m o C e h T : + + C 056

ytpme won si 2tsl

:egrem retfa 1tsl fo stnetnoC

9 8 7 6 5 4 3 2 1 0

eht fo esu eht si elpmaxe siht tuoba eciton ot gniht rehto enO )(ytpme tI .noitcnuf

ruter ecniS .ytpme si reniatnoc gnikovni eht fi eurt sn )(egrem eht fo lla sevomer

sa ,detelpmoc si egrem eht retfa ytpme eb lliw ti ,degrem gnieb tsil eht morf stnemele

.smrifnoc tuptuo margorp eht

tsiL a ni stcejbO ssalC gnirotS

Page 179: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 671

sesu taht elpmaxe na si ereH epyt fo stcejbo erots ot tsil a ssalcym ,> ,< eht taht ecitoN .

epyt fo stcejbo rof dedaolrevo era == dna ,=! ssalcym taht srotarepo eht era esehT .

ni selpmaxe LTS eht tset ot desu relipmoc eht( ++C lausiV s'tfosorciM yb deriuqer erew

c rehtO ).retpahc siht eseht sesu LTS ehT .seno lanoitidda eriuqer yam srelipmo

hguoht nevE .reniatnoc a ni stcejbo fo ytilauqe dna gniredro eht enimreted ot snoitcnuf

nehw stnemele erapmoc ot yaw a sdeen llits ti ,reniatnoc deredro na ton si tsil a

nigrem ro ,gnitros ,gnihcraes .g

.tsil a ni stcejbo ssalc erotS //

>maertsoi< edulcni#

>tsil< edulcni#

>gnirtsc< edulcni#

;dts ecapseman gnisu

{ ssalcym ssalc

;b ,a tni

;mus tni

:cilbup

} ;0 = b = a { )(ssalcym

{ )j tni ,i tni(ssalcym

;i = a

;j = b

;b + a = mus

}

nruter { )(musteg tni } ;mus

,1o& ssalcym tsnoc(<rotarepo loob dneirf

;)2o& ssalcym tsnoc

,1o& ssalcym tsnoc(>rotarepo loob dneirf

;)2o& ssalcym tsnoc

,1o& ssalcym tsnoc(==rotarepo loob dneirf

;)2o& ssalcym tsnoc

,1o& ssalcym tsnoc(=!rotarepo loob dneirf

Page 180: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 771

;)2o& ssalcym tsnoc

;}

)2o& ssalcym tsnoc ,1o& ssalcym tsnoc(<rotarepo loob

{

;mus.2o < mus.1o nruter

}

)2o& ssalcym tsnoc ,1o& ssalcym tsnoc(>rotarepo loob

{

;mus.2o > mus.1o nruter

}

)2o& ssalcym tsnoc ,1o& ssalcym tsnoc(==rotarepo loob

{

;mus.2o == mus.1o nruter

}

tarepo loob )2o& ssalcym tsnoc ,1o& ssalcym tsnoc(=!ro

{

;mus.2o =! mus.1o nruter

}

)(niam tni

{

;i tni

tsil tsrif etaerc //

;1tsl >ssalcym<tsil

;))i ,i(ssalcym(kcab_hsup.1tsl )++i ;01<i ;0=i(rof

;" :tsil tsriF" << tuoc

;)(nigeb.1tsl = p rotareti::>ssalcym<tsil

(elihw { ))(dne.1tsl =! p

p << tuoc - ;" " << )(musteg>

;++p

}

;ldne << tuoc

Page 181: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 871

tsil dnoces a etaerc //

;2tsl >ssalcym<tsil

;))3*i ,2*i(ssalcym(kcab_hsup.2tsl )++i ;01<i ;0=i(rof

;" :tsil dnoceS" << tuoc

;)(nigeb.2tsl = p

{ ))(dne.2tsl =! p(elihw

p << tuoc - < )(musteg> ;" " <

;++p

}

;ldne << tuoc

2tsl dna 1tsl tegrem ,won //

;)2tsl(egrem.1tsl

tsil degrem yalpsid //

;" :tsil degreM" << tuoc

;)(nigeb.1tsl = p

{ ))(dne.1tsl =! p(elihw

p << tuoc - ;" " << )(musteg>

;++p

}

;0 nruter

}

fo stsil owt setaerc margorp ehT ssalcym bo hcae fo stnetnoc eht syalpsid dna stcej

margorp siht morf tuptuo ehT .tluser eht syalpsid dna stsil owt eht segrem neht tI .tsil

:ereh nwohs si

81 61 41 21 01 8 6 4 2 0 :tsil tsriF

54 04 53 03 52 02 51 01 5 0 :tsil dnoceS

1 01 01 8 6 5 4 2 0 0 :tsil degreM 54 04 53 03 52 02 81 61 51 41 2

spaM

ehT pam deppam era syek euqinu hcihw ni reniatnoc evitaicossa na stroppus ssalc

Page 182: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 971

eulav a ecnO .eulav a ot evig uoy taht eman a ylpmis si yek a ,ecnesse nI .seulav htiw

sti gnisu yb ti eveirter nac uoy ,derots neeb sah a ,esnes lareneg tsom sti ni ,suhT .yek

eulav a pu kool nac uoy taht si pam a fo rewop ehT .sriap eulav/yek fo tsil a si pam

yek sti sa eman s'nosrep a sesu taht pam a enifed dluoc uoy ,elpmaxe roF .yek sti nevig

a rebmun enohpelet s'nosrep taht serots dna era sreniatnoc evitaicossA .eulav sti s

.gnimmargorp ni ralupop erom gnimoceb

.dewolla ton era syek etacilpuD .syek euqinu ylno dloh nac pam a ,denoitnem sA

esu ,syek euqinunon swolla taht pam a etaerc oT pamitlum .

ehT pam lpmet gniwollof eht sah reniatnoc :noitacificeps eta

,>yeK<ssel = pmoC ssalc ,T ssalc ,yeK ssalc< etalpmet

pam ssalc >>T<rotacolla = rotacollA ssalc

,ereH yeK ,syek eht fo epyt atad eht si T derots gnieb seulav eht fo epyt atad eht si

dna ,)deppam( pmoC syek owt serapmoc taht noitcnuf a si eht ot stluafed sihT .

dradnats )(ssel .tcejbo noitcnuf ytilitu rotacollA ot stluafed hcihw( rotacolla eht si

rotacolla . )

A pam :srotcurtsnoc gniwollof eht sah

& pmoC tsnoc(pam ticilpxe nfpmc ,) (pmoC =

& rotacollA tsnoc a ;) ) (rotacollA =

eK<pam tsnoc(pam & >rotacollA ,pmoC ,T ,y bo ;)

retInI(pam >retInI ssalc< etalpmet trats retInI , dne ,

& pmoC tsnoc nfpmc & rotacollA tsnoc ,) (pmoC = a ;)) (rotacollA =

taht pam a stcurtsnoc mrof dnoces ehT .pam ytpme na stcurtsnoc mrof tsrif ehT

sa stnemele emas eht sniatnoc bo eht sniatnoc taht pam a stcurtsnoc mrof driht ehT .

srotareti eht yb deificeps egnar eht ni stnemele trats dna dne yb deificeps noitcnuf ehT .

,nfpmc .pam eht fo gniredro eht senimreted ,tneserp fi

luafed a enifed tsum yek a sa desu tcejbo yna ,lareneg nI daolrevo dna rotcurtsnoc t

.srotarepo nosirapmoc yrassecen yna

rof denifed era srotarepo nosirapmoc gniwollof ehT pam .

=> ,> ,=! ,=< ,< ,==

eht fo lareveS pam 42 elbaT ni nwohs era snoitcnuf rebmem - ,snoitpircsed eht nI .4

epyt_yek a ,yek eht fo epyt eht si dn epyt_eulav stneserper >T ,yeK<riap .

Page 183: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 081

noitpircseD rebmeM

;) (nigeb rotareti

;tsnoc ) (nigeb rotareti_tsnoc

tnemele tsrif eht ot rotareti na snruteR

.pam eht ni

.pam eht morf stnemele lla sevomeR ;) (raelc diov

& epyt_yek tsnoc(tnuoc epyt_ezis k teR ;tsnoc ) semit fo rebmun eht snru k srucco

.)orez ro 1( pam eht ni

si pam gnikovni eht fi eurt snruteR ;tsnoc ) (ytpme loob

.esiwrehto eslaf dna ytpme

;) (dne rotareti

;tsnoc ) (dne rotareti_tsnoc

fo dne eht ot rotareti na snruteR

.tsil eht

rotareti(esare diov i ;) yb ot detniop tnemele eht sevomeR i.

rotareti(esare diov trats rotareti , dne egnar eht ni stnemele eht sevomeR ;)

trats ot dne .

& epyt_yek tsnoc(esare epyt_ezis k taht stnemele pam eht morf sevomeR )

eulav eht htiw syek evah k.

& epyt_yek tsnoc(dnif rotareti k ;)

& epyt_yek tsnoc(dnif rotareti_tsnoc k)

;tsnoc

deificeps eht ot rotareti na snruteR

na neht ,dnuof ton si yek eht fI .yek

si pam eht fo dne eht ot rotareti

.denruter

rotareti(tresni rotareti i,

& epyt_eulav tsnoc lav ;)

stresnI lav tnemele eht retfa ro ta

yb deificeps .i eht ot rotareti nA

.denruter si tnemele

Page 184: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 181

>retInI ssalc< etalpmet

retInI(tresni diov trats retInI , dne )

.stnemele fo egnar a stresnI

>loob ,rotareti<riap

& epyt_eulav tsnoc(tresni lav ;)

stresnI lav nA .pam gnikovni eht otni

ele eht ot rotareti ehT .denruter si tnem

ton seod ti fi ylno detresni si tnemele

saw tnemele eht fI .tsixe ydaerla

si >eurt ,rotareti<riap ,detresni

,rotareti<riap ,esiwrehtO .denruter

.denruter si >eslaf

42 elbaT - snoitcnuF rebmeM pam desU ylnommoC lareveS .4

sriap eulav/yeK epyt fo stcejbo sa pam a ni derots era riap siht sah hcihw ,

.noitacificeps etalpmet

{ riap tcurts >epytV ssalc ,epytK ssalc< etalpmet

yek fo epyt // ;epyt_tsrif epytK fedepyt

eulav fo epyt // ;epyt_dnoces epytV fedepyt

yek eht sniatnoc // ;tsrif epytK

ytV eulav eht sniatnoc // ;dnoces ep

srotcurtsnoc //

;)(riap

;)v& epytV tsnoc ,k& epytK tsnoc(riap

;)bo& >B ,A<tsnoc(riap >B ssalc ,A ssalc<etalpmet

}

ni eulav eht ,tseggus stnemmoc eht sA tsrif ni eulav eht dna yek eht sniatnoc dnoces

cossa eulav eht sniatnoc .yek taht htiw detai

fo eno rehtie gnisu riap a tcurtsnoc nac uoY riap gnisu yb ro srotcurtsnoc s'

)(riap_ekam a stcurtsnoc hcihw , riap sa desu atad eht fo sepyt eht nopu desab tcejbo

.sretemarap )(riap_ekam .epytotorp siht sah taht noitcnuf cireneg a si

t ssalc< etalpme epytK ssalc , epytV >

Page 185: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 281

<riap epytK , epytV tsnoc(riap_ekam > epytK &k tsnoc , epytV &v ;)

yb deificeps sepyt eht fo seulav fo gnitsisnoc tcejbo riap a snruter ti ,ees nac uoy sA

epytK dna epytV fo egatnavda ehT . )(riap_ekam eht fo sepyt eht taht si gnieb stcejbo

noitpircseD rebmeM

& epyt_yek tsnoc(] [rotarepo ecnerefer i tnemele eht ot ecnerefer a snruteR )

yb deificeps i ton seod tnemele siht fI .

.detresni si ti ,tsixe

stnemele fo rebmun eht snruteR ;tsnoc ) (ezis epyt_ezis

.tsil eht ni yltnerruc

lbaT 42 e - )deunitnoc( snoitcnuF rebmeM pam desU ylnommoC lareveS .4

ylticilpxe gnieb naht rehtar relipmoc eht yb yllacitamotua denimreted era derots

.uoy yb deificeps

eulav/yek serots tI .pam a gnisu fo scisab eht setartsulli margorp gniwollof ehT

hs taht sriap retcarahc IICSA rieht dna srettel esacreppu eht neewteb gnippam eht wo

sriap eulav/yek ehT .regetni na si eulav eht dna retcarahc a si yek eht ,suhT .sedoc

era derots

56 A

66B

76 C

e.i( yek a rof detpmorp era uoy ,derots neeb evah sriap eht ecnO .no os dna rettel a ,.

.deyalpsid si rettel taht rof edoc IICSA eht dna ,)Z dna A neewteb

.noitartsnomed pam elpmis A //

>maertsoi< edulcni#

>pam< edulcni#

;dts ecapseman gnisu

)(niam tni

{

;m >tni ,rahc<pam

;i tni

pam otni sriap tup //

{ )++i ;62<i ;0=i(rof

Page 186: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 381

tresni.m ;))i+56 ,i+'A'(>tni ,rahc<riap(

}

;hc rahc

;" :yek retnE" << tuoc

;hc >> nic

;p rotareti::>tni ,rahc<pam

yek nevig eulav dnif //

;)hc(dnif.m = p

))(dne.m =! p(fi

p << " si eulav IICSA stI" << tuoc - ;dnoces>

esle

.pam ni ton yeK" << tuoc \ ;"n

2 r e t p a h C 756 y r a r b i L e t a l p m e T d r a d n a t S e h t g n i c u d o r t n I : 4

;0 nruter

}

eht fo esu eht ecitoN riap atad ehT .sriap eulav/yek eht tcurtsnoc ot ssalc etalpmet

yb deificeps sepyt riap eht fo esoht hctam tsum pam era sriap eht hcihw otni gnieb

.detresni

eulav a rof hcraes nac uoy ,seulav dna syek htiw dezilaitini neeb sah pam eht ecnO

eht gnisu yb yek sti nevig )(dnif .noitcnuf )(dnif gnihctam eht ot rotareti na snruter

hctam a nehW .dnuof ton si yek eht fi pam eht fo dne eht ot ro tnemele eht ,dnuof si

eht ni deniatnoc si yek eht htiw detaicossa eulav dnoces fo rebmem riap .

gnisu ,ylticilpxe detcurtsnoc erew sriap eulav/yek ,elpmaxe gnidecerp eht nI

>tni ,rahc<riap ot reisae netfo si ti ,hcaorppa siht htiw gnorw gnihton si ereht elihW .

esu )(riap_ekam desu atad eht fo sepyt eht nopu desab tcejbo riap a stcurtsnoc hcihw ,

osla lliw edoc fo enil siht ,margorp suoiverp eht gnimussa ,elpmaxe roF .sretemarap sa

otni sriap eulav/yek tresni m.

;))i+56 ,)i+'A'()rahc((riap_ekam(tresni.m

ac eht ,ereH ot ts rahc ot noisrevnoc citamotua eht edirrevo ot dedeen si tni nehw i si

.citamotua si noitanimreted epyt eht ,esiwrehtO '.A' ot dedda

Page 187: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 481

paM a nI stcejbO ssalC gnirotS

uoy taht sepyt fo stcejbo erots ot pam a esu nac uoy ,sreniatnoc eht fo lla htiw sA

rc ti ,si tahT .yrotcerid enohp elpmis a setaerc margorp txen eht ,elpmaxe roF .etae

dellac sessalc owt setaerc ti ,siht od oT .srebmun rieht htiw seman fo pam a setaerc

eman dna rebmun osla margorp eht ,syek fo tsil detros a sniatniam pam a ecniS .

ht senifed e < epyt fo stcejbo rof rotarepo eman eht enifed tsum uoy ,lareneg nI . <

taht eriuqer yam srelipmoc emoS( .yek eht sa esu lliw uoy taht sessalc yna rof rotarepo

).denifed eb srotarepo nosirapmoc lanoitidda

.yrotcerid enohp a etaerc ot pam a esU //

edulcni# >maertsoi<

>pam< edulcni#

>gnirtsc< edulcni#

;dts ecapseman gnisu

{ eman ssalc

;]04[rts rahc

:cilbup

} ;)"" ,rts(ypcrts { )(eman

} ;)s ,rts(ypcrts { )s* rahc(eman

} ;rts nruter { )(teg* rahc

;}

.stcejbo eman ot evitaler naht ssel enifed tsuM //

arepo loob )b eman ,a eman(<rot

{

;0 < ))(teg.b ,)(teg.a(pmcrts nruter

}

{ muNenohp ssalc

;]08[rts rahc

:cilbup

} ;)"" ,rts(pmcrts { )(muNenohp

} ;)s ,rts(ypcrts { )s* rahc(muNenohp

Page 188: CSE-III-OBJECT ORIENTED PROGRAMMING WITH C++ [10CS36]-NOTES_2.pdf

++C htiw gnimmargorP detneirO tcejbO 63SC01

TIBJS ,ESI fo .tpeD egaP 581

} ;rts nruter { )(teg* rahc

;}

)(niam tni

{

;yrotcerid >muNenohp ,eman<pam

man tup // pam otni srebmun dna se

,)"moT"(eman(>muNenohp ,eman<riap(tresni.yrotcerid

555"(muNenohp - ;)))"3354

,)"sirhC"(eman(>muNenohp ,eman<riap(tresni.yrotcerid

555"(muNenohp - ;)))"8769

,)"nhoJ"(eman(>muNenohp ,eman<riap(tresni.yrotcerid

555"(muNenohp - ;)))"5918

erid ,)"lehcaR"(eman(>muNenohp ,eman<riap(tresni.yrotc

555"(muNenohp - ;)))"9080

rebmun dnif ,eman a nevig //

;]08[rts rahc

;" :eman retnE" << tuoc

;rts >> nic

;p rotareti::>muNenohp ,eman<pam

;))rts(eman(dnif.yrotcerid = p

))(dne.yrotcerid =! p(fi

enohP" << tuoc p << " :rebmun - ;)(teg.dnoces>

esle

.yrotcerid ni ton emaN" << tuoc \ ;"n

;0 nruter

}

:nur elpmas a si ereH

lehcaR :eman retnE

555 :rebmun enohP - .9080

llun a sdloh taht yarra retcarahc a si pam eht ni yrtne hcae ,margorp eht nI - retaL .gnirts detanimret

ht ni dradnats eht sesu taht margorp siht etirw ot yaw reisae na ees lliw uoy ,retpahc si gnirts .epyt