.

,

N""_iiU "" ;.n(llnilii:i IftIfi_",ilin".fu ,iIo""" ,_ .................... ; !IJIi,lr.b, I II!I- ..... , ............ ~ ~ ~ ... -!!!Il ~ M!II! II! ~M-'" -rlti"1Ii!1! ~!ill!lL!IiIJ ~!iII III'III!WWoiiiI-" n I!II;i 'II-IP. . n~!IiI"-IiIIII~~.

A_~ me we1J.S:ite

htlip.:/:/www. rnIh'oo .. oorWbalaglirusaliny.l'Octp4~

,A-C' 'tfl'!il' wt'tom 01: '~he tag ap~Jil~1 on ~Il" right~h!and !Side, k:!ok; 'for Rrag'l:..Hr [Now afiild dii~ Om ~h$ :S1\l!dt:nt lil"k

I

[ ,I,

[ Wh"fI •• koll '00, on!!O, !'OM' OOlIo, IjIJ)e in jii04l,lllllqllOl A_II NlII'Obwj .

j_

I

I ...

[

Copy rig hted m ateri al

I

t

Ab t th A tb

. _ OU,', ", ,- _e ~"U,"" or'

IE BldliJlpi~F1~, fl!lmu;~,rr V~ Chu.oohl.o.:r, An:no. UlDiv.!mll'o/" CbC'Llillaii!~ is, ~im.MY':M~~ Uni.Q(JJ :PIa'blic Sie:r.vice' OollliilDi.ssl!!JD~ NeW' DeW. He is a: 'teaclu.€'1'~ m.i[U1Hr~ aad OODS1!iltfmit in 'tlhe :6eldE GfIllinfo~liiO'JiJj TecbfioJlogy' arnd M.anagemoot-. ,He .b~lrh an :ME (Ho:ns~ :in Electdt.ail

'lI!i'!'I!IImrnf'c:ri'll1iG __ ..:I ... 'Q'I." D' ~rrn; ~~''CI;t;..~," U"""":""'-"""""","lnD" 4...'"1' 't!'!I,.." In.;i!':.,;,..,.,, T"7 .... ~\ 1T'.,"" 1""'m ....... llo...,..-.~""""'"~

,!I!ll""'ti~.~, L,~_ ,ClJIilU, UJ ,C'J~.II. ".~ ......... ,;.'!"~~, ~lIi!IoI,- ......... ~~, ,M;!l-y...... ',Y;or _IIY""'-'-" ~1I.o,!! !IiI!:' IIJIj, J!. ~~"'~J

:RoO:B~e, His 8reU 01: mtel\est melud:e' OQJec~Orieti~ SiiPiftwue E:ngin~g" Eled.romc 'iJIJi --- 'mlC - - "'":- -'h.fl"io'Ji~, i\K"'r.il9IfUi.-me..1lL'~ lEhasm£!ss ProtiJ8SS R;e;.Qr.I!m'noorilDll' and Llota], If'Iiud:i;l.'V,

;Il;\I~_e~, ~!!;;1~--"",,,,,,,,!!31.!' ~w~ __ O''''U _'.... _ '._ _ _ _ _ _ _ ,CI- , _ ',!:I~' _ _ _ ~ .. J~..\'

'M~II."IrleIl'r)t"

• Pr'Qgrn:mm.ing ln ,OJ,,, 2i~

• PI.'!l~mmIDg in J'llY,a", 3Je

• P.I.",o,gramming in .Alt~S[ C, 'life

• Pr,o,grtlmming in BASiC. ale ., NlJ.lmentt~] Me.th,OdB. ami

.,liiabwty, E~~t~tri~~

, r

t

A ~iitk 'm~l"~ b~ bs, ,aiUith'~, a]~ n1UD~!r' ofM'S~ :piID~'m and several boob" :mSJ ~~t SB1!t.mg bi:iob" ~-D,g. others m.cl!I!UI_e::

Copy rig hted m ateri al

lEN

FOURTHI EDIIIION,

Membf!:r

Unlilll.!i ./l'Uoli.c-. B'urJicl! CoRit/,rj i'.5'S~Dn N~w lklhi

Tata M.cG r,a",r: .. ,HlU Publlsb ing C1omps_ Y' ,LImited NEW'DElJ]

.ew De1lli N,"'W York, 'St louis. San ~:l'lu!td co' A.uek:land Bosotli Caracas K.Jlla~a iLlllnptlf Lisbon l.oooon Mnd'ric:! Me~joo (11'1 Mi Imn MOJ1'nal

San JU!l1lI. S:1lirrlrll3~o Sillg.l:l!pon:: Sydn~'Y TiO-'kya l'Ol1'Onlo

Copyngh sd material

-

.

'Tata MCGli'lliW"HIIi ~

.PlJblisJiOO by Trutl M:d3rn,w~f{m :P>uhl@ltijll_S Co.tliIpilfi.y limited, i' W~t Pilte'~ N':J41:tlr. 'N~w ~1De'JM ~ ~ 0 0TII8,

'iCt'lp'ytlg_ill @ 2008,! lQO!J., 20(!l I. [1)941 .. 'Ii}! 1'illro MI;;ii'Jr,illioil·-MJU ,Pillblis'hlh~~' CC!nLjJ~jjj}' LIundile-l!l

NIJ! .p-3!r:t iJlf [hi~ pU!bl.i'C~~ij(l11l m!l!)f he !ie'pn~tLul;;ed i).ir di:s~ril\li.1~ if! ,!liD), ~fN!T.! iI.1J" hy !.In)! !mf:Qlflfl., ~~l;l;tf'r1'Jjic. lMcll~nbcf!J~. pbrn:oeO])~~l1Ig, r-.e.«ifd:i IJg. !JoT Qtl~.RI,+se 'Of Slioredi im ,31 drunb.;1Ise! !I)J[ Ift'rri~""';l15)'5item witbJ)~t ~ prkrr wrtm.':i~ perm! ssiOnL i(j'f me pouMLcSlte:ro" n~ pnlgr'3m lis.{i.r:Jgs. (if lll'l~) may !!Ie ill..rnefiMl, f.'t{ireCl aJ'Idi ,e~ecm~d: In a I~D'.fi!iIPlll~'" ts;J:'i.te.r;q, bu~ Ilb~y mli~ nu:il. be .li>Cp-tOOItL.€e.d. :fiflir: pldi~[~II!~a!J(riL

FOllll'fih ·t'eprifit~ .2003

D;Ql!cltm!Rl\1IVi;~f3:

Th~s ,e.CIlti..f!fi ean ~e. ~pfi:i't;:d 'froin. I!rndiJll! it!ru~y by IEl:te :~Dli5.Itets,.

; T~~:;! M',p!lrnw~"m Pt!J~n~MIj']' CmTIJJ;,!I!1lj! L .. ~mn.i'I;e.d.

:~S~N I(.~ j dig~~s): 9i~B.J()"Ol-CD:D6:007-9

tS~N (10 di~~t"S): 0-01·-0~1J7..t1

Mlko.agi·ng; Dii'lOCtm: .AJay Sf:rJ~kJjj'

G~IilCU'ai M:m:tgr:f~ ,Pi,;!bl!i!~MIJg=SEM &, 'Tech BdI~ Wb'J~ M"ahajfJJJ Sponsoon,g Editor. rShalJn~ ,Hl~

JIr.. ~pt1f~f.fl~ ~tljl.o~: N;~r:rnJ~ Cha!n:t~}' ~i:rri(lr' Co.,.)' EditDr: ,l)ipik-~. De.'J.~ Se:ni!D!i"IP'riOO[lil:I~Cin ·MMilggr. ,p it P,r~,;tIIr(,l

IGe:D~f.aJ. Ma_n.a:ge:l'~ MaF"f~i:~jng=-Hiigb~.!i' Edl~C:Jt~M &. ScMol:. MJch&.d,j, C,!'m Prod:l!Ie~ .Mill1il,ge:g'; S:W & Te~m Ed; B'iJu ,Gf4I'J'<r'K"cIll'JI

IC:O'Ji~~~et-.P.:rucL1i~r!DJIl.: Rnjeruit!'f .p. Glt,(m~da

Assn. CnC'Ji!~j!i M3ina~r-!pf(!I::h:!~('io~r: fj' t. IJ!Qgora

l"r"QrliP~~ijnm ~f!<t:1iu!!led gn ~I!!i~ Wil!Ir'k b3!~ been cib!1rilr.!ifd 'by Tata Mcnr.(Lw~iHliJ~, frum 5ti1l!'rc(!:~, b~~i~lIed, ~ ·Ds: 1Fe~~~b~~, HiJwell,~r., J]~im~u ']',&tfl: Mc(]raw-8iU nor LtS -:a'U~lK!rs, glf.aTal)~~ Ut~ .aoclilfiJCf {if eemptetencss'ot 1iIn.:r i Il!fQ!i-nlii'itiiOfl !}lJ~li~l~e'cIi 111m!" .. ",_iW i'iejlil1l~~ Tata McG~.aw·:~ .. un: 001' j ts ,1!.I!I~M.rS 5lti~.:u. N J~p;il1!sibloe {(It al1i)' errors, i[Jmi~f>[O;rns", or dillnuJ:g~S, ,a:rl.si!ll,g uat of u~ of iI1ll~ illlf"Orm!L:ruj,Oll. This Y!'!Jirk ls pLibli~J~ed: wIth tile. U1td~rs~i:l[lj:.hDg t1fill_~ 'fi.U~ Mc(jil',l!w··]UH ,ilDd -iu.: .i.Ii!.llh!NS ~ 8l:.tp'p,1.yif~1i ~j]f~'tlou hi..i~ r..ll\e .MI, ilU.empt:lr~g ilI!J rend'::lr C'D~iniX'r:iD.g or ifJlihe r 11~!r!o:Fu!ii!ti~],lhL services, ]f !itldht ~i:r'!.lk~~ are lit>qLi~r",cL the BS1ii~·tii~e!l:· of .IIJfr Bppru;pri9i[l': prlo:fl(:!iSi:oo[J1 ~~ht!il;l\[t 00 SiiJlil,Stit.

~S~l !it Sr;r.Jp!. Mtt'k_er.;; •. ! 9,; A l.~D\,.lDiDA M;ilft6l., lP£tsc::h~ml Vihilt'. New DdM .! .~'O Oil·:}. i!i(i13 :p.Dfi,[ed ,at GO,p-SolilS . .A-2 .& 3, :S~IJl:ir 6,4 .• NOldiJI - 2t11. 30~

Ccpyriqnted materia

Con" ite . n its

. . ~ . .

.. ". . -' -' :'

:iL2

1.3

llA

::11..'7

S'urn..r.n!!lr;y ,15

R'euiew Q{,!l!!!stWJiI!!5l 11

I'~'

,;;:;".,

2 ;4 MIlji:[Ej c++ St;8lie:jJj!eO!te, 2':5"

2,6 An E~le with mass ,28

2,6 S:t~L1iro: ,of c++ Pf~ ,29

2.7 ~~tilll; 'the &~ File, ,(Jf)

2,8 Cemoolirng' a_ndj Li:rrikimi 3Q ~,um,maTJ! ,3,1.

R'e"ileUJ' IQ'U~U;[;r~!li 3;,2 ,lkluwg,ing ,EHrcises ,33 firrutlnamm4m E~'e7iCi&:r!r. fJ.~

a~ '1 I;nttOO.JtgmPD 105'

:),2' 'fuJren s Jtt

~lS, ~mdB' 3~

a ~, ]jdentjiiffir9 ,Bind er)Tils,tanh, ,:tIl

a.,~,

&6 •

a_,

119

vi ~=====~- C.o~tent:s ----------------

8.:1Q

,3.1:1.

3.16

3.19

a '211,

S.tU1i.i!i!ll::l!l' 69'

B~~i~UI' 'Que,sl~ii(l1l'Ul '1'1 ~b.ltMirw' ,EmniMs.' 12' Progromm.iJW B%ereises 75

4.4

77

;n 'I] ' ....... 'D~;t':..__~ 'L'I'l '!Va u.t ~1L'!i::Jj~~: .0,

4.5

4.,'

4.8

4.9

8~mmary ,90

lktl~!£!i(itI IQ,u(!,8~WrI8 92 Dtbf!t9inl brfN'ciue6 '9JJ iPr@gmmmiM Fa~T(:if,ff!fj f)5

------------- C'.timents ,------------ .......... v1li

...... '~ 1\.~.~. 0 ~-=..ll 'E!I. __ ~~ ·m'_~<: __ lrm.i..allLU.:g .a..nIlJHwi.J.~ .l" IlWwoD .!I!!W!I.illw·

3.10 114

,5.11

5.~.2; SteBiLliC :Mem~ Funl!:tiD'ItL"'I .11'1

5JlS· Ar"-mys. ,o:f(M:)joots 1: 19

5.14 Obj:eeh .as F\metJon .Argun:u:::D~ 12.2

,5.:15 :lITieDoly :~dirnrts 1:24

·5,.'16 Re~g crbj~.otB. 13J)

51"1 IQonst M'0mlK::rF~t1s 1.$2

,5 :18 Ml1itei"S m M~ili· 1'32

,5.19Lx;W (!~;ijs:re$ 1',34

8l-~m.!'ruil!ry 1:J5

R'ti!vU!w Q~~Wf.l!~ j\~Nl DebMg~M .E~lI'Wi8tl·s .un· Prn§mmmi~w' .E~E!'rei:s-g&, 1 n.

1144

~.9l 1,6fJ

il3.10

16~1] DAAOO1[1XfF8:1til2

8~mmgt7 164'

R;~vi.€w Q,ues~wfit~ 165 lli'b~¥ .E~'Errni:s-ns 168' PrQg.r:lImmiM· ~mse\S' It!).

I , ', , lOp:' _ ......... _ ~=-.; --~ . .;i1!i-!IlI' "",-d'.' nl'rfli"'"' ,Iif'" .......... ,..~~__,...ji.=_"'"

_ _.' _!I!;;.II.~)"''V.II. V~!I;;.I.··1I.~1I.0' ~,- ·",;rw~' ~!I!,I!'_,\l'II;;;.r.~~,

111"'1

''1111 ' •• i...... ~~~.-==.-==.-===-.==-.==-.==-.=. Cconienis ==-.==-.==-.============

7 .. t;

7.,,7

7 .. 8

s III CWfj!stru©1:or,~ .~]U! 'De.tiv'effl [C~ @OOM 2.12

8..12 ~:ti2'mb£:i Closes:. N Mtmg o:F'C] asses. 24'0 S~ifl'lmail")!' 341

.R.eI)~W Ql'tf!stiOll'ls ,243 .DlrbW'n:( &,;crrcis~~ .243

. ~mmi·~ ~n~-e~ .248

..

9t '1 W'otror1nmonS\,i) 1

,~ 2 Bli-illUIDj;j, 25J

'9LS Poj.nrers m O~joots 265

'9!"·~ th~L9 :PtdinMr 21ij

[9~5 Pminte~ M :oer.;,wdi {::]~ef\ 2,''18

'9' [5 'ViDUal Fug~ 2U

9[-' PlU·e· Vi-m~-8J~ Fr!J1TIIcMQJ!!Js U·t Summ~ry 282

Re~itw Q!J'e~\!!io~l~' 2'83 lkl!U4gging .E-~rcise~ .!M4.:

Pro,emmmiM Ex.el1Cf.8'tfS 2tJ9

~==~========r=, Co~~~l'1t~ ,==~~= s=e= ~~~ __

10.6, ~g Output wirth MRfi1iP!ilatom 3;12' .5b.tmmtill17 ,:1.17

R~view Q~u~·.5':U(;!il'j.i5l ,~'19

Dibtllflii.ng. Rtt_erfi~8 820

Pro,gnra:mming EI».l'reist&iS' 3~.1

2'''!iI'~' 1;J!~1~

1 ]]1 ]Jmfmn.rh:rm:tiif}D 3t13

l.l.~ m~S:W3 for m~ SV~, Oper,l!Utlons ,325'

,11 ,3 Openmg :and 'eLQ~& ,;9, File' 325

:11.4 JD.etectms: end-d!(f~i1e 3'34

:11..6 ~, about O~nO: :F.ile ,~ 8\3'4

11.6 ,Fll[e, ,!Pointers mld. ~ir MmliD]D.lJ!ltio:ns ,3'35

:11.7 Seguential,Im,purt amiIJ Oui!tpu1; Operati_g,ns 338

:11.8 U~*ilfll a F1:ile:: Rarnru:.m A¢;~6' $4:3

11.9 :En-Uf H~l~' D~Jil:' ,File 1()-~el',S!ti~1!If.j ,$48'

rt .. "!I'I~I C · ..lL 1\: __ 1;,.....,..., , ;I-.,. ?.I!'';;

.llLU Qm~.IlI!nU!I JCJi..o.s JLI.(1tlJIi2! .Y.~U'

~srumlnan' 353'

R_"'--iew ~j"::"""'~i: --'Ii o..I:"~

~~ti"_~_~ ~~ __ ~_ u>iJ'1ii'

"J:hfJWfJ{i'ml ~FC~ ,356: ,Pro_gmmmi¥ E-JOOFd,ges: 3'58

36l!i

37,1

BilV~W QU6-.!1'J'£I!ln.s ,3'U! i'k'-b~gmg ~reius. 31'7' PrQg~~ E~Nt~$ 879

L 13.. :~e.:p.,ti-Oil HancliijJJQ:

1;3, U Immoonecnm .1M

.l:l~ IBWji~ iii!f~i;leptitm H~dtins' 381

ix,

13.,9 :Exreptio:n HiIllldllii;g :M~oofusm S8J

13.4 T1!u-owiiilJg :Maeb~s,m ,$86

13.5 Ci!lwhlrrg M~~m 3'88

lStG Ra~,w1liQg aE. ,iR:xooptiuo'J. ,3!?1

13,.'7 SP?ci.Mng 'l[:xoowti~n6 j'$i2 Si!!lmU~C4iry tJ94

,iJ!!ti'&tw Q~~tiQ\!'t~, 3M JJ'e.bUCgttlg EX~f'iCi'8~8 ,3:96 ,1Tgg~mm~P9 EUFClBti'S ;loa

401

, 4 j I nitmdncti!!l!!!) 4n l'

1Il4.2 Com:~nmlih3 af'STL 4(J2

m,'£ 3 (".;J)liDbirn em 403

lli41.4 Algot'i'~n'iI_E ~oo

114US, Ttem_'~fjrrlj 408

]"t6 .AmJ#U~a'ooJl of COD)~mer C~ 400

J1,~,. '1 FUifili:otio[}, ObJects: as

S,~m.mt:Lr:v 4:21.

423

N leW' Fea'ID.reS of ANSI C'" + Standard

'16.] Jij'i!hvd~.'i©'iciofi 4'46

]_~12 N,~ Thlim_ T;ypa~ ,441

JH1.3 New OnemtGrs 441)'

Ji.'6,.4 Class Implementation. 45,1

============= c.:.1th:ln~ ,============." xi

16,5 N~s,~' [SI~@pe 45$

'16,6 O;pe;r-8!tor K9}l'Wlo:rds; 4~9

,] 6" '1 N~ Ke)::"'WCilds 4'00'

ll6.8 New iJeade[:ffi, 46.1 Summa"' 46:,1

RetJie'w Qi'igstiaif2,S 4&3 D..j}~mrzhl!!g Eurc~ 41J4 'rOlrtimm~q Extrc,fst~ ,461

411

17'.7 :11.7.8

17'.!) 4.S0

1.10 'WraippingU, 41n.

Summa:r:w 492

li'~tJ~illw Q~'§~~iQ.iiW ,1.'4'

570

$,£'f, ,~

A" n...illJ'_r F" in, -J' ,,'" 11',0.", ...,z:..

:_,~we~~ ~ i!ral;n~, ,.;,0 ,~memper

Copy rig hted m ateri al

Prind .1es of Object-Oriented

I P . !iii , "

roerammma

: Ib == ,iii

KeF Concepts

~ Sttftw~ f:V(IihltiJDtli

). ~cedUIre·'I}rieDibOO, progr.runr.L1rng

)0 Obj~~-ori.ented ]iiliB!

> 0l6j~0tM

)- Classes

). Datil !l~a!l'ac ~on

,. Ellcap "i.i.Iahon

>" Inheritance

). Po Yfllo.rphism

)0 ])yn.a~ hin~

)- M e:S::1.a,.!!1:1!i! [pMsmg

.,.. Object.mrJ.egt;egj l['!jtttli,",ge~

). Object.baged, languages

:[h;l'V(!lruCl!,PDH'lm!l:is m, S fiiftwillril 'techno~o:gy'

~ --

,c@ntinua '00 be dYll:8!~:ie. N'~w too.1s and 't.eebnrnq"UJeEli ,a;lrIe anaeunead in quick l§llJiI~I!ii!i!§i~,i~.Th:i~ h~~, folil1l:edi, ~he !iI)Rw~," ~eet;s ,Md:~~gyb.lll'il~tm,guS1rY,[\ook :mr DaW' apmn:'illa~s rIto si!dit.w[llOOJ ,@\~ ,a.d. de.ve:k!..pmeDt~ ,gIll, 'they' ,are Ilm~oomimg' :mo:re ,and mQft: ttitwal :m vtiJew uftlbe, m~~

~p1' .,..,.n'+'!J ,,,,,iii' s-iJTj~""" ~*, .......... CI aiD .. _1'1 ;:;;:, ~-H.i.I;; ~"':.1' VJ.; -~I""Wi'!U~ w;;;.o--rlf ..... ~_U_I:;II UiD. -rr-r.'1IZ_1J1. !U.3:I!

'the highly com,peti'Mve DfBt,Ur.'e' Otf' 'the indU'Betry. 'ilibese 'mpid rad¥a.n~s a.pJeM tu ba¥'"t: ~tU it isituatIDilE ,of'crisis ,mthim. till:

~_"'" ' ~ 1'I'ili. ... , ,ir."-Jlil,.· • . , , . .,'11 "'.~ 11._

liElliIIllBl .... .,. il,JllL{l; ,WJlJ.~ ,I£BliIgS n~,Wl' 1lI'(I'

ad~erl itO, :ifi"are this lmisis:,

• Row to ~!E'fO~l!1!t, !l.'eed-~ e!i:ttit5J~, Q:f :p:N"L~s in ~¥s~m dee~'1'

• ,Ho-w 'brn, dLgsign SJ1',st~ms w:i~h. Il);pen, :in'tenac;es?'

Copy rig hted m ateri al

.. How t.o eills'W:Ie irIEFllSi3tbili1::r and. I~tc.usiib:inty af :h'lli:!(]!t:ilL~g?'

,. HiiJW to devel(l']ll moo1.des 'tlui!it are wlerra:f1I.'t. to, ,BliDY (]ha:~8e :in fii,li!brroe? ,. HIiVW ~o i.miliilt~lve ~i!1ftwll[le ])il."@d'Ui!:t.hity a:l'1d deerease sofit.wm!Nl: (l!JiSt1

• H.ow m tmprove th~ quQ]ity of S'o:llw~?

• H'IlW to m_;fIl[JJ8ge time sehooJ1l1~?

• &w to ~ndust:r:iali21e t'he ooftware t~v~opm~t ~~,~

m&i_ny oo:fit.w3'H' :pt.OOucls are eilih.eil" [UJ:it firuis'hed1, CEr not used, ;Q(t" ~tse ,~, deillill\~, wHill :majOl" errorn. F'iguR m.l ~ the fate of tbe US Mfllmw~ sn1itwBln ~~~ts 'U!nd~lta~efi ~I)j 'the :1910,9. Aromld, ,50% of Ebe :so:fti;:wam PIlOO1!lCtS 'W81:''e :mM\fJel' dledlrve~&d; w~ Qne-,t.hllim of 'thC~1 which ~n delivered! w-ere never used, It:is ]I]rere~ting' m nom' 'tiliJ.at 'Q:ri!ly 3'%t wer,e ~dJ as de1iiv;e~ed. withmtt being ~lJibj'ected ThO a[IJJY ehanges. This lUustmtes, ~;EI[t th~ so,iw,s(R imtdlusctry us' ,a, :fijglnMb'b:ljl" ibM, ~rd in delilfelt'tq' ~1L"~thU!t'EL

13,6
J
I, zs
ofli
:=!l 2:
~
tJ: Hi:
on
."
g" "
(I,S
(II
1 A_b;[Ji'jd~

,orrr,~~

liisa-i ;IS ~~

,i) f'roja~

Cbillll:li§e-:cS, in U!S>eii" in;!qu~:ternentB bave always 'been ,8 majoI' preblem, kw~, st'l!ldy (Fig. 1l.2) shows tlrnrit :m.om tliJrnl 50% of'th£!, systems r,eq,Ul:r;M mltlimeatioos due to cnMlS'e,s ill Ylliet J:leqU]lf'emeD:ts and data fm'IilJii!ll.b., 'rn:t o:llily 'i]hlst'ra.rbe-s ~t. :il1l, ,Si, ~h8ii'l!;Jiillg wet-ld witJJ a d.~m[c. :bu6iiil.e~ en,v.Dronme:mr~ :l.1eq,uesh:for ~hatDg€;' aJR l!l.1MII,vuidaMa 8:nd 'th~~re systems mrrst 'be ,Mi!l'il'ltah11!! .and itOJ-: . - t ,~"", ~t.."I' - '.

, ",' .Ii'" -, - ,- - - - - _Ee!!,'l[.J], _ Ii<'!.!' !!.iJl~[lg,e5,

fteB.e' BimdlLm .and ath€'l" rn1PO* '!OOl s~Ihvm'le im,le,fi'u;;:n'ltakiuJ'!!. <!iI~t t.hat. ooftwR're' p[ltKb.1i1its uomd 00: ~va&llJaJtOO. Mrofullly:fur ~,eb:' ~i,lJQ1i:~y ~efute 'they ,aIre deUivce:[ioo, ,and Jimplemen.tm, &i,mel 0&:' tile ~Uty· issues wit: must D@: CQDsi.oo~d fill' !lJ:"riiti(1a] et'liI~~~ ~H-:

L C~~tne$.S

2- MBi~,taii~.i]ity

~,'. 1D; _1L.!11" i ....

iLl< neu;SillllLIIII....j

4. Ope:Mese aDd int.e.;OJe:l"Dibj]i;~,y

Copy rig hted m ateri al

------ ....... i :3

o. PortEilbiLity 6, S~!Jrity

7," ~iilfle;rity

8, u.ser: :fneildlJio_ess

C~IO'~fEl!ilY!lliIlit!l;Int:9,

C!La*9i'ln dail3, 'fotmat51

,~~'t f.,~U~, ,a'\1.tell-ltllO'WR lVritJer in tile field of artificial[ iR1lie'llip;m::~~ oom]:l~ tlte ev!IJ~U!t.i~ ,~f' ooftw~i'e '~~oo@logy tlo the growth of ,8i 'tNe. :!LiMte ~ 'tree, !~he saftcWaR' '~o]y~oj], ha ,I!i~j 1d.i6t:ixt~~Si ®r~biyel1f'Q'r~t:h. TheBe']ay'e:l'a we:rebWlt,u:p one by O'ne lmre~:tbe 'last :lve ,decade ',H SbWWD iro, frig'. '1,2, with eaeh layer :reprn'esentmg 3[[ imp.~e:mel'llt (!<veJ' 'tbe P.fevl:OUS 'OR~, 'Ho~'e"flf!Jl'!r 'tJi'le: analogy fiWB, :i£we ,vo:wid.e:r the llife i[!,f:lliese ~~em. In soo:tw.M'e iSys~e:mErl' each o-fllie ,~ern '~ilntinues tn be functit!nw~ wh_~ in tbe ease o.('trees,.. only 'l!]:u::, Ylppermost l:ay.Ll>'-i"]El. 'wlll;:th:m.'IIi_l

,Alan IU.:y'" ~n€l' Ciift~a !fu;on'u'l!t~n af'th.e' (iibjeC1t=~riel\'t.ed, ~ ,~d t:h~ princi,pall decj3igr.t~r' gfS:m;aUttrurk, has :said: r:A:s: roHij!:Jl'~i~j.i "incr.g~s;.. a~hitect~ ,t;I,'tlmi.n..t:1tes :t~ ,bQ,m~ m.tJIm.ritdP" Te, 'build ~O~,£ljy'iS li3i:km¥!~:aM mhmrn it ~sJ jl!l.sl not e.DiiJIqJgh t.(l! :put ~em~T Q sail'U!le\n.~Q ,af ]lI~~g ;B,b.ibememb ,and. sets iIlif]liro!:led.~rm.d :mmilliles.j' 'We need! to mc~arre: Bm.:m'G. ootaS_ruL"~itlQ, ~hThjqU'e8 gfj ,ptogt,Mii !5tr.ue~re!i!, ~hat m;e ,~y w eo:mpr4~nd, 'mJ,p]emen!t ilJJ1ld motify.,

S1inc~ the trv'l,feii"lti~~ oF: 'the oomp'U;tel\ mm,y '[1fiqr,~ apprn9clles '~H;1Ve been, 'trled.

Copyrlqhted rna erlal

ThiWe tfJlel'Ul(le ~~~qU!a8 ai!J~ ,U ,m~'u:iail" ,'progrommi'n.g~ ~o.P ·dowi!'il: ,pl'Ogromm! rlg, b(llft~M. -" ,-,<'mm~'c tt:!1l:.-,f -t'Frui ~"-'-A,--c,--_ ,- , - - rmiL- ,_J, _': _,---t.\".,-liIo!'-n i-- :-'i-., h . 'i..":-n

~ p~ ~ !iii' ~_, __ iI]_Uml;ili, p'(¥)8rrMR.m1.nR • .i!l.Ue J1\!J'i!im:tuy mg~l8J"lO:_~ m efi'l:IJI :9S ~e~

'the eOiQOar-liJ, 't~ h,~d[e 'tJl}e b)j~weasiiJ;g ti)gm:pl~~~:ty (J'f 'pr(!l~~ama, that ~:f~' teliable SUli!l ,mmnmiTtable, 'Tlle-s.-e ti!,eh_JILi~~ h~'\!',e ~e J?OpUlll!1!.l" ,~Q\tmg ~-Qgl',~m;mel'ij ~ tM La'iI: 'li:w'@, d~~ades:.

'Wftilit tl.el a,d,l,\'l!!nt o:fl~gu~ su~h, as C~ stnme~lUmd, p~ogm.mming 'bSQ9.m·e very [pc.pldar.

Pd W,~ the ~m '~Mhr.!ikll,u~ Clwthe, 19B0s- Sb"1!ld~d p~mm.i.llg W,QS a ~fi!ill 'OOQl wt eni!ili1ed pmgr-amm~s 00 writiill ~oder!l3!tely ,complex Jil"Oglf':.an'IIB: :r~:i'i:r1:y easil()"". HO'w~iN.~ as tn.e ,pr.,~ ,pe,w' [~r.'!! even, the ,stxuct1irned R,pl'ailCiIJ.l1RiLffiI 00 s'how the tooiredJ 'resu11ts hi te~e(j$: bQ,-\li.ee~ e~-'oo-'m~tai[!J~ ,Md J'En.l~'tlb]e ]lIngni.IDht

Obje:c~"O:r,MMtd .ProRm:J\ilUj!unB (lOOP) Us atiL ~& 00, ~ O~SltiQ]il mud deve'l~t 'tihat ,~pt.e, 't"01 !a]imma'te s~e of 'the pi~f31J~ ~f oonv'E!oti mai pII~'EI!rnmfug met.1w-d9 '!b,Y ~~ti!Dg'~bes!!;«~~ ,--~~~fegtnws ~t'h~~~w~ f~OO~ts..U is 81.:~ way iOf'~.~ ~. ~~C :poo~ i;U'id has ifitlthitlig ~ &, 'With any ~~td~ ~. H~! ~Dt olllan~ ~ su.imhll! to impl~t 'iJ:I£!' OOF oonoopts ~.

Com:~t.i.lInfd p~~rnm', 1rJ.&1in_g h~rth l~vf!ll hl:~:& ~, as OOBO:L. FORTRAN and Cf. :is ~om:mC!:J:lJ!y kfJJ!l:liWn, as pmeM.u'nl ·!iliil"-l'entejjj' pr~m:tWl:J'.I',.h1g (POP). '[n thl2i ]YR!~il1Jrg .. orie:[ljtm '~~" 'tdw ,~blem is, vj~d; I!_I) a a~qiUen.«! mt:hill.~ '~ be d~ ~u&]n as 'r,;~g, cRin.lat_ID__g

Copy n g hted m aton al

and printtiing'. A. :D1mlOO m:fwmti,~ are writteE to aooomplish 'i:h~ ~~. The:~ ~ is"o:n-:fun~~" A'~i~:~~' fill' p~~,,~iS:sbOW1O. m,:~g. ,1.,,4. ~.~tBclmLiqUA10fhl~~,d~t.IDn,~ be!en ~dJ W:lli.~~'~'~h,~_pile:ted

IQI' solVing ~, prOb]Gm!. . ,..,

:~!J.i~e:ilted p~~mmlRg hamcilb' ~st9 ,of"writmg {i, ltst ,O'r'h:ts~ms, (or. actions) :£01'" ~,he ,cO'mputef'"to f®UIirW, and or:gaTIlizmg- 'tWa.e.5le Dtru~tj®l18, :hoto ~p DQ~ ~ .f~naioM. 'W:e :Dormal[y' mse a fiawc..oort to 0~~ these ,actions and represe-Dit, 'hli-e :fI~' 01' -collitnJi om. one adion 'to' MO'tiber. 'Wihlle w,e coIiren.itraoo 'OE tn,l;:: devcl,opDID!imiL of'ftmm,msjJ, '!,;'''!:'Y' 1 ftt'l e' ,anenrtim i9 !ii,YEn bJ. tbe data ,tl1L8it are' bemg' used ]Jy varl~: :~~twm. ~t :ha"pens to 'the data? How, awe 'mey :ar_I{~~, by '~be ~~ ~t WOl'k ,a-1i!J th-e.m?' "

k ,8. :liJi)jL][U~flLmdimt progr.BJ~, :many ]mp~t darla ¥te~ are :p1ac.e4 :8t9,ciuoo" so tloait; ther 'may lJe ~SBed by ,~[1, :the fg~~~mw, "iE!:acb t"W!R~ m~lY lW~iVij :it~ '~wn ,~t ,~~fi1'" F!~l '1.5, ,'Jbnw,8, 'ill' :,",.-.'IIa.""ill,]jj=t..i' iCoi"-ll- k ".,.]1 £.-n....i;.i' " , i; -:' "~:",:~.Iu ",_,.......i, n~-.Ji -; iMIii~'iI1I'i,_

!L, _ _ ~_~e ,~~ _,Ii~ ~ _ !Ji.!!!!,_iJi!l _;!, !!.I!a~a ai!1!!;1i .!!'!.I_~"",,~t1n5 irn, :a pI'I~ _ife~.!!e_~!!;Ii ]11" '""!I!'" """"""~

G:!~ba] ,~. ~ m~, ~1~b3e'~ ,~, ~n~dr"r.~~C'l,t di~ilJI~ b21:eJ ~~ mh, i!l!J :_IE' :PH;iV:slm it Is 'V€G' dtmtitd't. ibo ide:fJ.'tif) w.bu,t ,data "i~ 'Q.iMdJ by whicl1 :~tmo:m. In ·e;Me we RE~ to re¥ise ,an, e.x~s;[ data 51ructwr;e, W'e affio iieeili 1::0 l~ :aJill &~ona 'tlh:ait aOce5,a: 'the (lata., TItm :~vi~ Lll (P,Pp:!Iri1l.Lltity f®r bQP 100' er.eep' in.

Anot,het, ,seH'OUS d!tawillaclt with 'me p[\~unl 8ippooacllL m 'matt rc does, fifJt mMel, fEal w~,[')ld ~l'\llih]ll!m$ "l!,~, 'W~ll This, ~,liie~!iI.1li1e filt.l~ti@'~s; ~~e ,Q~~f;},~!1.etl~, and d4!! DQ't oo~1]y

~~!rn'es~oud, W' the' e'la:me:l1i~ ,@'f the ,pro:b'lem;, - -

Copy rig hted m ateri al

lOcal Itta1EI

'.' :iimphaBi'S is 'ijlo d~inG' ~p hdgo:rithms)"

'. :~g» p]'(:!gr,0Ims i0!.~ diva,(k:d!, into S:mlIa:n~ p:rngr.I]JIl!1S m.ow!HI. ,~S flll!tl.C't~OOlI:EL

'. M~s.t ,of 't;lw, f!ll~~ti~~lS sh~, ~~Dal datlllli_

'. ~b move Q!!i8E1i'ly '!;Ir1l'!IIi!lll[uIL M:U!i a,~t.l;im, -["rrom, :fun~tt.ij)in. tAl! fun~t.iCin.., ,. ~d~I)M 'b"$!lSr~n~'m, d1a'~a f~m @'na f~l'"m. rbo :i;1'nO'~he!r.

• Ei~~I~:y~ tQcp .. d'ow~~ 9.p~lI'oaclrJ. in, pr!~am design, ..

1'1. ..-=;

!Ii ... ]

The :majl)f' '~~U,'W~tiil:l!g :raemr W, ,thQ in.'!l{!nrlji.on. o!F"llil:~J~o:ri.m:lJtOO, iOippNacll is to, ~m.CIl""·fll wm~ af'i.h£l' flo,wi! ,~oo'jmite.ll"Cd m. the ]liro!1ledW",~i ,approoi1ih. OOF meats, data as a criJtiml ~em.e:!Ilit :im. the IP1'lOgr:run d!e'I'Ielo;p:me[]Jt 8Rd, d,{Ie~, :OItJt. ,a~I.ow' it '!to ±low 'if'rieel\y ,i!lHundi the SYBtemJ. n tiES ta,i&' more clooe[y to 'tlte w_[jttf~[j~ that. ~,lPemt.e' OiR :it, ~ndl pt~t!e~~ ilit :fi:@m :E!J~.eidfj)],m[ iIIU]mRCa,tiotl 'hm g:gib,9id,e, tfy!j~t-_rnn~;., OOP SiU@'W!3 tl!F:gooTIr~itiflri, gf' * tJrnb]~m !Lt;I[t.g, :iii. :~llII~'bgr if,~ ".~:;j..Ii ... -; "·"'U~..1I~:r;.~~ ~~,~ and j,,'bCioi'l, 'bmhia ,dabl and :r1ll1Lett!lll.DS iW"!!u.lIn.rli tl~-=-"" .... lti·;O;i"Io'~"'_ T.f-'" iru: eJ].lI;:!iw,.,!1! """",~ey Q.!JJ~~""'8 ~~,y IW,~~,. ~ ~ __ ~~ _ _ ~. __ . ~.' ~_ ~. ~ ~ ~ _ ~ __ _ ~ _ _ "" ....... y~~""!I?!;!i_ _ ~.!!!I;;;l

li:n"~iz£lili.®.f.iI, Orf data i!U1I.d :f1i:1R-etio:n:s, in a])ja!llot-ori!lUlfoorii programs is: s:il.owo in 'Fig. LEI. Th'12 dBi.m.of,rul obJoot ,can be aeeessed o:nJly by the :iJnJctio((Js RSstJciaJtOO, with. 'tih.,a:t 'ilIIQject.. ,iHo'!,irevel"l' ,;to:.~ :"'~;,~.-.,:-,.-...i',c -.~ ~'M~~~ :"'''n,'''''Il:-~'''''' fh'" rL:iln~iiffl!i:'ii"'[O"'l1d:Jh"'ro'll.i:"ll:h·-_

~V!..nI1:"""I[\1~,,!:! 'lJ'J! moe iiJ~.!W", ""'!i!I_ !;I;_~,,",~ ~ __ ". _ I!."'" _ ~~ _ _ __ S - ""J"" _'~

Copy rig hted m ateri al

iSo:m.if: OF the st!t":iiking' feaJtIJiIle£ of: ohject;,ori9ted ,[J.1lIiJfiI';ammini~r 3JIIe:

• Emph.as:i~ is, '011 data rntheI' thaJ~ :p~!Ilre'.

• Pl"ogrilrlllls are ~iYided :llr:irlbo what, ,B1ire' lmo-WIil as nbjectB.

• Data stntctUFeS are dleB~pedi sud.. 'thBiti theY' maFaclteri:2le t~be objeiiilts..

,==~~-- •• ", 1

.. .iFunr:t.](Ul5 'Ulat opeirate en th€t. data ,of rut ~bjmtlt, aI1e tiM w,gether 'm 'the ,dB/tao 5t.nl{i~

, 'tW'ie.

'. D~tSi. :is Wtidld,eoJil md. 'C[ilDilAiit be abce"ssed by exte:rn8~ mnct~D:Rs. , 'Olbjemi ~S '~@mIRll_m~t.e 'witch ei!lidt other :t~hmli-Jh :fUndj)'j~fj.

,.. New data and fl1Jj]c,ti~ns ~i!Ui be easi]y ad~d wb~~w !!l.e~~00"Y. '. ,Fntkfws oo~tom~~p ,~.p:prll!ae:h itl P(~~ des!gn;,

ObjlUt-o:f'i.an.iOOd, :pro!P'a!mm..iJIIlg: is t~.e most !reC!2:[]l !!IQ:llflept. Blm(i!llg '~.Mnmiing :pHiI!di~ iB1IiI.-d. stiU :meaml mm:ere:mi.'tJrings to di[fu'l"€::rnt p00j:i[e. :rnJt:u taWmIDrn :impIlrttmt m ha.~' a WQl'~

..:il-,IR:: ..... ~;~.:: -- - f -'JI-..:- -~ ... -·',,;, .. ,io ... AI - - - -- -' -"J;..- 01:"-...... -- ... .......:i iI::.,,_."J;..,- W' ,.l .... l':: ... _ ~"'.I-u:. - ~

ue:UlIllJiw D 0 (ilJI.I'-;IIe!:~lU)"':'iIoK;1l!Ii ~amml]j[g' J!.lIe:lLlIJ'J.'e wei pl:lOO~. :u4!I.-W.lLer. ',~_ ill! ~'Jjil.!lille U~iet:;!1.;"'·

" ... ~.l "L 4 if., jI .......: .x: f ,~ __ ..l'i· ." it,

O~~ ~,ifammlrnl 8i!l!. ~i!'l! ;ji!:p:proa:c~~ J';i-",iIl.~ p~!I.iI~ij:' 6 U!~y .0.. :r'!\Uf!iiI;U,~~~ I}'n~gmm~ iLoiy

Ic~a:ttq' partit.iQ.rt~d mem.m:y area {rJr botk. aabJ !!L~ f~il1dwM ,~k~d >Gtln ~e ,~' § re~ta;te~' (:or !CrH#~' et)'p~e~ lof ,~cJ~· ~od~lg~ ,o,iti ,d'i;1~('.!:j~d:n fb.~~, ~ O'bj~~ ,~, ~~~redJ 'to be ai, iPari~ti.oHd. aaa o,fl~~m,U!teJl' memm'Y ,tlh8it si®.rec9 itlJata. and set ,nf ~Mtm 'Ulat ~ ,:KC:eSS ,ith~Jt dl!:l!m. S&~C'B tb.~ m~OlY' partitlOlltS '~' iw;1!B'pendl~'t. ,~,@~'~~ ,r:;:~ ~ ~d in ,8, vwty ,~f difi'fn'_t p,rogrBillls 'Wiith~l;Ht ,m~di~.ti(ilns ..

m;t 'La :[!je~e&9a.ry' to ~d,ewst~_d some O'f' t'he IC@[:}~~~ g~ ,e~t:eD9<]v-elJy ~D ll)'bjeclt-alielll;tedJ ~~ro 'fbes-e· 'ineh!lt~a;

'.' Ol:!i~bi ". C~aas~

Copy rig hted m ateri al

• D&'te ab5tr-Mt.i~[jj ,S!~dJ e;D~psyiLatt]o!l

• rnbe~tMm.oe

., Pioly,m~~msm

• Dyn~m[c bimding iii Me_s$0!gtl pnssl.!D.g

'·W· ·ii.. .. ·'l ...ll:_ .... u. . ..;;if • .:iI"'''',,",:'j. ~'iL" j.'

... e iBiLlru Y/W[lUBS IWllLme ,~o.nitle¥ .. B' llIl. some ,w::,~u HI '~uiLB iSe!:~li!Jll..

O~I~~fti

Objm:-ts m',e it.he '00 S ie run-time enJtiJtie_s::m 8.![[ ,oQje0t-orleJllited sysrem" 1ll'er may Nprese.lJ]:t; a PQTS(liDj, a p]ii.e€',~ a hBlIll'ik:, at"!Li01lm.t~ a ,t&'ble of,d8lb or ,ooy iIt€m n~a.1l '!tic: pro-gram. h08 ~Q banrl!k:-., i]b~ malY also :repre:rent lIl~d!_mj[u~d data 'slIlc:h CIS 'ftdOl's! tim!2! and lists, P:rogr.,wmm,.ing !pJrcmiMmn is, .EIlD~ed in, 'te_riElli'!l of !j)bjems, and 'tJ1e' ]'l;J]ftil1lre' i)}]: OOcmmJW]Walti0.l], ~~ t~t1l., P,n,grniID obj ~~3 sbauiL'Il De ,~hoBen w'lili 'tlmit t'bey metcll dos:e'lly wirth 'Vhe rea]·wor1d obj ooh, Ohj~l't~ take' up !Space in tbe memory' atlt!!d ~:av,e :aJ:Jl. ftflMdaibed, ,addnss lilkle a :reoord :U1Il Pescal, orr ,a, iZitl'Y,CtlilX'e' in c..,

l!lA1I'A

Ngj~e< ~!.Ie~~b!i1lh Miiri!ls:

f!UJ';,IC1Ii1 GINa li,a~~1 A:Vef,Elig~ [!! i':s FJfa;f

,ClaSKS,

W€:just mgnti.@tl~d 'thrilL 'ilijects eon!talln d)Q!tn; ,a:ndJ oode lJ] :fna_n~:p1i~9"'te tn-SJt ,data. De entlR' ,Bet of ,data, and, ood,e ![!t] WiI. object; can be made a lJ.lSe:r-dJ~l]l:Iied data. ~ 'Wiitn the heJp of;El!

Copy rig hted m ateri al

~l'~.~s,. In :fnct. ,i)bj~~ :aiR 'vnrlablecs Ql th~ type cla~~'. Onoe a ,C)1~~S$ 'b~ ~~n de,iW!~! .Wle ean ~kI',~ num'bar ilif (Iobj~c~ lb~lonlJjliig tilti th~;t ~lafi~, E~ (lbj~e:t is, 8$!1i~i~ted Mtn tb-e d~ibL of' '~' e19ss lVith wUdc'b t~Ja!Y 81n cr8fllbad. A class is t.ll1J.tS Q, oo,llemion, '@'~ ~:bjG~ ,of' ~imi]Q!' t~" ,FOl' !9Ii(~pl!e, ilDat1i1O:i ,aIP.ple a_nd ora__n$ ttt-e :meml:!em @f the ,~~~ ,hit. C~S ~e ~ef=~afined d~ta 'tYJe!1l, and b~ha,'le ~e 'the htti]t-'~n ~.~ O'f",a, ,~~min:I' '~~_ge. The 5YD'b:\x ~ to (Hate an object ]9, an diIf'eHIl'Jt 'tJtan tAe :S,~tu used '00 (j"~a'te .an, Jit'iJteger o'tf.fect ~I;] c. Ifhtt has been de:l][1ed as a cl.U!!!l' Uteo t;he 6taJtemer:Lt

tru 1 t mang'o:~

wm ~'gi.b ~ object :.ango Ml(inw!Il!g' to t;h.~ 'c~~ 'fruit,

IIil,=li~a Abstracdon and, :~~!\psil;lil~ti\rnn.

T.bfl' wr,app&!ng' up o.f data Bind fune.tio.r:I!Sl :i:ntio ,a s~:ogl~ ull1ilt :(.il;lilil;U~d c'LaiSiJ.) is known ~~ ellWtII~lit~~iq~" :[lQlta e~~a-pellJ8:tiCll'[ is the ,ml!l!~t :striking 'ro~t~ Q'$ ~ elass, 'IIh,e, dJ~ta, ts ruJit ~ible, to the ou~id:e w>oxld, nil, ~ruy ~h~e f~~~ wbiicl\ ~e wr,~~ in, Uw clQSS, 'a;lllln ~ ~t. fte~e :funetf~ w~vi1de' the ifi'~OO llJe'~weeFJ. 'tihE' ohject;~, data ,~~dJ the ~.am., This :in:sruatio:a]. of.' ~be d:Sit3, 'lro.m. dJireet a;cee9~ by the prognun is ,caJ]ed G!lita htd'iq or

s: ,",~. I'" iL"..i',;, .....

,I!~',~j'''''~a!;own ld!l.d • .:e".

1nheri.t9.D.C-e

.ln~'eril'l!Jooe '~ ·~h.e proC"t!aS by' wmcil ~bj~, ~r Oti,e elaes MqWi"e '~be pro.~~s 0'£ oOhjem ,O'f ,l3i_~;uvt4l~l" o]~. It e;~,ppma ~he OOli'lcept ~f' k€fJ'rorchiM~ ,d~~fim~joll. ,F«r ~"L-e,~ the ~if.d ~b$I1/ is ;a, p.mt of'lhe >cIa-as ~ Ml'd; whicll ]6, apJ.in ,a, ,pa'Wit ijfthe class ~il;di. Dw ~~i~ta l]e,hiE1l,d, 'U~.lS! sw.t ,wi div~i_gn iB ,tll:at ~lteh d,etiV100 cllS'!Zi .8!h_iW~ QO:~, eh~..m~Ert:l~tli~SI ~illi!J, '~be eJl~, :fHm 'vbi~.b. U, i5i denrveiJ, !liB 'ru.'W9u,ated i~ Fig. Ji.S.

Copy rig hted m ateri al

iBlrdl

J!I{i.Iit!~ f'E!mlile.J!:il, La1f'8~9E

N.gnl1ying !Bjj\d !lil~

/~.

Klwil

POlymOlt'JPJdsM

,~'i!'norphiSim lS, another im,portan.t OO:P oomm];l!t. PtI[ymoiLiPhism, ill Clreck term, means the ~.;bilH;y tln!'~ :mffi'\~ thsn illI:Ili2l fMm_ ,,An 'O:p!1I[['Q.tti(lll, MQ,l( ~Jdllbjt d.i!ffln·€:[)Jt D!!!:harlO'U!I'B m diil'el'>lmt msta'.[u~(:s\. Th'Qi oo·haviomr Mlim.d.s upon ~ '~~s; of data used in tthe opemtcion. ,Fm examp]e, OOl'llsJ~l' the !l)!1P'(lfr,grtJ'i1!l(1l o-ff ,add.iti~tll_ ,FQl' twa I~ulmbt;ll',s, 'tJ\o, operntion 'WIiU ~m1IDrark:: ,i}, sum, If '~ otpiln'mlfl.ls, ~i:!l strings, '_lI:l '~ (i~,B1t:i!l)!D, woLJiJd. prodJI1OO & third strln;g by !IXmOO'tellU~tti:!JJii:" 'Ih~ i~lrO!JeS5 o:f~' an iDJl!e:rato:r to exhilb:lit tie['lent be'ba;v,i.oum in different irJ:BJt.ooc:eill: 'm :known ,~B opc'f'ifJim' O:CJC'rloo..di~.

Po~y:mO'~b.d.sm. :p]ays an im.portant Mle in anO'w~ng objects il:LBiViilllg d~ffie:r,ent intel'niillill .structures, 'W Bilii:EU'@ tJiie S9JIIie atemHl iintem.ee,. TJ:ti~, me3Jn~ 'th8"'~ a. ,general (!~i1iiBS {!J,o,pem:Uons

Copy rig hted m ateri al

ma,y be aceeffi~ in UIDe s:ame' ,nl~F eV'ell 'lill~~_ 8p~ffic .'uU~m~~, asR~~ted, with each ;Q~,ati~jjJ may f1jU['i!f:'_ :~!)':_YDl~rph.i~;'iJ ~, ~xte~~$~~ly ~~~ in ,imll[;e.mJa1Ilting imi1£!ritlmoma.

8o:K object

D}wMUic ,El:ioilmS

i~n~:H~g ~f~!i'S, to t:hti,ii ]i~ldrwg ~f,a!, pr~Uir@ esll to the eode '~@ be ~~ted itj, ,rces~e 'W ~ ,call. Dyna~iic blilid'ing (also Jm1lvrJll. 8!5 late mmding} meMiS 'tEt '!the ood)e RsOOmi8;tOO. 'with ,it ,gfi,'\!',8.f)! p.1"OO.eduJ,"e ca:11, i::e;, [!Il!lt M!iJ!W,IlJ ~ii1t.i[ 'fihe time Qt~ha ~U at :rulF.i . .!~m.e~ I't: is, i9-S21~lted, ."..-ath 'p!)1Iym~iK_1D a~1rlJ 'iwheritSJn~. A ~unction ~U M.9~li:jarted, 'Wi't~, ill ~~.d,ym@~bic t-efetence ~]l!imds on, the dyn..:l3lmie typ~ ef'that n:iD~]lCI(;l;.

~

(~@nsi~:r ~ p~dJure "'d;l',mv" in Fig- :lL9_ By ';~'ril~nill~j ~e\r.Y ~Jibj~t wil~ ~ve' WLe;, :p;toce(h.i!!."'e- '[tc!ii ~agorith_1tri 15. h@weve:r. Wii~~ 'tQ' eaeh IIYhjeet ed 80 the ,@..r,a,w ~iiWurre 'will be reiianM ]ID, each. cl8S_S ithaJt defilres the ,o"t!jw . .At ["i(]n.'timfl~, tbe. eede mEII~ tt:u~ ,olci~

'~n!liw. illiJ;Ifi.\rn-:nt, :rm'flmlloo 'Win '~, caJ!l~dI_ - -

M~s\Sa,I~ IP;ass.i..o.~

h'l, !l;ibj'QC'~ ... o:ri(lniWd PrQU,Q:DII, i;(Iusists of ,~, SGt nf ,obje0tls '~t ~tlliml1!D;iC~ wii& !I!Iach othe.lt"_ The ~~ Uf,pToOb~,aITt_mi:(ig in an QlJje~oJ."ij;era'~ed l:E!lngu_a£e, 'tRem''td''fi.f.e, m:VoO,lves 'tffiae! :fuilUMDg basie :smps.:

ll. Cre:!lti!:J(g dSiS8e'9 'that detine objed:t£i, ,SJnd tiheir.' beha,1rijli~rrj'

2. 'Creating a'ij 0 ets :&o:m, elass rl!2:6muitiJilIIIS, and

3. Es;to.olisihrhltg' 6O'mlmunieatrO:rl ~OiOg oij1~ts.

Ob] ~ts oom'n:'l!l,ll ... iaa'~e with ons ,QnQ~ by :Eiendi~g and re~eiv.hig iDfb:n!!la,~ m;~ 'the same way as :p!OC!ple P:lIJs.:s messa:ges to iIJ.Iil.{l! UA1-"thiH. Tih.c, 'i5onG~t, i(}f:m~s..sa.g:g' :p0!gs:m~ m._i2S :it 'easier- to talk aJxm:t build.iiDg systems that ,~tJy m~riel or simulliate their. IIe::d.·w'O;r]dJ ,it-{t!Ui!!i~'~_

Copy rig hted m ateri al

ilJII:IJa:cl:

-------'

,

IO~~et'-S, have a li)~ ~cle. They ean be emat;ed, and d:e.stroyoo. <C~mHliWirimJti~D, with ~ obj{[ill;. is feMi})le ,1i3 :1.6n1' as "it is alive.

Ill"fj :Hefiefi.t' 01" oOP

• 'Ih~up mhe:ritp~:, we coo' elimht:Elih:!' ~d!~lIlId9:!l.t ICQ!lA]' and e::delllid 'ilb.e' 1Jl$i[!1 i)]f 9Xi8t~

ing Ill:iasses. .. .

., 'We; can :tiJmld, :pII~S 'from, tJie S1i:3RdR[ld w'O:rOOg moiliules that ii:ommu.'Il1eaibe wiIUl ODe ~nDthet p. ;r,aUlei' tbg h:I~;V~~ 't~ S~~ 'wrl~illg Ith~ ~d~ :f~aftb. ser~,t~lt, Tbi:!3 Jead~ '00 Sa;v]1il1; or d,eve]o:pm;e1ilit ,time ._nd ~her :p;r;oouc~ivity.

• !he PIm,cj!~~ of di3lltfl blding ~]p5l, tlwi ~~,grJ3Jmnwr to build ~elIDr~ ~~w.,am$ ,t]]~t OO'DD~t 'be. Uilivad.edi 1b,1I~Qde~ in other :parts of '~he p;I'(Igfam.

,. U; lS, :[Xl'S_s£b1e 'tc, have m1l.ittl:p~e iilii5'b:tnees ,o:f' a,_n object bJj c~st 'wi'tl1tQut ~y ~;il'tm'~

r,re\ll.Ce.

• I't '5;s jioMib'Le '00 map Q\j~~ in 'tha llIr'@bJf3l1l\ {loml;iiiu t~ tho!;e ~[i, 'thB' F~gr,~m.-

• It ~ ;e''([!'s,.y 't;Q ,pa!rti,~ion th~ 'w'Qrl{ :in, ,a pr.ojeet based! on. liJibj€dS"

• !.be d~'ta"'OeniteNdI, de$ip ~p:~\Ei.6h. ,@nQbl€l$ 'I;tS to IC~,ptIlI['G more dsttIJHs af ill Dlllii;bl:i in d~m~h,ble tb,r-:m-

• Ob:je~~etlkd ,t:!Y';~m:sJ oe~l 'be' ~~si~y up 1P',£Ild 00, :fr~lll, :smaU '~ ]:JaJ.'P systoms_

• Me S'Si.SiQ',e' 'U8~g tlee_b_ai,q~es m oO:Jnm,mrl~t:h~~ belwle~ lobjee~ ro9k_l!8 the ~niter-'r-ace '~~niP'Uli)mt with ,el{Jter,n;aJ ~,ysle:m~ :frn:ucb ~LmiPler'.

• S~ftw,Qm'ellcom!p:lef.'ci!t9' C:lm ~ euily mmJ!ogerl.

?{bile, it:1is :pos!:Plb~e 'til) in,Qorpomte ,a][ '~beE!e r-eatur;~ i'i!!, ~n ~J'bjec~C'ucien>ted sy,~tam, t~ im)m~ee' ,(ie])etllis ,on 't!he' 'type' ~ftJb€, '~ec.t lli~, the prt!f~fe.J:!;ce o:h;'hre ]1I~rnm_,(!lr'", Tlrn~n' ,awe' a ,DIIlMhr' of i's~~s that n~, tn '00 t~l!-dldOO, t(ll ~a,p ,s~m~' o(,fth~ lJ!2:n~6ts :s~u:cit lBJ'b{l1!i(J;" F"@lI:"

Copy rig hted m ateri al

Dmrtil.o;ping'il rofitwm'C th!lJi is ~y 100 use makes it h~rd to bvdld,;, It is h@,p:d, tha.t tbe ob$ect""O'rle[J)~] prc,gi'ammmg toO:ls wouM, he]1P m8Jna.g,a 'thls ,pro:b,[~.

Object..o:riented, ]Jt®~mmJiDg ~9 nmit the I'iGlht ,oF ~_nry lt9rtim.iliil" ]~guage" :Like s~t1.UEd ]lirrogrmmnmg, OOP oonc~,p~, ooD, be :im:plerf1~ted, u~lng lwngJUllges, su'lib, 8.iS C ,i!md, P,~aID, How1ever,.. progr.Blmmlng becomes ciU!.llisy,Md may ,generate 'OO:Iii.i~n, w~ tJie :progr,ums grow 'lm;g.e. A. ]RnguJage' Ul'a:t, is Elpeeia1JJy' de8~~uad W ~J1[])p().rt tb~ OOP ~OlIl.'!}ep-ts mRIreBi U ~"uoo,]" te ilmffilllmncn.t. them,

.

lII'he :L:3Jng)IJ~ should. sUffilI,lXll"t severel of the OOP tConce.'pt~, to ,c~m, thQt; tlre:y an, ebj,eel,..,

, ;a D' .... "- .... ..11. ...._ £ ;!l'a.. r-h' 'I!.. ~'i :.e.:;a.' _ ,,1..__ L'[] _ _. , ,

Ol"leEie.u., _€ifJ'&lJwffig" lLl]::!i31Ji tue ilieaJn.U'eswe-y- su!'VlJotit. 'Ley ~ !!.\iE!! !l.'i!!a5SllJI$ii,iL :mlOO"~ JI~ D'WnIig

i!;w,o cartegorie:s:

!Ii. O\je·el·ba,se!rll. prngr.a.wm:ing ]am_guagoG-S, and, 2. O~ject,..o:riented progr,ammi.ng LilUiP@P5"

OQj~ct·,b'il ~ed _f)."F"fJ'(Jrf) mjijti.rt~' ir;; th~ g1:_yl'!;!l 0':£ pro,gr~mming tt'ba,t, pl'ilmarily s~P,IP~:r~, enca:pa,lil,[i!!tillbn, .a!nd, (JI~j'e~~ inan:li.iJty" M~.o:r. f~'abJm8, that, are reqruired :~lJr (F~Je(9t-based, ]lIm~in__g Lna~

.' Da!ta, ,enca'~H~I_]8;M,((~

.. D~t~, hiding ,~Dd access me~[_d~m.s

'.' AUOOnHijJt-ic ifJ;iti@l~;a,'~i<m, a,n.d, d~r:-i,ll,p ~f otJ.jelllts '. 'Opel"at,gr M'\erloadi~g

Languages ilil3it support pNgroruJillllJling ~th obJ~ a__t"e tJaidJ '00 bel o'l)j~b~ p~.gr;a:mmdng ]u.gu81gE:s", They ,do not soppofit d.en;tanoe :f!Ind dy-~oorl~ b,m,d~·. A.dJ.~ i~ ~ Wieeill. d~e~ ~&"edJ pro,Fa:.m.mmg l~!l,giI:i~.

L-Imp~ge5 that w:pp~rt tl'l.ese fij~!time's i!t'tclode C++, SQl~~~, Object P'as~a],,~ Jav9,;, Thef'e aT>e :a: :18!fge n,1,tlm'~ 0$ @bj'act=:ba:sBd and ol!ij~t;..ori~]]OOd [I;[N:~~g '~~_~6", LIable 1.'1 lists :so:me ])@pul~l' ,~n~ra] ];JUl'JiiIll8~ GOP l~IlD{~e.s ~dJ 'Hl_e.k ,cllu.a(i;lterie,tics.

Copy rig hted m ateri al

ChG ruclil',,"-b.~.IIi Sllinul.u SnraHlu.IIt Q1iJ!r1I.!;I'f{~' ,['++ A.d.IJI Objui TIllr'OO fli!!1i1 i J(]Ova l'
'" '" C .... .fl'oI1.:;iltf:Jl ~1}f:a.{ .. •
EUu~ &t~ La!f!. :&a:m. :&tb .Elli:d'y Laotl!i ~ly hly :B1j)'!ih
[iI;!~ly iI)r ,ia~) " ./ .,/ ~ ,/ r/ ~ ~ .,f
:&I~ymi!irpilri..eBl ;/ .... ,/ .,/ ,/ ,/ "f ..I .,j
ID.Pi~ l!l!idi~Ji' ,/ ".. .r .,t. .r .;1 "" .... .t'
Ci!lnctl!l'Tlll ltC,;f' ,/ ~r. ~$ ~O~· ]]~r,m~i,J~~ Nil), N'D :f~ ,,;r
:mtL-elriilll[l~ ;(' # 0/ of ~(Io of' "f T" .~'
MW!1;.SPl~ No o;f' ... .( No .,t N~
Jmit~ti~~
GllfbgEi v' .t UI!l .... . .,< ;( ,/
C€llleNIDlii.
1Iik~ Smiirile
~~noo No p~~ N(ii Nil) $GL No ·N(j· Suppart: ...
Gimm~~~ No ND No ;/ ..t No!) N'1;iI ,f' !N'ilio
O~ Ul;w.air:l.t!i3! .... .,f ;,(' ,/ N!Yi:. .;' of ,.t ./
Jl"n,l(:ih
If hil'li!' ~f't-.Q·;!"i~n!t2d .l1!l!~geB
iI!* O~·,jj~ la.~u~~
.. . .- ~
(lItJhe"ru ~ ~i!'J'J:ti~il 'CD~n;fm'nal .la~~,b" .A..s ,!:ietii!D ft'tlill. Ta1b~ 1.1, ~U lugl!HIJgt!s :prolli~ fo]" ]Wiymsrphism and. data hiding. HlVW'ev,~ .•

,- ,- i : - . -. f· :,"'i.. - -- ,.;]I.- -;,..., - ::: -j-il." e..- ... jli.'tcm ...... iI!'~[j' []~fl:C!:u]"]"lfrlc_V _ ~:1I~rsismnoo and iml>1I1£!rici+-"·. Eift"el

m:a.1Ji,1 CI '1r.JJ.eJiIl y~ iIli!ii" p:rov _!!.!!~ i!,~","~ ~.~".,"" II.V - ~ - - - - .... it'" .b~"'" ~

Adm.andl. C++ provide' generic fad]ity wm.ch is !Em im[lPt~i\!'f!;~ COtIStNCt:. :r(o!i~' $i1'i.ppar.til]g re~~ .. Roweve.1"; pe.nisb;!n.ce (a.l(u.·,!!)a~s o:f:smrill1g O:bjC0ts) ls :['I,ot·fully iSU!P'PllJrted by IIny oftfie'm, In C! -ill-'" -J!k .~ii,.. - - . ..,]l, ~b - - - ,~t.,;;'" --- rr""lIlt :"'ii.r""Ci!it~O]lJ. Slt:il:t!l!l C9n 00 S;[IJv~d to dlis'k vet tthe indiv.i:mlumli

£!lIIIDBI .. !!II ,W!L'lJU!j;'l.L ~ Jll! eJiL~ .... CU!~~ I!i'~ _ 'ir<'!!-"r _ ~_ _ _ _~ _ _ - - , ~

oi{i\OOts 'l:aJ!'m.m i1JEl! 8.81", .... ed 00 an e:xtenL8il file. .

COmJt];eIld.aiUy. 0++ ia o my' to ye~ QM~ S:m~:]U.alk .~nd O~j'ooMVI~ C 1,3 JI~ru'S old, and Java ,oniIy,5 'years old .. A.U!h.ougb S~m.l!t]a ha5 e:riBled fur 'ID(f!;"e m~n two i:ll~f1~d~, ~t 1'i~$ s~·n.'iI: m£Jst. ,of its: Uf'l'l in. ,a_ :r!2.Se:<1J'ICh. enviremnent, 'The field iis 00' new, ~UJW{!"""{!:L"" .: tf.t,i:Jlil; it. aihililU!ki, not be jiJ1Ul)pd too baJfillU.\y ..

OOP' has beeome O[lC' aftll,e P~!Jgrnmmi[lg b~~J.m:~'S '~Oiday', There a:pfl!~~ to be a ~8:~ daal ,o:f~dtemenlt and. ii.IIlJte:rest. among' :Sitlfl.wa-t"e ~g]fieer.s iJl. UiS:uog' OOP .. Applimti!lili18 of GOP

Copy rig hted m ateri al

----- ....... 11,

~~e 'be,~ngS' 00' pm mp!:nt~n~ m .m1B~f ~M. The mo~t ,p!]lli~ avplim'~ o:J: gbje~t-' i!lriJeJl'~ed :V,rogIammillll, up '~ IIlUW ~ M!z1 'been m the ;!IRIIL oJ u.aet :in:bedace de:!!ign such as 'wmciU'W;5" HWlmOOs ofwifidowml5Y,stEIruilli1:8i'fe 'been deV\e:~ped~ 'ursing 'l.h:e:OOP ~eCJmiq,Ue.9.

Reall-'bU6-Jinl!!iiSi ~y;i!ite1lilJli S!![\e often mueh -mlioclie ~(Itri!,wj~ and 'i:IIJi'litaiili rn:all_jl' mote: ~Qjectca, with ~~m~lllca~, ~ttnlbl,]tes ari1~ :m.~~h!t~d~- OO!P i~, ~tu] i.irn, '~hE;!~ii1! '~'Pu, ~r,S!~p.ni~tf~~ ~i,llee' l't cmIiJ ,sim[p]Jity" iI3J C'.Q:m.JiJ,~ [p'[lo.l)!!Imn. Th~ prIOO1f:llis:in@t,~ r~1'" ~p:pHmtioj)ll ,otoop mili1!Kl:e!

• Re:ll~time ,s,ystems

• 8imwat;ioIJJ soil! modeJiog

• Obje~t-o:r:ientfm, databas~

• HypHtext, :b.)1Ii@r,[lIu!:iia ,atDG. l!n1Jcl4bmoct

._'.:' _.Ii; 11' rl ;j.. 110_

,l'IiJI. ,an.. frq.e.lI.'lL sYS!LGD1i.:B

• N~a[ ~twO:rlr.B ,ilndJ 'pa.r~dkl. 'p1'{i'gf.ammmg

• Dec~;siiO',m !5ilfiip],1ll!li:'t Qnd o:ffiCQ ~l1!oomatj!i;Pn systows

• CfMICAMlCAD ,SY$oom$

The! I~ik~bness oroo:p eD~O:lJim.e[]jt has elJiahl.ed tbe software iIlldust:.ry to 'imp.:ro'!,;'e' Dot only' ,~ Qluality of !ro11itw,~ systt~ms but ,:3<180 ills :prodiuctivity, O~ject,..~rimterlJ 'teclm.ology is 'tieriainilly' mangini' 'the 'wlW 'th£! ffi-oft;ware engm.ee:n t'tdruk." an&yz.e, de6lgn 8. __ Jimpilemet1t :B;Y5te:inEI>,

$i), SijlftWill'e' 'tell:bn~logy hss evw.h'ed '~b~uu-ih ,aJ series, '0:£ pheJ~ss 'dl!U'.inc the lut fi,¥of!"d,ecades_ $>' Tlla.e, :mast !P'D]l!uiarr 'Phase till re&eIDJUy 'Was "[[Ioeedl!.:ll'!e~o:rienJbed pw,~ (POP).

~, POP' empl.o:ys rnp-dCIwill! ]lIrogrBmJI1i.ng ,8/iP]Jtoacit wherE :HI pllobLem is viewed as ;iii, seql!Jence of ,t~~ to '~ ,ed~e<1. A. l1umher ~f f~n,~t]~nfj, ~ w1'it'~L;>.f:I, to :iwp,,~~,t, these talsb.

4$' POP' hBJ~ twQ m~o:r drnwbacb, viz. ell) data molW'e '&e€.];Y' ,!itrnuaJjd the ,ngnun and Me tih.e:r;e:fu,re ¥1Iilneraihl.e, 00 ,e~b_geli '[:8,usOO by RJzy 'ftUlctJilJn ln "tae Pi:'ugntm, md on :it d\o;es nM m.l!iil~l 'VW!;!! wi:ll ~, :['!lNiII[-W'Clt'M. [)'.OO\b'I.el'Dt;.

e ICQ(tiJje!lliti--orioted pl"OiV-:~lfl1.i1n:g (OOf) was, i.nR!Il!terli tb!J ;!J'va-oome '~b.e dr,awba!ilm (ilf the 'iEN"l'~ ,'~',j.,,~ ~-i~It."' .. ~-'Iti-· :t.~''''''''''''.''.", .. 'C'9"'---;-c- ',~ '~L'!lI"',iiiii\'il'fl"""";Gh~ I'li",:",a'~"",d!am "'''', 9i,ml~-~;' elFJtllE!nt ,IOV,:r,. i!I',," e.IIJI.P.~J9 __ ~ 1[.Ii!!R!I-',..m u-o p"'I!J';gI,am__imUJ~_.'t"'r"'lO!'9, ~ ~_ _ 'I,L!!,'" ~ ~ __ . ~ ~ _ . _ j~ _ ~ _

in, 'th12 :prr'!lJl;~ d!~I~lopmi[fD.1t. and bs. not aillow :ilt to :Dow mely aroand tllle sy.8mm. It 1!ki~ d!a.~a, II:l!lOm otllCi${iJjy to ,t!h~ fu:mij~-HOOli.S tillat operate on, 'it 'ill ill data. stcrulll'b:me called tCi~lIis.s6 Thl.s !l!lalmrll'e is ealled ,OOts, lBoo'i!psu,ia:OOlt"

e lID, OOP', ~,proble:m is, ooou;id£r~, ;El!S, ,Ell, oo]~cii.CItl of.Eli n~m.bl2:r' ofll!:otiJti.fls ,ca:Jfk:d: o'li~,h:~:ei!J~ Qbjel:l~ are Iastanees of elasses,

¢) rniii~':I~ati~!i]« data from dlil'ee~ ,;;J:l!;lt@SS 'b'y th~ ,p~;;I!!!~l is ~ilUOO, dMa .hid{J¥J'-

Copy rig hted m ateri al

§ Data, (lJi7iS~F@C1~il'Jn, :r.;e:~em to :pUlUing to,~dle:r' eS!Jen.'tlB[ fea'ttu:'tiiS 'w~tbo[l~ JJiIl£luding ba~lUld m::it8lils.

~ lnh!i!rim:~ ~El, thE p\ro~~l~ by 'which ()tbj~~bll ~f ~Pi~ cl$S!il .Ei~~W_~ ,rn,pe,rtiE5 ,~f @'bJ.ette, 0'1 lilllotJbSii:" dlJa~Si"

¢> Po&morph~m m-eatflJs, one' Uliru~~ m\l.ltiJple, f'ijimSl. It ,aU~w6, '~ 00 ha,¥~ m.ou U~~ ~ fmroti6;nl'W~lJii the s8l1ffiu~ DJ:3Jm.e in a pl"qgw-am. It alse ,:l!iIlIDW8 O¥erloadm;e' of O:pEmtors !in that" ,aD operat.:i.o:n can ex:lUWt diWe:llel11.t beh;;!lv1iQW.s ii!'li different. rn.:..9Wn~es,

¢:) D.Yn~i:c bimli,rf§ me-am, 'tlliiat tbe ~ode' tB£I&!ciatoo, ~th ill give]]' ];!WGredllll'e :iB DO't. ~W~, 'UiiJL'lH 'the tUne 'Q:f'the, (all at ~,~tURe.

~ Ht8'mgt p(J;8s,ilW mV(lhr~~ s,pe~~ 'the ,n::une ~f' me ~bje~t, the itut_me ow ,the, t~iQ;ttt (~~~'l ~d t~ il!d'ij~ticm to ~ oon1L

<::;> O'bjeIl;lHrie..1li.t.]~il ~~i~' Qff!ln',s ,S!I;nI'Ar,a1! ium,mts Q'!lflrf" 'iftu~ oo.nVm1I,t:iAlilla:l 'p:m~aJmmiDC: m~t~Oih:.~-,th~ :mo~t ,hm1pmrt!mJt ome being the reu~BJbil.iity"

e A:pp'iiC;![tiolllS ofOOP tei!i'tmology has pinec:J] impo:rt.anre'm. almost ~U areas ef eom:pUlcng m.cliU!d.i!llg :fea&,~time b~8i.S iSYLStems.

e Th.el"e ,::ve a num.'ber !of ]anp;8(ges 'tJhat i!fIllIllPort obj~.el]redJ JEMgramming ,1Ilall'adIigm .. n- -, .~--[" - -- - c-. - ",'I-. - -; ,- .- - C- ++ 0!...-..-.a1]"·"'1k. ill!1.d! ,J':aVLBL C-'++ ijr, ...... iL-.iDlillfliB ,BltIi, " ... .JiJ..] ~,~., B ....... · .... .i'-~

J¥'-o,p'UJ!;a.... !Iii~g, ~;!,~ af'e _ ,O]!y;, _~ _ _ _ _~ ~ ~ _ ~~ IL,I'I; __ ~ :!];J,Y _ 5 ""'J'~..!~~.1~

]~8ige todlay,

K'ey 'Terms
> Ada )- flowrm:art!
,. " ... sem bly Langu-B:~ )- fUillcti{lR ovee 11}[3 ding
).> bcttem-up [p'f>ilgrammin; )- f1lll1ictions
)- C++ ). IJflrb~1'l.' L:Ql~t!;'!t,:tiQn
> daRS-.f!'!i ,. gl~lJru dat{!!
)- concurrency )- hierarrhlcal elassjflcatlon
)0, data abstraction ~ inher.nt.anC€
" data encapsulation > Java
,.. data hiding ,.. late binding
.,. data .1ll@mh~1I'8 ). leeal mit:iJII:.R
,. dynamic bindj ng >- U!I:ia.-c'h!Tie ~.I:1ngu:tLg~
)- ellll"ly Mnding » member functiena
)- EiJJel '» mcs3age' ,passing Copyriqhted material

,. ml~th1Id!i )- open;. tl!'ll" over loading
.
)- modular programn 'l'lt; )., persiat once
) rt:I u hi Fll~ in hurl anc )- polym.1)rph.isrn
)- object libraries )r peoeedure-oriented progIl'llnrning
)t- O [}ju.'"t Pascal )0, ,r~ln;;.a~mty
.". object- based progra mTRi:o iii )- SimO'~i:I.
.
)- o bJHtiv1.! C )0, Smalltalk
)- obj ed -urian ted languag.r,~ ,. i'lb:uctured programming
)- f.Jbj( I ,t-<Jri(!! t~ Irn~W~l!p' ~l'll' )0, ~p-down progr&m:Il."Ji.rlg
)- o ~iec:ts >, 'l\ttbo Pascal 1.] Wlh;a~ (k, ,you tm~k ~rn' tluJ. .'rtuJjOJ~ iss.ws fa{!i~ t1i~ ,sfiPwa:n il1'dust~, t~f 1,2 Br,ie/fy Id~ilf8.1J: tM ~'ware' ~ool-[d'i~if't dur-i~ ,~ period. 1'91i() - 19..90.

'1,3 Wkil<f liS" proogd'IJn:~ri~ntYJd, progrnll'irniNg"? Wha~' are ita: mllIUl c:-.JW"NlC~'fI!,.urtir:e~' 1.4 .Dis~s an (jp'P'ro(j~h to :thtl' de.fJf!l{:)pm21'1~' fJf.p'ma~.()'rifJn/ted p~_~'.

,LI) ,DeBc~ MW tkt(i, are s'ha~d b, f~~M4M ~rt a ,p~W'e-6rie!ded' progf'tn~_

1,6 Wha! t1J ,o~je..ct·-o,rit,nfed /j}rogmmm~ng? 11~'W J8 U dt{fefient' (rrJm 't~ pro CediUn-'

f.J.i'rknt-ed progJ!'ia.rn.mii'W?

1.1 How @:r~ data and fu~tio.n!;. rurgan:uw in an objecJ-orieo!1red proRiiU.m:?

1.8 'Wlw~ a~ tk~ u~i;rue ~"a-~I:I' of ltl-ll ltl.Qie'Ct-oTk~~a pr-.f}fl,mm.~d~~ pam.<iteffl? ].9 ,Distinguish betu."OOn thrJ' fb-Uowing t4l'F1nS,;

(a) o,Qjoot-s end class:c"s

(b) Dam ahstmctio\!'ili 1i~d data ,e'lliflapsldarron. (c) l:n.kf'ritaooB' and polymorphism

hi) D;rnami-c b~nlt:ii~ and r.nessqe' pas:sing'

ilL 10 What kinds af a~~'ngt1 C{j;~ 11&}o~' .abj«:~ ~n DOP? 1 J11 Describe ~n~l;!ri~~' es ap:plrted ~Q O.()P.

1..:11.2 m~~ do. ,jr'QM m.ean by ti:yn4mtG b~ltdJ.ing? ,H1J..w ~ u ~-t!f~l fn OQPr.

1 JlS, HmD does ~~.(i-l'ie:nt-M appN(j)Ch diff91" jffJm ~bjem.';.~ed appN(lCh ~ 1 Jl~: l.ii8t ,a, ~w ,ilt&lS' of a1JphicMi.on ,FJ{ GOP tet:hoo1ogy.

ilJ.5 Stv~~ wh>e~he'r fke foJi,(j).'wJntJ, 8tgJem;e~ro ~F>e TRUE or FALSE.

~a) l~ pFtlrn:iW'e-Qriented p~ro;rnm~ng, rUt d~ta, ar>e' 8h~' by aU' fund~" {b) Tke 1,n:ai£n l~~kasi;s 0.( p'I"fJtJ~dH.J'e.O'F,ienl;,§,{i.' ,p.rog,mmmi~ U;, ,Oin oljOil',i:lh'mS' n:dMr t'h~:n an, d(J~!l.,

Copy rig hted m ateri al

~c} OIm of'tlJ'£ .r;trikir1lJ f;erUUFe& of ()bj~tN;"Or-ie1'l~~1 p~g~r~m~/!g is .me ditriei(ln oj p~1m inm o'f:!Joo.ts ~ktlJ 1'e:pres,e,n~ '/'iefj.l·w{)'f'~'d f1<IUiUe;fi.,

{d) 'WropP~J1;g ,up of data of ,fi.'i.fr'(!re,'fi.,~ 1:..):p&.'l3" ~n:t\r) ,ii. 3~11..gi'e u.~~~ i""k,ni;JW~ ,!';t8

,elWi.1p-!S,~lati.'o\!'ili"

{e} Oftill' probkm, with lOOP .i'l; a~ifj;~ €.i.lt'e-~ il. fl'l'~ ~ ~rn(;l.i'M d ~fM, .l';!!i'!ttef" ~ cha~ed. {:fl[ '~ker1t6~' m~~M ,r,he alrili~y [09' rn'US~ the dt]:~a. vatU€5 of,mw OOjflC~ by

(g) PJ!'Ji;ym,{JTphirm~, is' ~Jfb:=~LlelY us~d in impkmS'ntil~ inkiri~ance.

(~li) 0lV'8.,f~'·o.'I"ie'llJ~d '1yt'(JgWti.iN). ur.e ~xe'Cru.ff;!d om r$<c.A ffa~ ~er th(l!:r.I! COlli! t.'Ien~i(l'n~l p,r:qg.rams:.

{:~) Object'"or-re'ntM S,j',srema: OO~ sC!llJ;le up Detfer .from SJ1'uJll t(ll .larg~, m Obi{lr;t~r:}'ril/m:t'!IJd aplxr'@och 001J!.Jm;I;!t be u~ too croa.~ ,a.aiabaINS',

Copy rig hted m ateri al

I

Beginning with C++

I

Key ICo,Dcepts

)- C 'IIi LUi cla!::lse~
,.. c++ features
)to Main function
.. e+-. (:of!Jtll}'t&nts,
> Ou t put ope:ra:toil.'
> lflJJut GpE!':r-aoor
)- H cadcr 1ii1A}
,. H:etL!l'l"l'i! atate 1ItLen.~
> N :::u1I1espace
). Va.riab~
). Cascading of O]lier8:~1ll'5
» C+t p.rQgr8D1 Btrur:ture
). Cllent-servcr model
>- Sm,ltrr,:e f~1€, CNi!~tinl"ll
)- Compilation
". 1 JinkihS c++ i~ a.__n 'object,-~i.entJed pr;1!;,gnrmmiJll [i&!tlgtlill~~_ It w',as ,d'Q'!O'Ii2]Oip-~d! ibl' Bjili!liDGI 8tftustl:'u:p at AT&T BelIl LabttawHBS in MJi;irr~y Bin, N~w ,J~~; USA;, m, 'U:le ee::dy 1986's. StroUSitru~ an admDmr o~Slm.u]a6' and ill :strong' ,8;J[l:p'p(!~1' of C, "Wanr~d to I!!®rnL1ir.e 'me best of Nth 'the 19.._~~9.ps 9-Jld, Cl"€I!lOO a m.o:re JI(P'i""e:rfull~age iIID!J!t~old 5i!.1PiPOI:"~ ~,b;jted-(IIriente d plwJrr,a'm;~iq featums and sUU retain llii@l powell" and eleg'.s.nce O'f C, Th,e :r;esult was Of-+. 1'h~!~re, C++ is ,Qn, GXWrunon !QI'C witb ,a, mJ:3jor. ,a_ddlition of-the ~s construd fe:at!Ilre ,of SmuJJa6':[ SiR;Ce tJiie class was a m~mr ad!d.i ti. Ill! 11 tQ! th~ oldgiD,al e lllngaagD, Stroustnlp'wtianycahd Ut~nGW·'~ ,re with. cl~eB' .. H:gwe¥er'~ ]aw in 1968:; the l101lli1'l 'Wos ~~d to 'c++. ThQi ,iilOQ ,of'C++ oom.e5 &.om 'the C 'm~eDt Q]llemitOr' ++~, it'her,gliiY ,slIl;g:ges'i!:in,g that C+,.. is B.D, a~Qnited, (m~m.al]~) Vooo;,siQn, Q.f C.

:mJluilllg' the etu."'Jty 199.~'s tho: ~aJ:DJ,gIIl£1;g@' underwent a number ,mimpr-mreme:ntEi, Mid,

Copy rig hted m ateri al

10

ebanges, In N'o·'!,i'ember ]007. the i\N'SJlitOO standards eemmittee si:lJ[ui:!u."lliiserl thes.e' clt9n:il!l".S and added several :l1elV features to the 1,an,guJil.g'e speelficatlens.

c++ is a i5upe~ of C. MlJ3t of what we ,Slilfleacly l:'uUJiIN ;:OObOliil. C applies to C+T alse, Th~uf~[.e. I;dmQfji~ :till C J.lit(Igfoli!~fj a~ :alw [e .. + flIrugtta:_IDf:!" ]=IQw€"!t!J:'.,. 'tlhef"e 1IT>f!' a fe.....r min~r dirri!~[K"E!S, that w,u[1 pi'ce'Y\er!l,'~ a C :~rn,~m to run Uindetl' C++ oom:pilet. 'We' ahall see these difftl:ranoos later as and whi;lu 'they ,~. [~.EleQiJnta[\a(t

"ThAll most. Important faciUti~s, that C++ adds 0111. to, C alia classes, 1nheri.'t;.a:-~.ce" fil_ncth:m, ov~rloadil1,g~, and op~,ator iiJv(.':r]oad.in,g. Th!M:il1l features eH1ILbl!2 er~(JjJl:;ing of .alb.srtr.a~ data tne.s, ilnherit properties :from exisHn;g ibm tYlPes and sup-port. po]Iym..orpl'llism.. t~.'t€:!r'@by m~ C++ a t-mll,y' (Ihje~t;..miented Iam;gu_age,

The dhje~t=(l'rie:l1ited features, in C++ ,:lllww' ,progr,ammer,s to' 'build. 'I;ru:ge pmgJ'sm$ \vith c]a:J:it-y, ,~ten&ibili'~y' and >M~e oF.' mai'~'terui_]'a~", inc~atti!lg the spirit ;Hind efficiency [of C,. 'ftltr!' .EtdditiOOl of ]}£IW' :fem:t'l.ll'"Qs has U91lsih'nnBd, (~ :ih)m lit ~.£ii.ngu~ga that ~i;irfi;!n!tl':l fail,."lil~tate!il W:p-d.own~ structured design, 'lID one that. ]}1"(Ivides biltrom~up, ahj~flt-ori~md ~ign.

Applications, of C++

C++ i~ .a 'v~n;e;tile' 18t!(gu. f'@:i:" 'ha[uilHng 've-!:'y' '18il'ge ·p'~J.gr-am5. ],,~ is 5'~rlmb]e :ftill" 'virluaJly' aqy iPru,~in.g task rnel.llItUng development ,of,ed]oors~ ~mpi]erB". detabases, oommunication sysmm.:s and any oomp]@x, rnal~]iifu ;I1i:pptie&ti'lJ]l sys..tB.IU!S.

'. S:in.re ,e,..+ allows U$ 'to create hierarehv-related ®bjoots~ 'We Crull. buildspeeial Ijlibj~toriented libi'''{![[i€s wbich can beused ]u;ter' by many' pi'o.gr:ammeirS,

,. While C++ ~6 ~b]e to ma:p[ Uie rEal-'w~rld pro1Jle:m properly ~ 'the C ~~tt ef C++ giv,e~ the L£lI!Ug,i!.iJ1.go th~ ,olhl1lU,:y 'W ~t elese to, ,t.hl2i D!la'lilihl~··](!lvo[ dfltu.Hfi.

.. C++ ,p!'(!'grams aile 'e..1Js4~y malntaiaable and e:K~0lnrlab~" 'When a nG:w :f:ca:i.W"{l' needs '00 be· ~mpletm.e~ted. it is 'veIL)' e~!ii'y '~if!i :I.dd! IbO the ~xi!1!ti:riIg etiL'1JrtUi~ if!!f iI_'__11 [Iibjectc-.

·Ii It i.s'~ th£Ji~ C++ ~,mplQm C.SI$ ill ~i1Qra1-'p~ ~'in the:J!L~ ,fll;ilwa

fin~lude ~iastre~~~ /; includE header file

using na~s~~ce ~td:

Copy rig hted m ateri al

int j,Jil.'inO

~

return 0:

}

I J f=nd oj eXl1f"'.plf'

ftoGRAH 2.1 I

:h-ogtaUi, Peatures

Like C,,' the 0++, progr:am_ is a (lo:n~(jn. Q.f funetiues, Th~ ·aibov'~ ~lQlm'p1e I!,QEttai!ns, 'onJy ODe :I'!mctio]l~ mMoO. .A:s '!i[St:llaJ], '~OOUitiOOl IOOgins at mainO. Ev!2:r~1' C++ !llli_:l~O~ mllSt. have !EI! _aimO. C++ jil} :6 fr.~IDQ1'I'D liHIp<E!l;ge. 'W~Ul8J few i~Ceptiom,~ the 'Cl®:[JllfJiJle:r' 'ign:o:re:s ,carriage returns ,:!mdI whlte spaces, .Uil:Le C) the C ....... slatenru::lIltis ibfmninarre with ~iOB.

G0-mmeUJIi'S

C++ in:lrnlliuoCli2'.B;E]j~" ,oO'mm.G-D:t ~'Il11'bo1 11 {d(Iluilil(l Silash) , Ctmrmli!mits ~1).ari, mtB a d!.ouibl~ Sl:a.c9'b. ~yml_~@1 oel 'te~ate a:~ t~e end of the line. A eommeot mary smt1; RW,ywhere in the »i·~, • .f)J~~ 'W]~ aibevet 'rgllQw~ til the e]ld of 'Mle ooe is ign,Qredj, Now tbitt ·th:ete, is ·t!!o ('Iooml' s-ym.bol

!be do.uib-le 51aSb ooJ!tL.ltlelllt w basim.lkt ,[Ij ~ingi.e Me oommmt. ,Muj:r~Ilme cemm1£mts em be "!"-yrittm as ~llll)!wSt:

II rhts is an €XOlli'p~>t Df

II C++ pro,grom ~.,~ i,~ l us ti'IJte I J Some of ~ t.s Je'O'h;W'es

l~ 1rh] S 1 S ~n ~i(iLJ1lp,l e of

C+ot' p'rOQ ram to i n ust !"ah s I;IIr.Ie of ii t.$ T'eli!.tl!.!l'f'es:

*1

,\\f,'e mD use eiiItJh.er or h-inb, :styresm our :progr,Mn.S. rSin..m tthis 113, ,:!I_ 'boOk 0111. C++~, we will. 'use 'elm1y ~~ C++- style, ~iQWi;fve:t'~ '!'em~if th@t w.e' ,eRn rn1It mEie:i't a If !j'~yle mmme:[!It witllriJ] 'ti1ii.e~ 't.e.Kt ola. ii'Ii"f.~ftrI, Hll.EL .ro-rexam~l~- tledotllbl"-IAtlh ""!o"'rtn'm-nt 1l:~i4 ... -'-.--;--41110 ""'he ,-- -iLllI1- c

--._ 111·"'1!:>··'"....·~ -- . - - .,F_. ~ __ '!i'i!;i 'I;;_'I,!\ __ e~~ I!i,!'I;;ll~ __ 1,;o ~ma~e;l,"

as 5: he wtl, belo.-w;

r .

Copy rig hted m ateri al

Ourtput Ope.mJtw

,)[,:be illill1[y' riateme:oti.:mi. Program 2;,] lis. an output statement, "iI1]j~ st;aOOm:~nt

0a'U6~~ the str,iIrlg 1ml 'q'l)a(ttcati.O<ll marks to be rlis,play.ed, or.u th-e $i~e:Q .. Th:L!1j, ~tatement irlib"o@uces, two JrlEw C!-+ 'r-etd.li..tN~. eo:li1'~ an.dJ «. The lcte:a;tmer: cauL (p:r.-MD1.lllredJ as 'C out'~ is " predefined, Qlij~Ii,.'t tJl~t ~re~~in~ the, sUtJidm--4 Q.1Jt'plJ:t Btre~m, in C++, Here, 'the 51~M.dittd ®UtJJ1Jlt st~~ ~re6en~ 'dle screen, n ~~ ,anso J]:clsf5.1ble Ii;:Q redite~t the ®ut]Jut to ~tJ!te]' 'tlllt.put ~ev,i~. W,E;!j shall ]a,'ba'I:" diSt:ltit8Si 8t[\~am!j hiL d-etajJ..

The 'O:(!!eml.o[" ,<,< is ealled the in.oorlior~ (ill" Iud ,w ,o:pen!L'~o:r. It:irtserts {m Bends) the OODiOO]]:i1s of ithe variable ,on its ligbit '001 the' objee.t 10]il its :Ieft (Fig. 2.1),

n_e, o.bject ilJOU!lt has 8J 5imple rn:ted~.ce'. If 5'trirt-,g repreeeats R 5tring 'variable. then the 'tb][ow:iiQg ~tBitement wi(] dffi[llay its ~®nten,tg~

y~ ma:y' ,[\et:!llil th~~ t'he O~81Ww -c is the bitt-wili*!' leR-shlft ®peil"a:oor and iit C'.Em still be used fO'II_" 'this purpese .• 'This is an E!'Narnplll;!' of how QJiLe op€Jrs:to'l" lean be used ]'0[" ditffhnrn,t\ ~'fPO~. d-e'll!:fi~:ing Qiti. t'he ol):nlex,t. This concept 'is ~lUiJOWlll, :a~ ~erot'(:!!!" Q~fJrl.trHM;U~~ :(!__n im:po['ltaot aspect OT:llOiymDlliliism. Oper."llJto;r mlierload~Ilg' is diseassed in dctml EU ICh~pOOir '7_

Copy rig hted m ateri al

BBg:i'nn~Pi9 w~th C-.r+ .==~~~~~~~~~ ........ ', 23

'The ,instfeam. :fil.e

We have us-ed the foUowing ,11m dude direetive in the prGgram:

This directive 'C8,~S~ ,th~, ,pre])rtIceS6Q(f to add tile' ~'OD~'t~ ®f t~e iU~j'~!:'>ea]ll file to the IPr;;Ob~m- n oo:n,ta;;n~ de;t:.J::n-atil)rtI$ fil1!1[-' the lde:ntifle:r ~}IIU.t and! (he ®peta:twr ««. S!i]me' oM 'wmimls of C++ laSe :a header 'file called iootremn.h. 1."hj_s its (file o:fthe o.1t~, b~;tnd\Woo. by ,ANSI C++_ (W,e sh'I)'ImJrd ~Ee h)..'illnam_h 'if-the compiler dees 'n,01;\ $l,lpp:rt,AN$l'C++ 'fieatu:roes.)

The, h~ad~T' 6~ mg,irn§!m sb~U!lld li(j' LTilriludllNl. at th~· Ixi~n[ling' Q.f aU W~~~s th~lt ~e mputtoutPlJIt s'i:;at;emeJ1l.is.., Now that t1'1Le, iliam..in,g eo:r.r'!;{;rtlilions, M !hnadsr' :il{lS! ~y 'VQrY, So:"me 'im!pl,ementwtiOM use IDBb"ea.m.ibJ:Pp; yet others li.osnarm.iImxx. 'W6 mast md.m_~ ,~propri,iim header files depeJil.d..i.ng on the 'Oll1rte.n;t5i of the progr,am and. impiementation.

Tables 2.1 ami 2-.2 p.rovide lists of C++ standJarii ]i'bnITY header files that may' be needed in C++ :progr,Si[e. Thoe h~der files with .h E!Ktensioo are "lO:ldJ sty]e'''' ilea whlel~. sbould be !J6-erl with old ~'Qf®:~iler!:L T8J]~E' 2.1 9J60' gi\''ES lhe 'ver.9iu~ @f' thEse 'files th9Jt a.l1Q\lJd 'be' 'ooed 'with the A_N~U ~l.Ddard ctm:lp.ii~em,

~-~r.: ;1:;.." ~

Irg_~_,.~

1',B!ld.¢i :2'.1. C~mrt'llO'n~y r.!ae'd ()id--R!~yie ~(]deF jitetj·

, .~~--

<:f]Qatlib~ <!im-t§l,h> <m8!~h_b <ii.'beU01. h )0

·Co~·~'l.n.J.!'j!!oJ!i!! .: tJ''''·· ".

.- - ----:-. ~. - .. ; It.:r. .

Cant..aiJ:ls m8lEnli!l· ,a:nal inf.o:rnJ.a.tiO:IrIi :for adding: dica,gn,ostim, ·t.billll aid progrillll"i d.cliuggilDg

GO:l1Iitaim.s, fmu::t.:i.DD. pOO~Dt:~ £0[' tfUI1I,Ct;onB tthElt :test ~a:!'":IIiete.-s. :fbI' Iil!!rte.ii:i. p~rn.t!\!i; and! :functi.on p!'!litoIrj.'!P.!I!'.!3, for functiorDa

that !l:1iID !be '!JIsed! to oonverl !owenz:ase ~~m '~ iJ,J!ppe:n;:a.'>-e ~.etWm and 'vfee V0ts~,.

Co:~tai~, '~'he 'fi.o.[:I,t]olt"lP.o<itllt ;9,i Ie lilm[t.?:!, {it' the $Y.3te-m. CI!l\!'l;'~f.i'~n8 rt.he mtegral size ~irnj;~ ~'f the ~tc.m.

COIlita:~rnl!l :ru.ncl:tQI!I 'pmbDlt.r:pes. fur ln1i;plJ-i. ~i.'b:r~I'). 'r1l,lnrn'i;;i!1H!L Ool1b'1!hlL';, fl;!Jn~~ilJn prcokJty]l!eSl fur tt:he !]ta__l1gaoo mputloutpul~

. ~ibtilil~r- fwidml:l iIUild :irucniliiati1:!I11. used by them_

Cafl!.ta1nlil fUfljct5o:_~ ]U'ot~ l'Ciol" !i;l(i{I~L-veJfBiOcn m:nuru/beg iI:o rteKt. lE!oct to !l'l:umllle['~; m!i!'IIio:ry ill~iuD. :tl3!DIilnm 1iI.1l!m~l"I!j, ,BtLd varioos other lJl't>ID.ty funm;j1rtS.

Cfm'WDS J'unruOD. Jtwl'>ol:J'PS,s f:or CI!lt,yle :s.m.n;~ proces.sm;g l'l;m.etiQru;s.

<:tt'];I:i!!!:b· <e'I~ts> <'tmiP.t!!> ,<~!t'~io:>

Copy rig hted m ateri al

..

T,o.lble 2.,:11 (Conhrl)

'ClOOltS.iIlS :fu_ll;!,ct;J,Qn pl'!!rt:o~, and 't'y[;i1!!!S 'rCJil' J'll::,lnip~l~tmg ilh~ 'ti.iilill{j; lilDd. dll:l'OO,

,<iostre.i:rnli~h> Cootrciins :funotiilll p:row-lijr[)e;:I, -r'0]" tbe' standard input and -.ti;l)stl\etllm>

$ta~dI o:l,lt;put mnit:tia-ns..

<i~man:i~.h._:> Co:otiIIiiM [oo.£tioo ]m)wt~, fur the stream rn~;nipuJi;!!;~rs. that ,<lIl]([lW.n:ip>' eD;lIihle· 'rormatting ,of e~a:rm:5i ~ d~d:(l!-

·<f$~~n:>· C!M1tain:5 :F~n, :proW~, fnt funer.ioillS UfilIlil ·pari'i!!r.m input d~k>E!Bm:;" Ji»:rn, fde.s on, d'iisik and {~l[n'put' 'W ftles 'Gfl dtsk;,

&.der Ilk '<Uitili~p

'~'; .:disb, ~dEq,ill8> 04i;UiaQ-tl.0>, <sBb~ <ItI..ilfK>!, '<s~iWb!' <b.itscb

,~rmlC;~O~

'iI"h.13 headar mB8 con;tai:n elaases that im:pt8meJlii: thE! st.and.aJrrll ]jbi"tu;V wo.OO:ifiers. ClMlt(UmQ[,8 8tOri.l data dur:i.u~' a pru;gt:amtli'g Erll(lll:;ution. We WIl)US8 these hea-dc:r lltu!!I :iD CIiI_8ptC:r 14.

{:Il:mf~ elasses -il'fidl fiitw:;Uoru; used by,a]gorlthms o-i' th.c standrurTIJ l~r,ill'Y,

COIll,tillItcEi classes ilII.n~, flUldwthS US!2il.1 hy rb!ii standsrd libt~ry tm. uilleootc: iiiIiIc.ElfL1)rj' 'ro 1111(:, stllfium:rd :Iibr.u::ry eentamers,

CiMlitEllinI!l d.~!i! :riM" !JlIj]ani:p!IllJOtin;g d.a!tiI in t!he stsmd!srd, librHy e oIl;t;nUlJ.c.r.&,

COOl'm~jlS funetroilS fur iiiIlI!ilDij1fljiu~l1j dtiitlL in 'tH sltaiiJ,dMd libfa:ry e O-1'1'~a] ne'rs.

ThC!lO hC1ldifll' 1'i.W:s OOWlL'1:.a..l:n elasses 'Ui'lut ut{J- 1l.I8(ld, fu$ CX(;{,_o.ptlQ:iJL handh-~~,

(;OO'!f~a:j)ml ~~ de~r!W,-O(!i of eless S-rnIl_g. hm !the 1J1l:c[i_IJ;da:rd library. D~UB8ad in ilJhlipteF 1.E,

~PJl;;pj'Q~ function. [JlIotQtype!ii fur fl;liI!!J;:~-O'na tl!-i:!l!t pedonml, 'i~p~t tEI-oo:DiJ 8tcin~ in [iIlLmm.;Q:l)" and iJutPl1lt to 8tcitng_S in ~;Q:I'J"-

Cllm'~~ elasses and f1JJlotiollS :Il-o.rmLliiy llilCdI 'b}' S'~ prt!(\Ci!iS'· [n:g m p'ro~, data in the 111 8 ll.'llW I fcnn ror dil1erel'lt ]!1DgJij~, (e,g., fDIOOl.e-~ary ftJ tmM:St s!M1 ing is ~ti[i~! !iih~t,iU:mE!t prt!8M'i!!:B.'liioifLj

~oo."

Co:ntsi!l1:5. a alaas for da6niiDg the IUilIn£Fi.ciSlU dalS! "typelimitel iIlilli. ~;[ie]) O!)wp~t.e:i:" iI,1!L'Il.ti'tlrm,

Co mt!;Uos classes ,fur ,fWiL4ffil.e: t)'Wt!i j,dOOlllil.Ca!t5uifi (filI!'Ult.mini!ri.g d~r;a 1type.51 :(l!t, e'W(<l,l,tiollI tim~)-

_.. .. It ........ 'O:, .... o~ ...... l"'s; 1:I.J.5-'I.I.IJ-I.'L.1Jl.UI._,;I

Copy rig hted m ateri al

N,---~,",---,-,~a

;unesPI!-C'!Ir

:NrM'IiiESl1!8.00 :is Il new' OIillOO]it mtnrd~, liIi~ 'tJh~ ,.ANSI' C++ standards ooIllLlDittee. T1in.i6 ,m,e:f.hle_s, It ~e ,fOr the idanti:fiem tbat ~e used, tn ,:}, (IDl!I';llm. For mm:g ,the identifien:l, d;efinedJ in '~ I1aJineiS,IPBCe iBcli:qJe 'W€ IDuB't inelude tbe ~' drirerlhr,ej tike

Rete~ iStd 19, 'tJiIe namespare 'WheJ1e ANSI 0++ ,8t~andaro class, Ubr.ari,e,s Me dJe:L'ME~l AU ,.ANSI ,C++ progr,am.JS ml1lElt m_d11 d,(i' 't!1Us ~h"f!;. Tb&s wi1f1 brin.g rill the id~tmgm dlefinedJ 1m, sid to the elll~nt ;8"lo'bal seope. UJS[I!I(I nd. :namespaee, Me tJIe new' b~ of C+ ... , N,amE!5.1;r~ ~J:'e ilis.CUe!SOO in d1eta.il ~iD Cbapbe:r :llfk

R~hHo 'l\7e of mahl( )1

In C++ majjf:ilf" :retlirn~, ~ i.n't.e<N!!i," '''~e val'-- - to 'the (!f~ra'tinOf :!ifi(6itl!!lii]"l_ "rheref1:J:n3' 'elI'lWi"jJ'

• -- :I - - - ~ - . -~ ,,,.... "'1;1' l" ~Uie -". '.r"'- -- ~ -y - -- - - - - - , "".,;!'

main') in ....... · """ ",,'ll.. ~·I-h~~ "' ..... 11 w-,joL. "', '-;'""~_ .--_- ~ lO.\ "t" !i. .......... ,,,. ... ,t- oj"it'iI,..,~~,,,,,,,, ,ri, w~i!l:l"" iJI!f:" ,!Ul '9I.':t'ilJ1l"

. ___, 'V"'F Q\~;LV~~1li!; ..,MY! Jj",UI Q ,[""",lU.iE'nlj, J rn _a,~~..." I!.!'~"'-~Ji!l!,,", '"" - --- D _ __ _

Milr~,~,OOCi)r- S:ii'iOO' ~mnO ~t~!'l'lli:p:__n ll.1tJ~ef '~e 'Uruue. 'fle-~~ t.l'-'~e f~l" m;!;ilin() i.e; p~lictuy spacH'iad, as m't. N'ote 'ttha'~ the .clefau]t :r-.etum type 'Rbr an $lJ[i$i~nH in, C++ i~, :lm:L The r1}no;~ing :ma1n without tY"iPe and retm:n 'Wi[I:run with 8J w~ng.:

Ii' i!!' ;;;; ;;;; .. ,~

}

'[et us evn@der a BlIigh(Hy mere ~m]Jiex Ct+ P[lo.grn.ID. Assume 'thait w,e 'w'Ould lme to :~ei!id 'tW1:I numbers &O'm the k£!~d and display tJbcar a.vemg:e on. the sereen. IC++ Sota:'beme[]j~ te aecompllsh thfus ]5 SMW[), in Progr;am, 2;.:2.

f 1 oat 1'I1-,1n ber1. II' ill •. er , U"11. ave ra 9 I;l ~

f rt lIJo:!fn{)

[

(Coold)

Copy rig hted m ateri al

cout « 'I[r'lt~r'" tr.O nUfl'lber'S = '!; j I pJ"~~

C i n ;::0-'" numb-E! r 1 ; J I Reads n,uma£;' rs

cin 3~ numbE!r2; 1/ from keJboon1

~um = numherl + r.uMber2~ a"'er"(lge = ~um/l;

(out..::...::. ·Sum = ..:::..::: SUIr. ..::: ... -\0":

(out ..::...::. 'I~v€r(!g~ ... " ... " averi!lge ":0: • \nJ':

r-~t ... rn 11;

,PR~ It.AN 2:. 2

IEmlt,s;1!' biD Iflwb B'r1i, ~ 6·.:5 /' • 5

SIJJIIIII 1.4-

,1!L'i!'~ r-a,g'~ iii 7

!]'h.e, :pmgw'.m.:m. '1.li86S, faur 'l,i'jlii.ria'blea :n.u.moo(r'l, :rii:!i~,mibEI1,~, Sl1m, ,and! at'lf€!IL'1i£iEl" 'iL'.'b~ a['.il!I deC. aNd, U 'Ity]p~ 'Ooilil:t :by teb€; staiem.c:nt.

Input! O,pemmr TIlle statemsnt.

iE;, an ifll,]JIlIt 11:~te11tH!f:lt and eausas t"h~ :progr,9Dl1, t® wi!l.it :ro:r ili.C!I rt1~~ to ty:pfl ln ,~, 1"l1!rnJiool"., ~ Il'jjjjfitl!el~ 'kleyad, 1.0 is ,p1!~oo in til:Ul' ''I,1'Qr.l;ab]t;!J :nU!rnh~l" 'fh€: irl€:i;litioo!' ;e~!I!iJ (preneuneed ,re :in.') is a ]l!ii."ede'MnOO, llIl'bj'eet hl C++ ~la:t C!l1!n'1!Isp!!)ud.:s'~ 'iful;! .standard, inpu,t.:st.l"e'.B..rnL ~,this ~1ll"lB,a!rn, r-ep1'>esellw Ute ~E,~r'bO~-

The operater »» is known as extroctWll. 0'1' g~t {'!1om operator, It e:xtr,acts (0[" tdef3) tJlI,e vlllut!, from 't;}W :Jm]ib~ud ,uno n:g&iJ~s it Ui th~ variable 0:0 its ri;gbt cm~~ 2"~.;n_ Th~JS corresponds to the, famiLiiar ~) operation. :Uik.e « , the ope:r,BmJ' » C3naiIso be 'llV'erlofid.ed.

Copy rig hted m ateri al

45,1$

-~=~~=====e 21'

easmdiIag of' 00 'Operaton

W'e Elatvli;!! 'iU$ed the ~~~I:ln O'jM'rtUQF « ro[p:~EIImdfily in the' loot two S'tate:ll!l,etd~ ftlJ:' :prltttl~g' results,

'6m:t aeniIJ.s, the ~tting"'SUJm !!!!'I; 00 eout £lIod ~1~1:~i!l(JtlrlE tlU;::'Vl1ilug,ofslllm, Finail.1,Y~ it sends the -newline chru-at:tel' 50 that the next 'uurlput win'~ in teba n~w ]~, Tn£! mwtirple. use of « in ,one state:lilie:nt is caUed c~!:i:cQ_4in.e'. \'Vhen iW.SC'~dl!tlg aJl.L output O~BLOOl!"~, we ~houldl, ensure 'D~El~Sm'Y' blank s]llaces betw,~, ,dJ&r-ent ]tems. [JSml' the ~c,adLn_g t€chniq!l~, '~'~t

,t, ,-' 1Io''-''jI.'';' --: .... ~,"" - n i"-A, ....... m'l.·,ni!!d, """', :~Uows,:

~ iS~,...;mif!I'olII""" i!:iIi~_ !.I'I;:...,.". ",J ""'... _ ~ _ _

,CIOil!it « II Sru!ff! =: • « S 1;![1lI ~<: ~ \1ilI-

« II!Av!!!!iI"I~g@ '" !! ':;'!l; ~V@iillg@ oOO! "\n·~

This 5£ ml{i: statement hut profld)e;s two ]m.es of out,PIJl'tt" Uy.ou wallt urdy (I[ije!! :li.lne of !i1I !il£]l uti ,too smt€lnl.€l'llt will 'oo~

ceut «« II S um =: • <:<: S;'UITi <'it!:: II;, II

« IY A:venge =' II <;~ ,~veNge 'Q< I! \n - i

Th~ values are iliJ.tSs]gned from left to right. T.liu,at is, 'iFwe key in 'WW\O v,~l'ues, :say. 10 and 2;0, then, 10 'Wi][ be ,SlBBignerl to nymb~], ~nd 20 to :num'bGrl!!.

Copy rig hted m ateri al

12.5 An 'Example 'm'th C~

OJil!!i!' ifJfdl~ miljor f-eaLmes (IIfe,+-+ is. 1;':~~Hes. Tbe~r provide iii. method !Jfbll:Ddjng roge her da'la iIiilDJa iiunctBOllS which. operate 011 'them; L&e stmetures in. C, elasses are W:;~.I' ... defined data t}"'Pes.

i n Iude. ":1 II 5 tT'EiUTl""' U~I"9 ~ pa~~ std. c 1 a. 'is. pn r-s on

~

11 bl'li;;~

~ClI I a F.! .1 ta {Vtt d) i Io'oi rl d hpl ~>'{ "Hi' d, :

~ ;

v~icl p~~ n :: ~e dhL~{V d) r

out ~ '"[nil!!:!1 [F~~ ":

1 n >:> j 1I l1e;

tout ,~ "Enter ag .... ~ II j eln ""-' agl'!!:

l

v 1~ p~r~ah :. dl~pl y(~~1d) f

ou ~ II \1'1 Na.me: ~ ..:~ "a~i

COlJt ~oC "\nA!}e; "":0:: a9~;

::li!l!T' On p;

p .~e.tda a 0 ~ p .UlSp' ~O~.

Ccpyriqnted rna nal

''iF!1.. . ..:iI. ~ .. __ -...., - ... -- '"', ,o!j, ,..,""" .. data ....,r: ,~:J1e pN,jgmm 'll-e;J!une.s :pen""",n ,ii!I~ G :r,., .... ",!, '_ ,~'~ w'

tt;ype el:BiSs. lbe clMS pen.Oll, :includes two basJc data fi:ni: ltems and tw'o fu.n..mon '00 'Dpe:rn;te' on, 'tfualJt d!ata. Th~~ fiLm.cti.oD~ are ~ed :mem'tJ.e:r

I 'lfUDCtiOM, 'Nl~ :IlIlQiin.'p,:rggr.a:ID uses 'pen3o:m. t.o

..._ ~~======,#7 dE!icl,a:r.e 'YB!]',i,a:b~e$ !il!f ~,ts typo'", As J!ml!Ltii~d out

earlier, elass vBiriab]es, are 'ilmown as obj'm:-ts.. Here, !PI is iBiD ohjei!llt oJ t;ype 'person. C]Ii:SS obj,ec-ta. are U5'OO 'to, inyoke 'the mn.etiiJJiliS defined in '!t:ha't elass, Mi'}lIe aDoUlt cloi5.ses, ,ad Qbje.~tB lis, discussed :m. Cba:p.~ ~i

Erlitel' iN(J!!fiI;e: .F!i;(!'!;',~J"I,der En~cer A"c:;: 30

N!lilIiTili!!': ~jiI'Jd'-~iI' Age; 3{l

cin can read on]y one word. and there:f'O['f: ~ OOImot lliSG' :nQ:m..~ mtl. blank spaees.

As it. can [be seen fr.o.:m the 'P:rogr,am 2~,3, a typieali Of-+- progr,am, would, ronJtam rOUlir :see~ioos as MOwn :m Fig. 2.8.., These sectio:ns may be [placed 'm ,sepamtE codle files ,and t.hen C®:mpiJed moope:nd.elllitly 0:1." jointly ~

It IS $i, common ptactice til ,crI'KiB'WZe 8. p:IIogFsm i1lI;oo three separate files. Jr..b.e' class ~ecla'f.',Qlti~IJS ~j:\a F!JW:l!:ed. io ,Sj, he~d\e:r :file' .ruuJl 'the denni.tionB of member ftm.ctiflD:J go '!into iUtotheJ:' ifiJe. 'l"Wi!3, appoo.ad't 'eE£lib]es dle [J~.er to aeplttarb::' tbe abstract ~fimtig[JJ

Copy rig hted m ateri al

tljf '~Jite ];n!t;e;r[aoo (Cbl~8 de5ni tio:md from the bD.plemen·t.aJ1dion details (member functions de5mti·0JiL). 'Fmailly ~ ·the main pngram that uses the dElls'S is plaood! in a '~bi:rd file' whlrib 1Ij1llcih:a:des,'1 '!!i.e :prev'wiruS t.wo rue~ ~5 well as any' ®"tliler f]~~ :f.oeq'lllil"1e~L

Thi.s iiliPP!i{J;QJcl! is, based on fhe OO[lIi~-eli't of elie:rJft-:renrer modc[ ilJ!S ~ iu Fig. 2A" Th!2 elass ,(ieinition. :m.cluding t.h1i!l me'JDl:i€:[" :flm.ctio.ns GillltScw·te the SeNer '~,h:d ]}rnvi~ ~r·'l.h::&j, W ths :main progr.j;iJm knewn as client. The client uses th~, !iif2n'~;r througb ,the' public ioteFfaoo of 'fibe claslii.

Cliont

:LlilIDe C ]Jro.gr:a.m3~ c++ pr®grm1Ils can be ereated using anry' text ediwt . .for e:mm.:ple~ en the U:N~, we can 'fl,!iJ59 mar ed te.xt edii:~ff[' rrtJT. 'Cf'9QJting ,~!i.ld! ad'utiltiQ; 'tt.i~ seurec eeda. On '~e DOS :sys·fu!!lln. \V~ CaE. 'I!1SB etlii.,fi. M illlY o~ edi:bar £iI.v:e.i~9hl.e er a word p.i'OOfl'SSOf' sy,s!f;e.Jifi Illf.i:d.er n.OO1L-rlOC([IIU~:[JIt made.

Soone :G"~~mf<l ,6Utlh. as T~;b!l1! C++, :p:n:lvide.£liD integrated !l!lf.lrviro.1lfi1I(iut. fnl" d~veioj.lin;g and. ooitlng pii:"!IIIgnu[:l~, .. Appi"!jprla'!e~ mnn,uli11s shoulld 00 'DUii~Wt.Gd fli.iit' rompl~tu dL'ltrulis..

1:he 'fne name ~hguld ha'!,l''I;;! a lP!!.'nper :ffi Ie ,g_d.en2iiitilil'i! 00' i fid'~Il.:;!;l~;g! th~t it J~ a C++ llfi1gr'.a!!i"iiI, :I]rn. 0++ :i!m.pie'ManrbTLt.i:OJlcS, usa !l!Roollsiolls sueh as .e, J~~; ,001 .cpp and .. ~. T!I1:r'bG C++ and Borland C++ 1!lS12 .e fur C progl"B!ms and .,e:PJ!' (C Plus :p~:tl.S) foJ' C+,* Pl"Og;r.lll!Dl:.S. Zortcoh. C++ :syst~ uses .~. whili2i '[]NIX AT&'il'.' ~.on uses. C k3!p:itrnlJ C) ,il.ndI .iCC. The O~.il)ting sy..slem .ml!l1l.'ll.I.:als S.h61!l!rl be; ~!ll!r.I!su.]md to d~t@'l"imjJl'II!I!I th~ pf.\O'p{ll" tii~ [Jjrull~ !ImIOO:rIIsLons to '00' used,

Th....e iII'[IlJICIeSS i11!f'cn(npi~'iir1g .~!Ild ~illlkillg' a!Win depeu&, 1!.!l.piiiil1i the o~"Bltilllg I!iiYliltetn .. .A f'E!W :piUlpu~at; i!3~'Si~Iililt'ii~ ,[;iN lI~e,l,ISl:i~d. i]\ thls ,B!i!Et:l!lili'iL

U:Ux At' &.f C+ +.

~ prOO~3S of i.m.pl~lImmuo[JI of a C,.,,.., .progr.am under UNIX ;S similar to that of.a C pwgam,We ~'Id '~e the "(}C" (!J!PJ.Ie~e) oommRILd t.o',[!~m:I#i]e the P~gI"-alO. Reme:mll!e,]'". we use 1ilJwe.[icase '"0:" 'fO:r ,c®mpilirl__g C ]Jl~tJ.W8.!ms. .. The wmnil!i.ul!d

CC ex~i:e.C

~U:h~ l.JNIK pMmpt wlmkl. oompI~.c·th~ Cf,+ pmgrmn mW'CC· eodeeontained m. the :file example.C. TIlle oom;pn(!:J!" 'wlH.!lrl prod'llOO an. otm{!ct :Eilf!i 'C"XmD!l1~M.o aad then W1Itomati'OOlly llW:k wi'~h too lilb:rary' ttlmcttio:ns 00 prnd)uoo 8(fII exeooitable· file. The· dlg.famt executable fi1611_R'me:lis ali)1W~.

Copy rig hted m ateri al

----~~~===-,.'; , 31

cc 1~,1€'1. C .fH~2. ill

TI"w smtemfln't .oo:mpi1~ 0'1"11l' 'the file 'flll@:l..C and. ]i:n1:lli i'~ wi;t~ the ,pNMioutsly ootn])iled 'm'G'2.o ftll~~ Thi~, is ufleflllJ whell ,o;m)y QJiLe QI. the iles n~, m be, mtJdtrled. The files that 8J~e in~t :i\!]@d]~led need:not De com~i1M aga]n~

1b.rOO c+ +- ~d !Borland C + '"*"'

"futJ)D c++ ~d Bo:rl~IW c++ :p;rontid.e an m4;egr8ited p:rogram d.~l(lrJrnumt ~nrn{m:m91'lt WJ11der l\~ DO~. ~y [p:r,ovid£: ;£JJ, CbruU::..'jn sdij.'~r.' gLu!il, :a :i!fi~:iL!I, bar 'whiA;:.lm. [ncl'MdtiS, 'o.p'~i.(Jt:i.S :5i!iU:h as Fils, Ediltt Com.p:i!kl j]l:li!m R.'W1L.

We ean ereate llI!Dd: sa¥~ '~ SIll!lrOO :illes lJI100r the' F,it0 ,l)ptiJi!lD;, ,oorl cd]t t.h.am 'Wld~:r the' Edllt op~_wsa. W'e ean then compile the :p1"Ogram under the Cmn:pile o:ption ,and. e:uOO!oo it ll_ndei" the K'!.Ul opt:is'o. ':F.he Rrwt 'GptioD can bJ:l; used witb.oU!t oompilirlg tb~ ISO'lJ!fce eede, In tbffi caee, the RUN' cmnmamd, eauses the system 00 c®nltffiiliJ)e~ ]m:k and 1"IIJ[l till,€;' ]Jftll1U!lml m O[Ul: step. Ti!.Ubo CH- bem.g'lIlle most [popullM' .!;lompil,e:r ~ creation and 'e},';_el':UJtiiJE IIlIfpHi,snmS 'lImd_eI' ~bo (:","~, ~'S:~ are dillii~8ed :in detail in A:p.pendix. B.

Visua1l C+·'+

It is a Mim"(lS(ln ij!~Uc.aticm ldevel~pm,ent r,;,yste[Ui f'fJI' C++ tluat rtl_jlcS uIild.er: lI-V'ifidcrws. Viswall C++ is avisual p!'Q.~~ii'lg ili!rl'l,\'if~mef!rt ~n which cti;ml;; ~ oom;pom:ntffi, ctm be a:el~dI t'b[lO'u:gh. mftllU daGl,ees, blJ;t~~~, JC®ns, and ot1il.€fj' ))tsdetetmmeOJ methg~. Develo]]men.t ilIod iB~ilml'tiilllD, of ,C~4 ,:F!l)I_gfa:me, '1,J!1i1iel!' WindowElo are brief1l.s expl!'-ln-ed in Ap'pend-ix c,

SUMMARY

¢> c++ ls a S<1!lpnD.''S€lt of C ]~.liIige-

¢) C+-+ adills iii ,[lJlll::n~1\ a!: o:'hi aet- 0 riB-ntl!!:d, :(tliIllU!f"I"!I,,", ''''IIll,.;h_ 'i"i'" O~"-"" .. "",," 'i'ih .. ,.,-,j.. ............ ,Ii!:~_-~ .... t .... ~

'",,!! _ _ _ _ '_ _ _ __ ,~';m Q _ ... _ ~J)J""''''~' .!!.ll o;;u,h'QH~~ .t1a_ll'!.'w,oJJiL

O'l;l'llI~l.ood]lilQ' aM.dI. 'iJoTi!l!lrra1i11l' Qve:rl"'e:diinll' ~ ..... C.' . The"~ e .• "" j, , "'":"''', ""Ib.i,~ 'b ... Hdin:~rJ '~, - e-

ll:!. ' _ ',t" _ _ _ .,~_ _ ", ,"',., . ~ __ ~!i:i ... lJt:Q,iJJ", _';!j] eIli!illJY'tt.: !J~ !!J'JI I"'''''''~ i!IImfii

with d~['ii:ty~, exoonsibility and eaSi} of maill~[JJill~i!L

.¢:> C++ CIMIi h~ used to :brnild ill lfariety 00: .sys;~!2n:1s, SlI,lld'il . .8;6 ecl'i:~o:r6~ >oompiLer.-.9, (]a'~9ba.s;e8. camraunicatinn ,sY9"tems ... HAd many mOTe complex l!"eal·,Uf@ iI1i.p]!IUeatio:n sy.ste~.

~. C++ s'!J[p,pgrt--s hll.iera.cti.Ye il1'(rn.t ,SiiDd output fe~:Wres and. :m.tndl!lOO'S :Q ~' !l)nmm,eirft 8,ymb~lI~. fllL'Mit elai!t!i '~ lJ5eQ: '~I;g ~rngle line oomment:B. lit; also 15u(PJ:io:rU!l'~,J.style, oom:m~ts.

'¢> Li~ ,f'ii, '-81m' ex.E!eill'~iCl - ,-,' .1] "'-'++, - - - -- ~:; ~,.;. ' ... ,- - - '" '( '! £.'--~.' d - _,;11_ t

, ,. __ J;! "-' P'PCtF'-_·- s, ~ __ . __ It ~~:(j_H 'V proliUaJm~, ~B R,..,m8!IIID.· 1. J.WIA>iO"LQ]l a:n_; ,el1UO!; a

ret.urn." )i sm~nJt. The ltea.rl~T rue iM~aim ulItlld.~!i! ii1[1h,id.e1!i 9It the begilU1i:n~ ,O;f.' all ]'1im~_m;9 that use rn~tJoutpU' 'operations.

Copy rig hted m ateri al

-0:»' ,AJI~, A:NSI c++ ]ilifi!~gwam5' lDi!.U;.t :mciutte 'using'n!ll!mespaoe :51W dli'[\~i'!.l'e-

~ A typi.c.a[ 'C++ program 'would! IOOlIl'tarin foW" hasic sections, namely t. indude rues l!€ctiOD" class declaration seetien, member IUIEIICtion smio]l and :mail funetion sec:t ian. ,

~ [,j~e C [plIiJ:grifrnil.S~ C++ pro~aJIIilS ean be mooted mllng uy ttexl. editor'.

'¢) IMwt;. co:mpi[e;r a.ystems prwid-e' ,:MIl integrated: environment 'fur deve]o~!Ilg ~nd! elre(;lut:ing pmgr,ams. Po,uilar $y,s~~ are UNIX, AT.&-T O++~ T!ul!o C-H- and Mi'lTa5oR Vis~ail 'e ..........

Key'Te:rms
)- #indllde >- main( ~
~ u.out » men hp.J' funct i em!'!
)- ~(J1 I and c++ ); MS~DOS
)- cascading )- name, pacll!'
)- cI'n )- tIlhjcct
.
)- cl ali!;; )- iUp~r9tilil.6'i c; _. ~~, rL!i -
,. cl ~t!.nt )- o~atlH' evcrloadi n~
)- commen ts ,. il)lJtP-1lil ill'JH:!'!"~tm-
)- cont )- put to operator
). ~~H 1 i ~l > ratum ()
)- f!X ~r.a I::tLtlJll (]pE:"r~ tm- )P CrEE!
)- no~r. » server
)- free- form )- Simub67
)- get from opera tot" » '!text editor
)to input operator '> lixbo C++
)- i naerti 1)[1 oplI;!r.a hlT ,,. [lnix AT&T C-++
)0- int >- usmg
)- i()RtJ'@:o.m >- Vi&'lliJJ C++
), WindOWf'l,
" ZC!'rtcch CTT --------- •.. ~ .. 33

(b) In: .c",+~ Cl. fitnctMn. N:tIitr;a:UtM wi~·hln a If:ll)U's is ,Mlkd rm; nurmber !Mndwn. de} lAo'kin8· ild i!i!11le' 0\1" ,tu.'O ,tilul's 0:( oode. UI~ C(U1i, e.rJlSiu" 1'OOOInJzjr!,· WhfI~r"!Ii progmm ioS' writf,e~ ,fn C OF C++.

2;,:2 2:,,3 2,4

'td) In C++~ # is ~ eaBy to add il1;frW fij!lgf~ m ,the ,gis~ing 8rruC'tun of an 'fJbj~t.

(IE:) Tk~; OOJ~pi. o.flUili~ ORB" O'ps'ratall" fbr diffo;rolupUFjJfJS1J:S is know,n ,00 ~I!!rntor ,@pitr{(IG'd'ing •

(:0 Ti~· ou;'PlUt jbnctllflrl. print«) ·fi'a~~O~' ,fill!!· ~ed ,in OTT progrmns.. 'Wh:J It1.O we nooti Hw. pn.pmooswl' di~~i~ ·#1~l!:lde ~~lf'ielim>, ? How dee'S' ,a; molinO {Uw:tir:m: in. C++ differ from m~inO in C~

Wh~~ dO you. tmllltk ,i~ (11£ .~w ~'[u;Jnfage q(tJu OOm}t~Ernt j I in C++ !lSCiDmpCJ:rnt1' it~} ~~, old. C typa oomme~d?

.De£C.rib~ ,a&.e' m;ujOI!" p~m orr) c++ ,jtlrQ§,ll'Wfl,.

11'11, E' ,,",,;;II

2" :Il lde:n'U(y' the emt in the fij)l]owing ]1Iito,gtam. hill:.l ~de <i ost re!I:I,_ II>

~!O1 d li'!~inO

'I

iwrt .! '0: ~;, 1=1"'1:, ccat ,~ 'j ,~

i-I ~ i!

I

I*f;.~~t\*/ If! = '1 + :[,; ClOut ~ " I'

}

:2.2 1,e,D,tcify the e~X" in the foUow.ing ~~Q~.

I'i I!]:C ~ mile < t iJ5'tI;'relillCl,. ruilo' void matnO

{

short 1~2~~~~ J~3~~O~

IC01!11t >';10 iil + j Ii ill >~ - (t+ji);

}

:2.3 '~t "",11] h~p:peD w'he:R ~'Iii 'fiUiO 't.be' 'following, ,progr,~?

11 nc ll.!llo~, -<1 o~t'f"il!\~fn" ~~, 'Io'\[]11 III Iltoilfi n 0

~

Copy rig hted m ateri al

~ lit f=:,W, j=5;

~ nt rnodR~silll'l t 1IIi{i; ~ nt Id 1 \i'Re:;~'l e-o ~

F.'IOdR'e~,il t = 'i %j ; cout ,~<, modRJe'S.IJiU

."!! ... "

~~ 1M iii"

dfvlilie'50U" t • i ImodRe5u" t i i:!C!!lJt ~< d i cI!'Ri!~!il t i

l'

204 Find, errors, if ilUlY.; ill the [bUowi-ng C++ st!},tiBIU!2rtJS"

1(:llI] 1[!f;lU!t « ·'x~,'· :x;

(]b) rn ~ ,5; 11 tL !!!!! 'W; Jl !:i' !!!!! m + n; {c) cin »;Ji;;; >::;:'y;

(dJ cout. .(,<. \h "l'-~TtUl'lie;!! «« ru:trne; (Ie) OO!J1t <<""En.t~l:' "ilahJi!!!l~'!',i, ein >,> :it; (f) pr Arld.1DQrr.iw/ z = x, + y~

2.:1 Write ,g: progrnm to d~pla:,.. ~he' !'aUcw,ng oulput f.~dng G, 8t.!~sle coul slale-men:t.

lVa.ihs ;;; ~a

Pl:iJ'8iC5 ~ 11

Ckem'~B',~TY ~ titl

2,2; Wl',r;i.'e a ,,progrom: ,00 reed ~l'cOO ~utmhcrs from th~ Nejlboa.rd and display th» larger ~'.cd;[l.e on, ,tA~ ,scr-m:m .•

2;,3 Wr,~'~-e a fJ'NJi.{rom to .irtp~'d an in:h!'S.eil" Qa'{~ from, heyboord' and' dJfjpl{!~ ;pn ocr~en "'lVELL DOi'ilE"" tka~ malilji limes"

2~4' Write a progrom tll read fh£ iIJ(Jf~e8 ,of oil, b a~id' c and' d~lJplrzy tr.:e i(,!I]Jue of x, wher-e

.'!t=a,fh-t' Te8~ yPtI!F ,prolMP.fI, (OF ~he' j'OlmwiR!8 ~1.L'l1'i[U!'8: ~,~) a;;; 2.50, b :::; 85. c ~ 25

{b) a: -- 3.(H), b -= 'if),. ~ '_ 70

2.5 'WrU~ ill C++ pr'&grom that wm ask for ill ie-lJ':tpt'!mtul',t'!' in FahnJuteir; lillil:d di:tpl(jJ' il i'n Ce18iu!S.

2.S R;~do E:Iffl'rciu 2.~' lllS"ing a daBS' caUed :tenlp (m.d 1l'lt1'Ili'ti.ber (lmcUons.

Copy rig hted m ateri al

.'1 _I •

I

IT' k ., • d ,.o,-,_···ens, ,_r..xp,r,eSSIO'DS an" ..

CO··.'D·' U" ~····O·.·' ·11 Stru .... ' I ct :,' .0. " r···e····,s,·_

.. [ .. . . - . ... .. . .

- - - - ~ - -- - - -- .

I

:. i'okena >- $eDpe ri:"i::i8ol:1iullrm
:. Kp.yv.'oros )- De,re.f~nlnciJ, g
" Id.cntifieg~~ :. MCDlOlj' tDJ3Il:Dg£!ffiC'nt
)- D:uI~a t-YP~E:I ). iiUrm:att~ Lb€:"! 1"tLll put
)- User-defined types )- Typ~ ensting
)- Derived t}t)JE!:!ii ). Col'lat.nlct.~!i:lg ~xV'-f!-!'i::; LonH
>-
)- Symbolic censtants . Special asmgnment expressions
» Declaration of varriab-ks )- Implicit conversion
.
)- Initi.aliz.a. tion ). Oper.atoT !lrvE!f 11,;H,J,dl n g
). lieflJ"tl'"h!(;~ vE\jriu1ilLcil> );. COi1l:tt'-01 iI!In"u(:Jl.~JI'~~
). Type 'POmpa ti'bility ,A;8. !tlliCRtti.o~d! .~:tK:l"~. C++ is a SIl!,~l'SQit ,arc aad It;lmm:fnro ,mes-"ft, ,oollls!li:ruiOOs ·o:n:~ iIm~ kg,oJ in C++ 'wifth, thgir ,meanmg ~a1'iIgerl_ Hlil.wa-Y·IM"; ~ £ilIi:'B smllLe: ~G\.iltiollS and, additiiDi.llll. In

Copy rig hted m ateri al

." )

,36 ,." ''---------- Objed .. OnerU~d ~FI11l\1j':i'Ilg wl~h 'C++

I

this cll:a-pi±er, we 5l1aU msCoU6S these e.xiCe]JtiiOOJil3' and additions witili :l'espect to. 'to'~ens and

ecntrel sb""ru:;t'lll"cs,

"

"

M we know, the ssnallest mdividua1 'lLIDib in iBJ :pl'ogram are b.own iEIl.S to:k:eJn.s. Gt+ boo the

f-oll!owll'ig' '~Wreu: -

• Keyw'o:rds, ,. Id:ent.ifiets,

• Con:9t~l!'ltcS,

• StrinGS

.. o,emt~J:'S

A 0++ pro1rr~rn ~6, writlltEm !.l!sin:_g these kkens, white :5,~0e9, and. the s:~,twr. of the la:~a~'.

Mast of' ,~. C++ ~o:lootm.:B IIlf,rJi hEllsioo:1H.y sll!llLiibn' 't® thl2 C "k!~~Il!S wi.th, th~ D.reptiOll ,of S-Cl11Jj_G, ,m:illriU.ti.0.IDS aad mm.ol" m,Otii.c8j!iODS,.

'1Il'"""""".....,..,~ ... ~I, ... ~~1.'Jflt'.~~i::II

TJrn.e ke:Yw~ implemr;mt ~~'CWc c++ lW1~!ig,c fuat1HCS. Tih.ey are (.~nca;r;:I,l(' ~OO :idEfiltrners and eamwt [be 'llISOO, D names fox the ]J'l'"O.lUaiDl'vRr:i:aib1e;s or other ~dle6ned px-®gmm elerni_EnOO.

_ TiaJ_hle !.:l .. ~v.oo the (i{[mple-OO b~ QfC+.+ ~W\~~, Mf:i~,Y; @ft:h~m tlte' 'C(~~~1ll 00 biJth C $:~d C++. ft~ AMm. C kG~~{!nlls ~M mOl\1'fi ill boMf.ace. MdJti®.oru ,k~Ol'd.s M.Vl!:' been ,a.rlJd..€d to Um J\NS][ C 'kO:Y'NOrnIE in order 'to, enhanee lts f'~tu'c:s and make itt an ohjm-criiWlJtm Lm:guqc'. ANSI C++ studa.rds committ.e~ U5 addled ,!3iOme't~li!i1re ke:yYi'tlro£;,'w '!TIa__l!l:_E '~~ :bUltliiYag.e rnote' ¥e:f<sauile. These a!!.':e ~bOWD Be[l'!in"a'te~.y" ~oLI1..$ ~'Qd PIl.iI:r.pOse !llIr,~u C++· k~.Y'Wnr-diEl, a~ ~,..~n in.l\.ppend!ix n

.lden~ifius refer to the Dames of'varriab]esJ, fiuJDctiou, .anay~I' elasses, ete, ueBued. by 'the Pl"ngramm.eir. ''illbey aIle the :fimrlameJlitElil reqmemot of any' 'I~ge .. ~iIDh language, has its OWiII. nJes, fur J!UIlm1n:g these iden!tmem.1be roll~··l"iIlilies are OOmlJil0'lIJi 00 balb C and. C++:

.' O.nly :ff!!lpnabt!tic ooEliif-aet.ei1'5. djgi.t~, and u~de-r~oor;es ,~re :p.em:iUedL

'.' ~ ,~Q:FDJ~ ~~~H;O't s,t~¥~ with ,a!. di~t;

'.' UIPJ.!'frl"CrnlJie and k!l'8le~ letiber.s ,81ft. disti:n0t .

• ' A decl~. keywm'id, tanrno.t be 1118€~ ali a 'variable: :iJJam.e,

Copy rig hted m ateri al

i!liwitc:b. "tempilat.e thiB th!'\OW try 'typeief'

dO-1l_lde ,tibe Oll!llllJD ,e:~e"" :hu :{Q.J" :fri~d ip-lD

:if imlime

,Ii_Sfi1ilI

!8iu~ ibr:coik ~;a;5IiI1i clllitiih. ""harr d~!ll!I eOJictil!t; gQn't.:iinQ d.GJBiuil!t iIile:Hi!!m

do

:new O:lii!jjJ.",El'~1' ]in.vote ~~~d. puib'lic

:r,e g:i s.te!r ![',ii!I~~. iSh!ild &~~d. 8.l.zcmf 8tO!t~~ strnot

'\1~l~ wh-iI.e

:int lMI

.JbUoo' by ANSI' e++ 1b~'1

!l;lDn~U8B~ d3-,un'[]ic_:c~t ~pJidt:

tEinte:tpl'e;t_t'.!:Ult. :5 t:liJti~ c-.as t.

n.e

Weidl

expor:t

:il'9J1:!i!B m!J!ta~~e l'Ii~m~{!;,paoe

'~pan:!lme 'usmti(g w~ba.l:'_t

Calte shrniEd ~ ~~~ wblle nammg 8J v,~abte w:hicb is being s.h~ by mon' thM 10;11I.e :fjjle '~ntammg, C :and C++ pt®gH..1nF1. Senile, ,~pel~atJng ~.:rstemij :im;p@~e ,a, 're~~"riC'~iom, Or! ,thE:lelJ!!¢h o:f 5u<:h a ''li'a:liaible name,

Like ,e, 'C,*,* ::3ILlIPJMn'ts iSe¥er.i!!lH. kinds of[iter,::d CClDSi1anb. They' mi1:[ude :int~~ ebareeters, flD;m:fr~ng;"p,cmt ,mmloorn and gtmgs. Ub:!rnJ CillJIi:.stant do not h:!r.Vll memory l\acaitions. E~pJes:

1~'3 12' ,]4 031' 0>:.2 ,11(,*+11

'I Ii. ' L'@b~

/1 (ilelt~~" i Ii:tege-r

II fl~~t1ng p~int irnt~g@r ! I Q~1;.~ 11 i n1N~g~1F

1/ he~~lIlIeci I'DoiJj 1 i: I!!Jtegerr II $tri~g con~t~nt

/I ,chali"\~ete.r 'CQDstant.

II li'fl if~-(:ha.ra~b~'n" 'con~:tant.

1':t.t~ we]IHlir:_t t.ypi;l. is :fJj, wirlli:!~_er' Hrk:ml :~mmdUiBOO. li:r ANSI [~++ and is iloOOndH far' e:l1J;Q!['ac~m" ,sets tbat ~wmot. :liJt a 'Ch&:r.,E1Lc>m:r moo a :single byt~. Wid0-cumdel" limr. ~~[JJ lh-ith. the, letter' L

Copy rig hted m ateri al

rtDt6

c++ iSUppotts "tWO,·t:Y1;!if!Il!, o.f"smng ·r;epresen'tation. - the C-style m:!lF-8Jcter .at-rhug· and the ~m.,_V[g' elsss type :Intmd~ with S~d.d c++_ Alwll'JiD.gh ~ '1,:tS!;! !l)f~ ,e:itY-Uili_g clQS.!1i '~.Y.Pe' :is. reOOJltimHfi!!kd. U is &dli!s9Je· 'ItO unrli2NlandI end use C-style: 8'mlEligs ln se.mf!: sit'llUl!rnmSL ftl\!l s:trllDg' d:tliss type stldngs support roam)," feat!J.u·,es and are discussed in detail i]]1

.Cba.pool!" 15.

~r1!.I~~I;J~ II.IIniiJrtli ~El

e I"i 1I11"i'i a 1l'a1loo

atra;,.o ~!Oll"l pt!ili~!lr Ii\E!r'I!!fam.oo

Berth. (~ aDd C++ ,eO'm~i]e!;\';, ~g~pg.Ft ~U the ~ih.-i·1], (aJJ~~ ~~w[W .a!~, lla8ic @r fund~meman dla:ta. t.yp.Bs. Wjd~i rt;hQ; ~Jll!l!:p1;i.j}n of 'void~ the basic itaiM ty'pRs !EDU"iy h:£1!v!I!l SOY{i:rnl mqdlf~r~ preced!iDg them 00 ,:ijgrve' the R~edB of 'VaIriOlJ.il.£l :si;t<l.:u~;timtS, The !lIDJdiiiJe:rs ,sip.edi" unlS:ignedi, bmK~ and. !slitON may be ap~Ll~d to character and inrbeger 'basic dam tJ1!Es. :Bl0'v,teve~", 'llbt: m~:fiie.r ~:mg :may alS@· 00 ~ppiied to. d&1jlb:~~!. D~'f!.Q ~ ~'['le;s~~.~~ i;s .. !~·u .. thif,i,e !jpecij~~ lin C++- h"bl~ 3_2 ]i~t.5 all Qanlhinat.io:n.cS. of-the: ~Q;s;ic dlata t)tb&.5 S-1iId modi:tJera· ~~ilG: with 'the±~ mil1: and :r;ruuge for. a i6-bit ward m.acl:U.e.

Copy rig hted m ateri al

tlMipe« c;bru-- 5ign,e.Q. char ". int

unsigned 'i~t. . ~igned. ir!i~

~ Iltmt in~

UrrIi Eli fPl ed, ;!clli[]11 im't I!Ilgo;eG, s'hlOOtt j!ot lWilI!:: int

signed J(lfig int unsi.gned ],\gRJ i.!!!~ floillt

d.o'llitiJl!3

lm:'1!l: double

~iI' n

i i

2

:2:

:2

:2

2

2:

4],

4],

.;,'Ii

4

S

:10

--

.-JJ1.8, to ,l!.2'1

I] 00 '~15

-1~~'l!.21

- 327~ to 3t7l1,'

I] to '55535

- ~l17113;S t.Q 3.21~,'

- 3:l7e1;8, to 3.21'6"

o Itm. ioo1585 --$2.168 to a~767

-2M/ji',t3364i to 2'J141'4~?

~2M,7,4m~H8 to 2JWI1'4S8G~·1 @ to '~I;2$4t~.M:2~D

3.4E-:SB, 'w ,a.4E+3$ :1.'1E-:.'30S m 1.'&008

3 .. 4'E--493\~ to 1,. 1 !E:+49~~

.ANSI C*+ rom:mJittee has, adlriOO 1two mo~ dam '~~J' boot and vmh __ t. 1hey are ~ed, in '[Jh_:apter 16.

The It;yp€, vmd. was muooucerl 'm A;NSI ,C. 'l\o;o nnrmel uses of'vold are UJ 00 s,pecify 'M1e mum type 'of a NRctio:n wIlen, it 'is :not r;e~!Jming, ii_]UJl' \',alue. ,a.[)dj (2) '~tJ ·it'idjieate, ~ em.pty 3IQ:UDlell1±. list 'W a fu.nctwn. Example:

""'!lid functl (voiidh

Anot:h~f" :iintec.t@s'~'nl u$ei ,of'VQidi :is ~:fi the d.ecllilr,~n;iiOiDi o:r gail~1'i£ ,poffii!]te.~. ~m_p]e:

.A generic ]Join;ter can, be ,asslgn.eiI, a :!;KIillli.et ·value of my bM.ie dEta type, ~U/t '~:t may not he d!er;e:fe!t"t!nced. 'FOF example,

i I'It j"i p'~ 'gp. ... 'i prj

I / ~Ilit J,a i:n feW'

II (IISs, ~ gJl' :in:t po ~,I'1':t€J'" to u'~ d pO'i II'JIt·.f.',f"

A.llJii~no; ~--Y po:it'iter 't~e w a vot"d ~t.e]" v.;i~ou:~ U~ii'ig ~ ,c:ast is, ~UO'W'.ed in, both, CF4- a:mrl. ANSI C. in AN,sa C, we: e;an ailso u~~. a 'void. :p[].jomr to • ncu-voi,dj, pomrml' w1i.ta:mll't llIStll,g £ii, east m nO:ll..y,ojdj peintar ~L 'This is mot iIIillovvoo, lltl c++, F®:r ~~~,

Copy rig hted m ateri al

voii d '''"[plrt:~ C~1'ilU" '!liptrr'~ ~ ptr2 ;;: pt rl I'

..

~~ all 'V,alfd ,smmmo:nts in, ANS'.[ C ~U!t.mt m C++.,.A ·¥o~d pDinter eannot be direct],. BiSsigned, 00 other type pil'J!llten :in C++. W:e .need to use ,;lIl caBt OpeTfl/OOi]" ,a~ aown 'b~dow::

~t.~ ~ (ch~p ~)ptrl~

I ~. ., L.'. ...... 'iii 'f,,,,,u;ii"_-:,D:.u';C!!:-.i!:id· Data "fi~;D;iO:l'

'" ;]iI_,!!i]i 11LJ3'!b.a~' __ ~.IIJIlU._~_. . __ .g, .' al'p~il!!'

S:truC!tUlfCS and Classes

We· ha-ve w.s~ 'U5er~e:fin~ data '~ such ~ st'l'l!llC~ and llmito:o in l~. '!Mhi'~ th~, ld.nta types :i'U-~ le,gal :i!n IC++. SI'J!lU! ~ r'ea~s ~'!,\'El boon, added. to ,l1tlW' th!l!f1.1. srnitalhlfl' ]'0:1:" obj~i:}t-. o;rrerlt"il'lil. p['o,gr-ammmg. C# !ils-t!' Pf!_tmim e 00 ,de£ine RIllmhe:I" ~e:r.defuted dJat~ ,type lUubwmL as elass 'w'biich can be used, just: Likle ,any mhe:r basi_( daea tY]:i'e'~ W de clan' '!~'luiables,., De elass v;Eu:i:8lbl,es. are m~w:n. 8;8 "J"bjects" wltic'b :a:ife. ,the ce:f!!tr-.a.l f(;lcU!!!!i i!1Jf o'Etiect.-q['~ellil:ted, pr,]l)grn.mming. lime ,ahqiJ1'~ t'he.se tl &t a, 'tJ]J F: 9, i5 dj~~~ed ~,@~ in, Ch~ptgi" ~"

'jJ-J I -I - __ , -:i'-~dl !Do:Iir~:- ~ ~Mumcm!lie ~ MIla ~',I.l--"_

,An enumerated dJata type, is: another 1mSer.dem.e~ rtJr-pe which provides a 'Way fur' altt8citlng !!:l8.'IiOIi!!.!iI 'i!;;g. !rl.u.mbe-m. til:u:!Fe'by' i[lj~ii:ng 'il!ill!~r;!i!ihe:iil8iliiilit,.Y .of'it:lrn.e ood:e. "I'11Lo .oiDi~m 'kl~Td {!ram C~ iIlIJllIoomatimlly' 'eJ1um£tRtefa ,~, .lJJ1!lt olfwmds by ~~.G:ipm_g tl'iLem vah~,es O~112, ,iijjJi!J so On, '11JJis facility Jlnwrides an alte:m.ativ,e 'mMllS, £b:a:' rCl\eattng' ,£lym;'bo]i.e oonstanW. n.e' 6-y:nt~ of' ~ enum statement ]$ simiblr to that of the ,stru.6t st!ll!'Pemem;l EK_a:mples~

erum shane {ci rIC 1 e , 5.qILlare, t Fi oaJng'] If:~' :' enum col J!Jud red., bhufi: ~ gT"e.e;() ~ yen!!Ji!'!! ~ : e'fium posit1 on'~off i o-n} i

1Ii'he enumereted data ~ dJift"e:r 5l!ight1y in C++ when cQni~~" with 'th~~~e ill ANSI (:_ ]~, C++. the, 'tagll~ i!IIbIlPC'~, <C6l~iII1I";, and pOsffi~~Olili, b~~ !];~ t.Y'J:t€:' 11I.:I].I]'U~S • .By lIsing' Ulij}'8~ tog :nDmes, wn ean W:lc]M'(i: n~ v~b]!M. :!E.~s:,

s l'i,Bjpe e 1 H IPs~ i coll@llIlr' hac ~g'l"oLlllild j,

II e< 1 ] l' Ps€!' ij s of typ@; sJbap~

/ I bee kgllfTIlmd is of typ.e col iIliUIr

JiJ.NSI C d!!2'f:iItlQS, ti1lfl' t,»!llS ;j}]ICDJ1lmB, to :bl!: :iD.ts. m:n. C++,~ 1~~cl'lI~J1i.U:IlI.:l!l!t'~,tM, da.ta 't,yp.€:' :fiii!i~ai![:lS its ,own 8!2pmraw it;ypG" This m~a:ns, t.il .. 81t C*+, does Dot p€'ITmit an iot value to 00' ,at1JmmaticaUy li;l!lU1V(!;[md til) an ,e-nJum. vruJllC. :EXlimUJles:

(;o'lo!.! r baiCkg rOlJlln'IiJ = b 11 ue:

EO 1 ow r ,b~(:t;g r'QI))JJfi(l " '1;

co 1 eur l:Jackg rowmd 'Ii (co] im.l'r) j i

J I ~HQ~ed

1/ Er'I""Q1" '1 n t++ II tOK

Copy rig hted m ateri al

--------. 4"

By default, ~tn<e en.illneI':ators are ossignf:di int~gc[l' values: smrtliog 'wit][ 0 fur the fir.st e!m.liI·Q'I;e:r~OOt. 1: foE '~b~, Beq:~ncl,. t3i~d 00 ·IJJi. 'We' ~a:n over-rhie .t!h.e. d.efawt by ~cltly M~~rfng i~~ \i"E!!1.~es to the eOlUm.e(Wat.ors .. For e(i{)e!Jn~Le",

e~u~ colour{red~ ~1~e=4i gr~em~8}i iE'lIium cc'l our{red:c:5., b~ ue, gr,e<8rnl:

c++ ,Q[s~ pe(fmits. the Clle:3itJ®n {W£' ~nonymi)US ,enu~, (Le." e'Jl11.lmS without ,tfJ(~ naJ__mes).

Examp]~:'

et'ium{off,. on} ~

Her.e. ,oR' it:!- 0 and ,!)g is 1., These COl1stant£; may lJe refex.enoed, in, ~he !:!~e ~1i:'i~rr a!~ te~a1 oonJjtaJl'tfj .. E'X._mrple£!~

'i nt s~Hclh 1 = '!Jlff~ int s~itt~ l z ~TI~

11'11 p:ra'!:t<i{ie~ eeumeretlon ~ used '~O define ~o1ii:i' constiIiJiLts ror a 1S\!Y,iifich. ,StBiimlient.

E:~a.m,ple:

enum :~ha p@

{

ctrel !!, N!1Ct.at1g1@~ tri'angle

l ;

] fit rrLa;i n 0 I

'C(:iI!lIt « iii Ent,~ r- '~hg,p'@ C!l)!dle': u ;, i nt code ~

ci n », cod~;

liMil 'E!{ cod E! ).o!ll ci If\C l e &~ code <II t ri ang' e)

,~

Copy rig hted m ateri al

42 ... -=-~~~~~= o;"r~~Ori"'rt~iE:1d ~rt.i!rnmjn~' wi~~, C".Jo"l' ,~---~-~

,~i _

, I

"dr ,'"

Dr:f!\~ lot ~

c~,s:e rre·ctan.g 11 e;,

bf'lsak~

C.iiI'Si~ t rii ang 1 @ ~

OIl .... , ....... ,

- - - - - "

cout « ii E:n'it€T' shape cod 11:': ii j, c::i In » to-de ~

}

A.NS~: C :pO'rrmib; an ~HfI!lD1 to be dil2tul€.'di, within i!l sb"u1ct'W"G 0..1" i!i class~ 'but 'thG iIlll9JlIml is glo"bIDly w1sibiG" In nF~ ~ m:JJ ,eDJII!IIlIj, defined 'wirthiin a. class (m ~truct1Rre) is l.:ocal to thart class ('0:1' ~tUft) onJiy.

Air.r.ay;s

']'be ,appicaItam ma;tt,~ in, C++ is fiijrnilll1 'bJ that in C. 'The ,only e~ption i5 '~he WII_Y char-acter It_tt.~ artie '~j(ilJ~I]~..e~, 'lWhe~ li]jtiIlJl!2i]]_~ ,~. ~lu\t,~()~r i;\T.'tgiiY in .ANSI .c:, t'h(!J w:mp;i,I~t w1i.l1 ~U®:w uS to ,declH'foe the arr,ay illJlZ;e as the exaet length. O'F. the B'~~ constant. F@r:iru;tafice,

:FcmlnCllLolits

:iFlmet:l)or:JiB, hill,'I,\oe WltieqamLe major &'IilalQge5 ia e++,. ~e seme of these cllaJngt:s are simple, ,O'the-m 'iteq]uiirE!' :a: iOew w:a_y- Q:f tm:fil;k;i'f.I!g when Ofg8i!Ojj~~'l1!g our ]JII'-.I)g;trams" MiUIi,Y 'Of' these

Copy rig hted m ateri al

------------.. 43

mOOi;f'iea'tto:~ ,sAd tml1J'{N,ementts ~, ,dri"~n, by '~l1e '~equil\emmm ~ ~ ,obj'~E!mil\ed ~nw;p.t QI C++. S@m~' ~f'tl~~ w~~ ii~bxMclJ~~ed t@ ~~i!$ the' C++, PN.W~' ~ :ooJlLEI!ble ud ~adii!'Me. ,A.i[ the Iia~t~:t~ gf C~+. f~,:nie!~iunij __ l'E!' dia~E!ed; in ~~iL" 4.

:

tnt ';"i p;, f p III ~:q ~'i IP l1li 'ltIJ~

II iint po~nterr

1.1 'Clddij'"\i::!'~~ of x ~:s S l gned tQi p

II no ,ijlSS,1 gned to )( thr-..ougn i nd ii rectt om

1.1 ecns tant [peri n tar

'Pointe:1'6 are ,el'l::tem:il~;'!;eb U&OO in C++ :reI' m.emoil"Y manale:men't and .ach.~m:rilg pol!ymOl"pluSJ1Ii"

.' U's,l;ng "the qulifil:r 'cOJilSI!, and

'.' :DefimiDg a i5et. of ]iIlIbeg.er O!llllstan'&s, uaing' If!OUlm, k~D1'd.

[_i!L liJ®'th C ,aM .c++", any' 'Valllle' ,~eela~ed 8JS ,e.G.J.1U3'!' cannot be mooified ~ 'the ~fiOgnm,:in Q!i:l1 w.ary. ~~i':; ~.iii!!'E!"~ Sii)!1J:le ~~~ m ~menb.\ttlQn. mo, iC++~, we IOOUi ~~ ommt m It

Copy rig hted m ateri al

con~t int sile ~ 101 clila.r namE! 1[$·; .Z€!J I;

fhj;s W®tlld be 'illegal in {~. GODSe aUows !,]!1J; flo 'crea.te typed (;~Ilstantf:l ililltead ,o-fJun,-<ing w l.llie ,1'defiDii!' to, oCi:"e;;.te ~~mSitalil.'te-t'h.'at !1:'UlVE!! :Ii1Q 'typ :i:rli.fMiJ'['fIJatu{~n_

const int size a lO~

C .. + requlees .m 'GOJilti~ to be iniitialized" .ANSI C does n@'t requfre an ]nit:iiaJiz.er~ if neue ]8, giWn~ iii:; initmH:zes the !Boost 00 0,

The :sctlping of ~t values di.i:II€m . .A (;O]1st :in C++ dlef~llJlts 00' the intemaill. linkage nil. tn~'Qrre it is loonl '00, w fi],{j' wne.rn ilt is, dillfllarnd. In ANSI Ie; eenst V,il~.lIl.J2'g i!l1"e' gl!ll!h.i:i.l :ktt ,DaW!M1:. Thiry BlR' visi'b1i]l eusaide the IIc' in wb:ich. th!2Y are declared, However, tl~£l'y ean be mJiltd.c;, l(!;!!.O[ 'b¥ dcekil~ It:h.em M ,!JtBtio. T0 ,;i,Vee .l\I! ~llSt, v.!;l!h'!'!!.~ ;f,I:11 ,~te-rn~~ linkage 00 th~;ll; it can be :rdr.aiteerlJ :&om mother 1:ine.., we mU9t ex-pli.ti'~ d.efme ~t ss ~n extern 'in C++. Elt-a_Mp.le:

Thiti. tk!flL:fit.-"S X, 'y l1!D~ Z .us i]lJ.t;ra.~iL oo.ElJ..StanitS w:lith . values 011, 1'i and 2: rosp'@ct..ively_ Tms is eq ll!i.'Y,i}il£,;Ii'1I.t t.(!~

CO!i!it l _. O,j
censt Y _. 1'''
"
Ii;.Qns:t L "'. ,2; S~ V'~I:~a ca'lt 'be ,i;lin_Ji' i;n.'~~ VSi~.l!,iLes. Er1,~met,fl!ted. dat~. t.ype has been (H~"1J!i$$ed in detail ill, Ssetio:n 3.6,.

Copy rig hted m ateri al

" ,

~o~n."i:. E~rel'il~i!i.5l and Ci;J;.'1.trol ,;Stru.rtr.ilife.:!i

===~--------.;~,~ .. 1~1

C+-+ is 'very sty,iet witk [lega'rd. to 'type !ff;Jm,])at~:bmt.y as CIlllltllP9n=di 00 Ie. Fl!!Il" ills;lla~; c++ [~[I}~ Int, ShiillKrt ~'iru~j I!IDd, :~on,g iD!t illS, th:r~ diffe.n:nt types". They mus.t be oos-t. wThre[). thw values ~ ~~i~'i;gtliGt;9. 'to ().T.tj;!l MllJiher. Si.mHa:r]y, Ul3s1gDi!ld ,c:hilU"l! Ch!a£I."l and SJ,gm.(!:d ;char ~ >C1!lI~;'jjsi~:r.ed as rli:ffsr~u'i:. typ;gs; ;althl!l!~ eaeh of th8";S12i nBS, ,!l s.i~, of!llllll2 ibym.. In C++~ tffire: ty:p€:S! ,o:fV'al~,ues IDi!.1st ~ me same f(lt c®'mp~,ere cornpa;Ub:iJlity', QI" else. a t:Mt mmt be a:pJ!jedi. ThEse :r;e.smc:.tiO'm in C++ ar:e n~:M'Y in om\er t® sup~ fUinctioJiL [~lnadiog wh.eiJte' t'WO functions with 'the ~ame r):e;.TU~ ~~ di2iitiin~]5h:edJ ~siI1g the type ,t}f fU[i~ii~n, ,~m~Dts.

Jm:llt'h~'r ,n(t~9Jl!~£!' dm.F.rf!niDi~4iI ~ii t]ne, way char ~t:aDts 9'f{!' soomd., ,m. C, thi5Y ,Q:]'{:' siomd as :liH'ES~ and t,he,m~rn,

...

lJlI:l IC_ In C+ +; Ih£lWGV~r.', -cihlar is not PflOE:llot€:rl to rthfll ~re of Int and t:bcmfom

...

W'!2 bow MUlti' in C, all vanmDl!l".S .IN.1JlSt be declared ibe:fOR they are used in ftlmcllrtable smtemc[}lts. This is 't.rn.c' 'With C++ as 'W~lil. However, there is a B~~j[ti~t di;i:'~!m{i.e 'OOtwem C and C++ with regaM '~O the plaee ofthcil" declaration. in. 'the pl"OgTam" C :requiTeS aJJI tbe' "V'miableB. til be defined ,:!It 'the ~lIig m a 1ilC.(J~. ''\iVhfm, we '[ie-mid It C P[cillgta1tli, 'we' i!JBUlaJ!ly oome' :ii~~8S a group ofvariabte dee'bIT8iticms at'th.e be~g,o:f'eacl1 9-Co,il)e' leveL 1be.ii" ~a[ IIJ.i!lO ,Elp,p!"J".ru1:i, gJJslI .... ~:rn lilll 'Khli'i ~~, :5tm];etl:m.iI!i8, :[':Elll" S!way &D'rIt 'Iib.il!i plBC:il!i ili!frlJeclS't,B:ttihti~ Be:Fi:r.toa using a variahle, 'We sh~wd. go back 00 the b~ing of" UUl: pTClpauIll 00 Bee whe:the:r U. has been. declared and, if 1SQr. of''Whait '~ype.

C.t4 IIJIQII,'I5 'Ule de:clatat1Q[! !lJf a 'vliI.rlabie' a~ltere rn the. 'SCillipe.'. TJiU.a, 'i[u:,[IIruJ: 'tl:1_:~:t a 'V'8iri:~;ble ~ be d.eelaTeil rigbt ,9t the p:laoe 0'£ its :First U!!e" This, m~ th~ [UiClpam much e-~l:er' 00 wrifk: ,and. :r~d,UOC"8l Uu::: 1j}'.H{jo}"g tlha:t ,may"h!2 CQUsM, ~. iMrving t(!l :Eloon :lmrl and tF'ortih.. It also m~ 1ili!2 p1"0,~ 'iOOlSie-l" to 'u.d:m'StJmd. ~UB~ tJhe 'l,l'miahlM, am di1'lclM'Gd :in th~ oon;~ ef ,tJrLci[· 'tllS e,

Copy rig hted m ateri al

'ililt miiiliiO {

float Xi,

f1 oat :5il@ = O:~

f,or{ 1 ~t, '~:: l:~ 1 <5 i, '~ .. -If) (

I'

n oat ,ii'llIBT'aiQ'B';

,3)!'f:'Ii'~g e =: silLm!{ l' -I) ,~ CIO !,i!,t <:::< I",eri~ge ~

1,3,.,)1 ~k htittdizaIdo:n of'Vad~bl.e.s,

lID. C~, ~ vmiab]!~ m1l!S!t h imtiail.iimd using ~,'i:lomrttm.t ,~~, and the {~ CGm,p;]!m- wa'llld b tbe iinitiaJii:zatillllL codJe art the time 'D:fCCH1Bp]lati~D. C++~ however, permits 'miti,ailiza:ltlO]]l !llIfthil'l v,ufuiiiles iElit run. 'time,. ~ isrefenecl to as dyJUlimk' init.iilIlizat~(itJi. Kllli, C++'t a. Y3i"5able can be mitiani'zled at rum 'lm:ie 'u!_Binl" expreamDru! :Hit the pla~ 0"[ decla!rDtiil)t~. F,OI' esample, 'the fblikrwUng' :lWe 'vRila 'm.iliaH~!iIt:iDn stHitle:m.en!ts:

a. s !II! I!! ,'"

f1 !Qat ,neraJ9'Ei';; // de.cJQ'.re wnlf!'rf' f f' t S J'J\i!!CfS'SO'r'Y

!a!j!\B'rilig:e "" :5 umlt :,

Copy rig hted m ateri al

==~~--------... 41

])ji'lIlamie inri.tiEJJlimtiol:1J lis, '~l1si\'l'~'l1y il!8Hd. l:~ ~bj~-t-OFleD!led. p:oogrlil~. W~·~ ~1l_(!; e:K.i1l'!:~[y the it.:ype !Of Qhjeot needed, using imO'mlatron. that is ~ ,onJy ,at. th~ '!riIBl tiime'.

flQat total = 100; 11 oat ,&. 's,1!lrn II tot.~ 1 i.

'Ifi;otoil l$' a :flaQlt tfPli/l 'vnrinM@ t.'h1l!t hQ:S QJ:r.W!0!rly iboom. ,(Wc]rure!li; i!iI1JIm. is '~ .aill.li2:rn~tivo n~ deelarcd 00 IDpl'CSm:lt .~~ 'lluia1b[e atat .Both th~ v9ri91bles Wrt!li" to tbe ,suna WribloDject in tlm.e' 111!B rnUl!ry. 'I\~ow; thJ;l S~·ta:D]ler.lits

w]']L ... b ...... i!ip , .. iI,."," V""~'i~"'J. 'I.:-;;>, .. iI,. ,,~,..,~'l o:,,,,,,,,,l s'"'....,, ;I;.~ 111n, 'Ifill ,"n_"."."'.,"" ,;i.iIo.,;" '''''''~iilml'iim,.,.".'''' '_.' , '", ~'3'" W;~ '. "",~,,,,,,,,,,!!J'JI !ilI ... w:t!i.<llll1iG '<lI1LII!iJl ......... 'L;U, U. ,1Icil 1I1iI ... 'll .• ~!, !l.:L1"" ..,..,_~,..~""'"'- ...

wil] cliM.ge the ''I,i':.fJilYle Qf b~tlU lihe· 'll~n8lble6 '00' ~e:i:lQ,

11 ~€~ ''!I!\ilu'ia'hla mu.eJt 'b~ initiQ[iz~ ~t 'the, 'time' ,o:f' deel~,9It!~:g~ ~ ~tabL1R~ the '1l!!ll!~S~l1dA;;neg, llfltw-een ili~ :fI~gmljl!'ila ailld the: da.m 'obj'~, w1Ihieh. it n~. n is, i'ml1,port91l,t to ~~W' that the irutioJliz&tcW]l '0:£'& rn~nm vuialhilc :il3 oon1LJlll,~ly dlif("fIDN!Lt from m;sii;~t. ~o it.

Copy rig hted m ateri al

C++ aB5d;ps :addii.tiGII:ail, m.eaning 00 'the! 8,ym;bol,&. Here. & ils Dot 8]11 address OpeTaiWl", The M~tiO:Il t1~fi~ &. me'gLn~, :r.,gfe~lie:e' t@ fto!mt O~her eK8;mp'les, 8~1:

ii nt In [11[}]1 ~

ii nt ~ ;( .. Irri[:1II]] ~ it: hat & ,j) :0. I \n ~ ~

1/ /It l5' aHas. jor n {1 OJ

! I i,l!il ii:;t 'f,~ l ize referenc» tl} i7 l'i terol

The '~ari'B!hle :x :is an ,alJ:te:matirve to the mT,Siy ,element o[ 1,0:]. The· 'variable a. 'IB :initialized, 00 the ne\~~m~! ~j)]D15bJtit. T]ti~ ~tes, a ;refem::~~e 00 the ot'herwise 1.:Hl __ tmoWti ioeation wber;e the [lE'lNfi.hre, oonstallJit '\:0 ~,soo~dL

t , '1f!1t ~;,

iint !lip - ,b; 1'nt &. 'fi'I =' *p;.

'1['he :t]rst aet iliff ded.:e.mtiQJilJS CSii!J5E!S m 'W' 'Jlerer 'to :~ w'hicl1! is pilJrntecl to by the pointer p and d'Lei ~t~J~~,'~ :lin (liD,) ¢1f:(HliJtt~ :i1I:n b~,t Ij}bjE!~t with Y:iiLI.ue, 50 i;lftdl nama H,

-

,A mii1rj!l)(li:" a~ieati!llln a['rofu.mnoo- ''I,1'uria'Dim; i!s. in pass~ng' ,QJrglIm~m,ts to functioDs, Cons:tdoQ(l"

the fgll(mfing~

.·V(f~i~ 'f(tnt ~ x) {

l/ use,s r-.e1ef.fmce

}

lnt m!~w.lO ,~

'1 nt, 1111 :;;> l®:, 'f('m" "

. 1lP.

,10 -I' 3! E'r.

}

Copy rig hted m ateri al

Sueh liinction C;li](:s Ei.1e known as .tJaU bJ nfenntJe'" This imp]e:metilta/ti:!rm lis. inEb'8i~dJ ~ Fijr. 31,'2. S~Dce··tlle '~hies :x: ,MId, :m .. ~: ,~ias'~s~ ''RU'll. 'tlre fu~e.tiillD. :inm:I~mh:l! :s;, :m.:is .aJlso, i!!'u;:;remeH!ted. The vRIiIJe of m iEliooomes ZO ,amreli'iL\he fim.etilJIlL is e:xenited, lin. u'i:u3Jititm.:aJi C~ 'we' accwm,liEll (IWJ operatiQn ~rng prrinteJ';8 .. MId deJleferencing 't:emmq;!I,es.

in.1: 111=10;

-- - -~--rnl

'------ ...... 1 1 1]1 1in!iI1~!SDn

''-- ~ mam8a

in~ .& x =: rn;

~,~, by :f.-e:r~~ce 1iQ~~!!in it, ~,u!efilJl·igi. (pbj~rl~ted :~~.minl''beea~e it,pefm;.~' the maniJ,pu.latiLm1 0]: 0l:iJ~. by mmrol:l.oo, and Glimiuil:i.ms th,(t oop~g 0'f ahj~ct ]!!U,!llm{!:t~.s 'baCk, and fo-rtb.. It 'is also impm.1i3!Dt tn ,Ill 000: 'tltat rnfiM'!i~D.'fli1',S eaa 00 iM"eatmd. net .orny:fur bdt .. · In data ~ ~ut also 'fiJI' "E~-de[in€dJ data ~ sI;]6b ~ stn.eL'LlRS and ,~la.ss~_ :.fl;l\j~I!I.'Ojg;S' WQI'k wo:rultuf't1iI.1(y WBU wiJtJl 't]w~ USGl"><~mtl2il. I~m, t~~-

O++:h:a:s a ridiJ. s~ o:f@~Eii~. A.ll. C ,@~r-SJ~ ~I'e VI.aiJW ~]fl c+* aJ&~l. m ad:dBiWlriJ, I~.}~* 'iif~~

l~- l~ •

s:CJl:n.{i. uw (lJpi}]i'i:1foor.s. W!9 ha,'I,I''C!: iIllm!ljy SQ@Jl tw'Q. S~h ,~rr'aJtGl'S; 1i.'1tmnoe-]y, t!h'/i!i in~o.~, !ll!~oo.1!:"

< <:'j, and th_@: et¢ractlicm.1. ~~~r' >'>'+ O~r. ~ew iIl]llel'!;l!w.s ~:

•• 'it

SCriP@ ,);",!I!!sl!:{l!IHt i Oil op~r;BJt[j;rP.oi ntler\·,t!J}~mariQe,.. d~c 11 ~1I"[J,tOIJ" P;lJii nt~I"\·,tJlJ!-miML'b!l!!1I" OP;E! Ifat~n" p;1]1 ntt~I"\·;t!ll~m_iMLberr op IHf''d t!fflf" IMefDiiiry rel ed.SIB I[!piliilf"lrtorr

l i FI@ 'f@~ Q~@II'\~torr

lM~fI'~ry all Qcat li on Op;e!'r'a, to'If" Fi~'l dI 'lNhlth !ll!1)E!'f"at'Dlr'

a'll::lletl~ t!I;~d] lrn~ !iil!!u.'

:h ,ad!d.itiOD, C ... + mm allows: us to poovirl!2 new' die:fiWuo.ru:l W ,S.O:EElOI oFi&bi9 'bn:Ut';l:fii ~pi}lr.~b!lrs:.

TJ-J.at:is~ W~ !llamL g1.¥G ~nil m~ tXl' m:li ,o:pemOOr" d:,~diln:g upon the, il;ypGs m: m'gtml£lD1s used. Titrls.'~ is '1kn®"WD aBo Op~rn~IliIf' or.H!~;.rliO'aa'Ii"l;g.

Copy rig hted m ateri al

13~ 1.4 Scope' Re~Ob •. tiOD. O,ernrt,~r

LI~eC,. C-li-+ 'is ,~SQ a! b1oCk-,et:~.du_l'«1l~gua~. Bloeb aDd ~[Je , csn be tl.S€d in constfictllliig, progrmIlJJ!L We m;a,w that th~ same ''!,!''~rim.bli2 llLl!m@: can be, used to hn,f!2 ditltln:n:1it mkI'.i1ifii:r~~~ ~i.mm, ~Il'tblocb" The scop.e oftbi2 vmialb~'€:'m~nds &o:m the pOOLl't o:f:i:ts d£cJJ!u"amull '~U tlID and, ®:flhe b]®:r;'lI: !OOnmimn.g,t)lle ,declan.ti®:n" A 'variable declared im.itie.a bleek iB, aRid to be ]~l 00 th9!.t b1ll!l!dk_ Ctlll;sklf!l' 't.b£l full.o,w:iiil,g :!:'i~~~n!t !fjr~ plJ:'1lli~!D:

tnt, ):, = Uh

tnt, x, 'm h

'1" + '!, a !5

}

n~ 'l;w'd)! d~ll;l[aJtI"~t'±'Q:M o:r-:g, m~t:!r ,to trwo diilr'f:rent ,rnc!UlA:!'ry L1J;C.Q!tJan8, el),lJ1d:ai[[l1iii:~ dlitoor.ten:li, villlll.:ms. S'ta~!2111CJJm in 'ilh~ seeend Ibloek ~Ol. nl\~1' '~O ili~ variaM(!j x (le!l}i~d in &e fif'S!t blod:~ and '~ce "!,!"e~. Blocks :in C ........ are ~ nested!" P,or m;:a:mrp]e, fu~ f:tdlowiD;g g~y1!2 Is ;fl!J]'[U]'OCln.:!

Copy rig hted m ateri al

}

} ,,.. '~=~~-----------"

Hloiik2, is CO[)ltBiin.edi lJD blmrlkl. Note Uiia.it a deelaratien tin i!lll i.:n..n,c:rr Morik ,hkhs ,~, de~i£l!m'tioOO'b. i@fthe OOi..me V.fi..rlll!~'!e 'iJn m:1l!l1w~e;r bl.oc'k OO'Ld~ ltJire[lef1lme'~, eaeh d.e!ilaraiion ,of:x eanses it ,to mi2JJ.' m

a difro.:rcl'ilt ;f1ja:m OhjMt: .. Wi.uhin the inliE!it 1m1~k. "~he v8Jria.hla N win :E'{:1e_!i:" to the da:ftn. objei:t deelared tb~~in.

mn C, th~ gliO'ba] vi!!i',siO:1lL (j(f u. ¥3T,lji'bie e~[IInO't. 'he' 8~f:i,llii~d from W.ilt'hi]l t'h~ hm~:r bloek. C++ ,~lves 't1I:tis 'II'Ii:'iUh1:~ ik'U ki;koo'-~-~ iT a ;-;-: j"', _- rtot·- alled 'i:h- 8('0- ~ail'if,!:t-t-"fi 1Ii1Wii".a:W., This,

___ .- --- .t"_~--- --- .". - UCI]]!!!,:n~ ope:ra .• it. .!1!! ,If'''' --- _-- __ "'l;'- __ , _

lem. 'be used ,to WiLoover 8. biddeau 'ymable. n hiles, the :&JJowmg :f'urm~

lL"lli9 Qper,~tm iill.mv5 aeeess '~® thoe global versien of a ·yruiabLe. flioT' ~i~ :~Xl~wt m~~ the g~obal '\1\ersion O1f the vmll_ble &UiUDt.. (.an.dl not 'the lO'CaI, v,~able OOlm't d~l~ in tbaJt blcC!kJ_ ProgrEhW 3.1 iUw;:tra.te-s tb~!1i fe~;t.i_.fre,

~~fng MaWR~~&C~ std;

1n~ ~ ~ ]0; II ~lOb~l ~

lnt m c: 20;

1 nL k '"' m; lJ\t rn .._ j{l~

/1 ~ ~e(lar~d again

IJ lo~at to inner blo~k

c,cuit -cot "\111~ 'tire in i fll)L!'r 0' 11-1: ~ \n· ~
I1:llut ~o::: I' ~ = .. of~ k ~< 'nil :
'IJLJ t 0(-': "m = ~ .. ...: m o(~ 111\11 u :
(QU <-<: II ~:n -= u ~< ~:n « iW\l'1li: [cut -:"'= II\n'~e arc 1 n eurer olod: 'nil: rmrt ..::-c "~ Ii II c c m.oCC ~l \ n

.c:ou t; HOC II: ~m " • ...... :: m -c ..;: .. \n II •

P"eC:Uf"'n D:

The ~urtp'UJt ®fPmgnun 3.1 w,ou1d b~~ We @re in inner block

k '" 2:0

Copyrlqhted material

m !II! 30

: ;[11 III Hl

~e are In outer ~lock m iii 20

~: ,m ,iii H];

It ~Si W be :r.u:r~ad ;=m. ,\v.i][ ,a].w,ays m'€:!r to'~ gllo'baJ. m. I'IIl. the irDlllier bllX'k, ::m relet9, 00 the .' V£I!llilW ][0 andnot 00,

.A. m~jCil." ,~,p1'teatkJn !l;Jf the SC{Jpe res~tll!tiDF1 openl'w ]S, in '~he classes m ide~tiifY the. cl9SS 00 wmclt a :rnf!mibe:r :W_IilJe't.i;OD b!llii~G~. '1'hi:l1i 'W,m 'fula d.e~t in. d!gi:&illa't,(l!i WhflU thG:: cle.ses ;[jj[',e :iiIllJtr'lldlllced.

A-si Yi[n:ru :mow ~ C++ iP~ts us ,t@,define a cQ~ss oontaiFJing vRri®'lilfl '~lDes Qf data and ~~(lns ,~S m~.m;oors. ,(:++. ~isi) :J!€ErnTLiJt.s us '00 ~.E! tthe class :m.e:mbem 'thil:"ii!lUi,gh. ~o:in.tQl'.!!L Ib, !ml'ae:r to allibi.€:vfl 'this, Ct-+ PIr'ovi,d\e:s a ~,t of t~e p!Jin~;tg-m~IQ'belf' rrp$II"Qlt,(Jr'S" THlble :ll3 .s11Ji)'Wg 'fii@siI1; o:pm-;arlio:r:S ,a[l~ t'beir rnn0ti.om.

OJMNlor ~iII

;;'. 'ir.6 dil'tlru:'C a ,P,(Imlter tG ft m-e:m'ber 6f a elass

roil' !o 8i~a ,a !IiIfI.~.I!]fI;OOt u.s!ng ,[ibJllet iiill:mC DM ~ ~ m it!b:at mgmbe:r

,->* '1.'0 iii_~!i ,bi ~00t "JS~ a pOOn'lier ItO the ~jKt Miid ;(Ij, p!)inlte;r"'~ th:a.t !lEe:m~

Fmfb,er detail!!!, QiiL these ®:peT81Wffi wm be ~.eni[lgfu] oniy ;BillaI"' vro discuss c1aJSat:3,t. and tihE!:fe:fu.l'oe 'Wi! d.~f$.l' rtha II;I.$iQi ,!l):f !tlIDm:'ti:!81r deref~g o:pe:r:amlrs lmti[ them"

C-" , ...... , .. ll""'l"'()·. ,- - _..:ii . ~ ... ,111 ...... 0''1;, ,iCl1r'til...,.j;.i"'n'f:j,:to :allooa'llei :m.amal('V d._~r.El~11l:lfiC.idl'!lr at run Mm.~. S:im..iD.m']v ,

~~ anlde~\1 ~""'--~"''''_!i<l .. - - . - - - -- - ",,",'oJ'''' ... ., _. . , ... ~

'i't uses thel f.i.lln~ti~!il, :heO to [~e dJyna.11I:liicaUy i!!LUOCBImdi, migmo:l)". ·We· use d,ynaJm['~ :aU®eRtiQ]Jl, 'm~1uri~lLOCl$ when :it.:is !DDt 'known in ,8.dJvlU11re hilrW mu[:h mtDlemoty ,B])~.ce' is needEd. Al:tih .. m.lgl'n. C+T s~.ports ili~ mmrtioos" lit also dleines,~' ~iLryr ~tws :Ii!ew Pd, dum-e'w tba'tpe~m.

Copy rig hted m ateri al

=======- ••• _, 53,

'[h_~ 'bmk I(}] w~mmlg ~nd. firccin,g ~ ~m.ory llo a br,rt:mr ud eW3[~ Wa'1f. SiD~ these 'o;pe:mmm mam:p1!D.l!a:ltc: !l:lH:Dl(J~ 'O:I'l! Ith'B :~, :SWl'1ll, th~f iIIIT!l i!l.l!SQ' b~wn as,.free S'to'J"e !IDpG!'Bfmrn:., _

~ gi;jfW oJ~r;Q;tlCKr ean b~ 'used 00 ~a'~e iO~~ts of,a!f.kY type'. I't ~bs the :[Qll@wing' g~~.w, fijhml:;:

I po~n'teii"=vQr;~:atHe ': nm' li1etJ1=t.Y'~'j' I

'He:re""ain.f€r'-MiI":J'Gib'~ :iB R pom'te!L" !lJfty:pe dtl!m-;~p~',., Th_e :g;ew I~raml." aJ[\ocates ei,tdliciil!!i&lt M~ W ho])d ~ data object ,~f' t~ ,a:a;f~-b'pe ,@nd! mU!m~ the ad~~!;'ls of 'the ~ij~ The I~ala,.~)',pe may be any '¥aiirli data il'yJic~ 'Thi2! pcJ!I;t~'e"l"irJliJriable hoods 'the' ,ad:dn:§ Oltllei 'Ime'mory spnoo ailoea1iim :lffiilmiD:l!p]es:

Pi Ie: l'IIeM 1Ii'!1t~,

q :: ne-w fl o~t;

whm;;e 'p i~ a ~ter.' of' type iiDt 8lild q lB It !Pnlit1!ter. !i]f tyjpe 'flfi'at. Her-ejl p :and !lJ1. m.~t have alHady been dedand as pcm:~8' ,of appfoupriate types .. Al~:ii.ti'ie'[y, we ~ oom__blne ~he d)eclaraJti~D, of ~tem RDd their ,rulSipillIlleni~ ,~S fQU'!Y!iVB:

ll1i1t !iI!~, .. ni;!W '1'lilft~ fl~!t *q ~ TI~W f]o~t~

1 nt. ~lP "" rile¥' '1 nt O!5) :~

""1""'&o~' 'ili'1l'iI =: ifi,i!iW ""l.i'i.!:l,ojo l'T _ i!::,\ ., II 'iI!!!iiI,I~ ""Ij 1'I§I'flI II '!.Iu!r~f ~'~1- lI!

Copy rig hted m ateri al

A:s me:ooonoo, a:.rul['[ier, 'Dew can be used 00 m!:l'.aroo' a mc'm.azy spaOi2l ]'01" any dia,ta t~' :U,lJjjithldJitl(g ~et:-d~£D.1I1Iedi it~ Bueb. ,a~ an-8!.y~, ,1!It.TU'CtUJ'eGI ~T!dI cla&ses. The' geneeal :fuX'm :rol" ,8, iOD.e~meifls<j~nal! ~~y iEi~

~a.'~e!;!, a me:m~ry' ~:faee f@i!:' g .er~_Y' o;f'l]~) iinte,gem. :p[llIMl will te~ to the' fIT..st cle:rnetllt, pU] 'to tihe' sOOimd, ;gJe:Il'U!,Dt ... a1MI, S!l) 0.0.

. in'1"ay_pt r '. I'i@W '1' tI t [3] [&J [4] ;, ,Ii r'l"a,:r,_pt r := rie~ 1 n t [iii] [~5] [".4] ;, ~ rny _~t 11" = new t flit [.3J [5.] [ J; ,~r'l"~!c~h" :iii n~ 'i ~t [ ] C5] ['~J ;

II '1 e;g .ail

f J " e-ga"

/f nlegal 1/ '1U 1 @~~.l

TIre :limt, diime:ns:i!J"J1L mary 'be ;B v:m.iabJe wuse vaJIue IS, supplied iBit l'tmtimg, Ml othA1:.!iS llilJ1Jst be {l!lJll;StEmim"

'YfheIi!: :eli data il]i'bject is :!!WI '1mlge.J' lIleedeirl!, itt is d,~yecl to :reieaBe tile me:mO'ry spaee ro!' N1!ISB. 1'he ~tlem] !lIFtrrI, 'l!)'fUs n!;;e' i~::

d.e' ete ~~ d,e1.etle q;

If WG wnnt 00 ni2l ,a dyDa.:lJfllka]~y ,D.1!I.ooBfOOd ,aH,~y." we. m.'!.fi$t 'll.Ise '~he fullowiiilg f~~ oi dlel'f:te:

I de le te {$ ':lie] po't,~ter'- ~or '.ab lit;

Th....e size' ,speciles 'tiI:1.e iIlJumlbel" @fe1e:ments'lEl. the RlTo8J.Y to "be flleed!. The :pNb]e:m,'Wit.h, 1ilU 'lbrm Is that. 't<h.El' prO'gl.',Qm.mQI" ~hil!l,llld. ireirPE!mbel" 'the ,!iii~IHI!! {~nh '" 8!~. illlecen't. 'vemlll)'Jls of C++ ,to nm req)l1!im ,thf: si2li:li '00 'be s.pcciiled.;, Flor' QKa:mple,

Copy rig hted m ateri al

p == l!Ie!.ll '~i!'!rt; H( !p)

{

}

][. :U ,a1!lto:ma1ii~a1!ly oeamplIJtes, th~ S!i~~ oft]w dJa,ta, @'b~'ed.. We. DQed ~~t 'l[l$B tllie' '@'piJr.aroo(r :8iiZleof.

:2. :rn:t ;aUliDmartjimUy reQltums t;k{!; 'C!JI',f!Rct p:!illlw:r type, so Uilat 'Ulerra is, 1Hli n~Bd, to iJUI~ ,a, type C:3ist.

3. mt ]8, '1Ixrssil:i1e ibo :iniJtUili2i~ '!t:ll6 'iJ;Dj{ict wlmjjL~ el!"{la'M:n:g '~:mamuirf ,s[p!a.efi'. 4= JKJke Wly Q'~~e[" ~erat~u;', g,-&w awd ,delel_ e cain be (j,ve l'] I)] ad ed"

Mamffi)!,jil~iroffi are ~,pe:r'SJWm 'tMt ll1e used N :fotIIm3t the dJaJf;a, dj~my. 'fhe nlLwt '~iln]iJtllmUly ~ m.£l!D.ipuJ!y!~ mrl(~ 0iD.d1, ,UD~. Sfl'tw.

Th£I, ~llJd!I, maniipulat"Ckl',. 'wham ~ed in, an out])u:t st9ib!ment, ,ca~ a :ttnefeed 'til] be, ~FiIied.

It ~ th~ :$.~, e:i'cect as 'U~~.n-f: th'e 'newline char3~e:r !'\n~i. 'I'OJ' 'e.xaurRpffie, the s.ta.temEm.t ...

ilXItII'l ~< Uill := II ,0;::< fill <:< ~nd 1

":;\0:; lin := II ,.:::~ n '«: endl

<''<;l !I p' := II '<:<. p ,<<. end 1 :~

would eaus€ tb['i~~ lines of' '0'Ult]!i!ut ... OIJ:!'2: f-O:f' IG~ 'VBlriaib]hB. If W~I ,asallmRl' '~he vahles i)!:r the v,ariaMes, as :2:5~7'~ :14, and ][,'5 resp.e.crtively" 't:JW; 01llt,pllit. 'ml] :lJip]l!eal!" as fMlocWS:::

Copy rig hted m ateri al

mil' 121~[9IF'1

n '" [!I!J

po:, P17~51

It hi, imp.~rt.iilin~ 00 Dwte '~bat 'lhis, :tb,~ is not the kleaJ wtftUt.lt sh,o'Yllid, rather ~~ear as '~n,d.e:r:

lfT1 = 25917-
n • .l~
p • 175 H~~'~ T1ll!mbifJ'S aRi r,WhJ-jucgUfi~d. 'This form, ii}j O'liltplllt is 'pcS8~blo on]y if .. w, ean s~ a rouilmDn iielld widtb. fur all Ure Dlll!mbem and force thern 'to' "be printed cigb~jrustifiedJ. The, iSeR¥ mampruamr' d~ 'lthiiiii job. It is, ned, as f{li]l~wa::

'r.he numi:puil:ltool"etw(!l5) s:pecmes ,;[I. '1Ii.e[d. 'widJth 5 fuJi" :printiq' the v~'hle oftbe v~riajble' S'WD. TIllis, v.aJJue is ript-.j1JBtHieli 'wi:thiin the 'fi:e1d, ,8S ,sbo.wn, below:

·i ncl uda ..:;i l1s.tn:i)[lJ;I!'

ti~~lude ~i~nip~ II fer setw

1nt Ea~lC = g50~ Allowance = 95~ l~t~l = 1045~

c~ut <~ ~~t~(l~) ~~ ~Ba~ic~ ~~ s~tw']O) « Basic ~~ endl

<"" set, ... nO} ~<: II A 11 (J'(JIam;,e M « ~dw(lO) ~~ A 11 O'If.ance <.::. end 1 « ~et~(10) ~~ ~rQta1" <~ S€t~'10l ~< Tot~l <~ endl:

r~tlJlI""n o~

Copy rig hted m ateri al

-----_.11 57

Ba.si c 950

Allowance 95

T()U·l 1045

~~~=-'==~=-d=-e=-~=-8=-~=:=~n=-~=_='R=~=_=,a=h=-o_-~_"-~~'=.=ted=:=,ng='=b~I~_~_'~_-_-~_i6_;_d_" ~~================~~

"'] m:::1IIlIi!le <f os"it'li'ei3li'P'

{Is.trr,~am S s,ymbol,os:h'@cra t. out~u1i:~

i

}

DID ,symbQt. is .~, ~. ,m~i~Il'I£IJ,tor which mprtGsglPd.s, B.s. 'f.b_~ id.Gntilirnr. ,sym'bol eo. 00' Uggd] "wi~ngve:r' W{l: nredl to ,disJday the stri.D!'f;r B.s •

.c::+-+, :pii!!]"]Eilrbs e:.xp~icit it.yp;I' QOll'Vtar..sron. of' y,mialbles ,0:1'" 'e:Np,f'S;SS];Ol1I;S IIlS;llllg the '~. CEI.s! O'pcmt~ll".

'rFBlwtiollBill C casts iIJ!II!Ill ,ausm;~IJiood! in. C++ b.~ a :ru.n.ctiioll.,ea]U EotaUOlll iIiliS a iSjmImme .aJ)l.emati¥e, 'Jbe :foUo-w.Uug· two ·vell'slOliLS an e~trl'lj"aJle'n.tt:

(ty,pe-·filme) expr>ess 1 on Ii c lj:Joti!rtj' on 'lype=nl!!rDe (.e'J.;PT'e-ss ~ 'Olil) 1.1 (++ nohrt ~ on

;[Ij'i,!\i;l'l"ag;e I!I! s u!!lj' (n oat) i i, Ii I( lJ1'Iotilt·j am ~\1\er'ag'e' =: S u!Q/fl o~t (~_) j, 1/ ('++ not~t.1 on

A '~-"'I?-]llEi!m.e' OOhJiIl.IVIe,8 QS .if [t, [;s a :~1;m.eti.CIn. fur· O!llIlrVQrt:iiIl!,g '~~U{iS to u ~~igm~. 'ihyprl~ The 'rull:mtiO.D ... !:li![U notntion 'Iltl!lua1f[y· Ieads te s,iimpk:Sit ,ruqm~.ssiOO1L:S. However. ~ iJIl, lean. :De used! miiJy if 'tnG type lS, an idmtio£ll·. F-or GNamplG)

P :: lilt .~, {q):

Copy rig hted m ateri al

A.[tema.tiveilly, we {:u, use typedef '00 ~aiOO i0iD idml.tmB.l' !lJf tlW :f.'leq,!!,1~fied '~e !i;iJ)ld use it iFf!. (tiw fUfietiOfJ;;tiIj R(ltal't1i!!iI'il.

typedef i ill!. ' '1 rrit,Yt.; p "" '1 nt_pt(q};.

.' I~O'~!!i.'L,cast ,', ,struticJGt

,', d}namiCLC'ast

,_, lIell:r!l:el['[lreLC8Jst

An. e:K]lIr'essi®:1li :is ,a. IOOmib:m.:lartlOIl of !il!perilit.o:rs;, OO]jJ.st~·~ :and v~ciS!b]e9 arr,:ilillgedi ,8]3: per 'the, rules of the ]if!j]]gtliage~ It may also w_c[ud,(l' fUitli~!!iI.n 1t1~IE 'L-vhri.cli :relt'llJlTIi 'Vtdi!Je9, 1iLlJ: ~:rem.on -m~ coe~Bt ,of'miLle or. mote' olP!n'aJi.I!lisj and :Zrl]"o Of' mora o:per,aJi;ll)l.'S, to P'f'oo~JOe .a, 'value. ,iili:M.p:reSS!i!llns. :may be of' ~e fuUo-wing seven t.ypes:

., Ccnstaat e:xP[I!l:.Ss']OI:l!S,

• rnil.e.gt.a[ expresslens

• F,I(la'~ ~pn!'S9km:s

.' ,Pojj[jj!bE:!lT a!\:~s.6ilJoo

,', :!RelalJti.onal 'P~e-.!1l6±@,n~,

'.' :iLogjml eKp;re_ss:i.ons

.' :Bitw;lj~-e expiNssi<rJi;S

Copy rig hted m ateri al

.An e'lqJUBsU:D may' also use com,Jbn~,ti01U!l 'flf.'!he ~bove, eX-:IJ![\e£i!l!il):Ji!B. 8uc1il e'lq)l"essions,;Ill\~ kn®WIl HE comp@ui!lld' ,~pNss~ons.

Cunsta:nf ~i'emO'u

GI(]~t BN,putSsiol1J.,S OO:tls:ls.t, (1!f (f![jj~,y oonSltLlftt V'a1:~e5" EX<i)![[J],Jlii~:

1.5

:20 + ,5 I 2.0

I~I

,~Di'~ Expr:cSSlODS

:rn:tegnJ l~ressJ!!Irlli i:lH' 'those, whitt:h prOOuae iinrte,ger 'f>e'S~[~, ~I" :impr~ln~t&ng alil the ai!Jjmm~ttic and expldt t~ {iooJiversioillS. E£amp'lle$::

f!!I

IIIi :to n ., 5< IIJI ;r" l:x I

5 + lnt(2.Q)

ROIt: ~teSSio.M

Floort ~~sions 3U: thos~ whiclU,~ iiiI!'fte:r' all OOil1vem®Ds,~ prudlliC'e flMtlllllg-,poiint re8ult&;, Examp]es:

)l: ,t, Y

):: 'i: ,,!/ ! H~

~ ,It f1 oa."!! (10) .[1[11.715

"~~11' KYpresslons

P@lllt~ Ex~Lrnus prllJlilllCe address ¥ahles. EXam:P]es:

2!m ptl"

fii'1til' '" :[ [6;.;~n:1I

ll\fiIa.'tii.ollal El(p~e~

Htda1iona1 ,EqJll.lesswns yiel~ :I"eswm [of type boo! whieh 'ta1itea, 8 value 'true [00' :~, JEx.9.m.~klSt;,

1; ... '" !1

,,+b "'''' (+d ro+n ::0- 100

'WhC:r:I! ,oritmnW1:l '~pft:Sl8i.on$ me 'used OD, either side ofiBJ :[lelarmon8l[ Q]lieratbQr.~ 'Utey wi) ~ ,gyaJIlllatiM. 6.mt aad 't:Jrn'n th,e. :r.eSWJtis rnmpum. Rlelat~!lJb.:al [ex,pT:e5.sioom 8...W U!ilI M,([JWO, ruJl Boolooil'il: ~JtI'.ro:.s'sions..

Copy rig hted m ateri al

61 •• !;-=" ========= Obj~\ct-Q#e11i~Ed: ~grl(J!mm!Pil,9 Ulfth!C'-lr+ Lo.c:~. kp~si(ijncS

:Logiml Ex:press1.oIDl comil:rlne· t,wo' !!)]' ·[!]].0lr'-e 'n!l81tillru!i[ e.xp[lesaiOJ1\9 and [pllooaws '~l type resuFt:s. Exrun:p]es:

B.iJ~ bpr'~$SlollS

Hi.mae Ex,pre58[QJU3 are 000 to Iitni:.miPVJJ~'te ~ta. ~.t. b~t level, They .au oo.E!i~~J.b '~~ed :t9t testiiD.g or ~h~f.tct!"lli:' bits- .~x:.ar.tl~les~

:w: «3 II Shift t~.r,~~ bit ;OQS it i O'R tQ l t!Jt

'I ;>0> [ // S,. tJt Q11'e' ,tl'" t pos I ~. iO,!'l t,o r:f ~Jrt

AN'B:I ,c++ has mJtroou:eed. 'what are· ,t.eJ;mOO. 3.5 O}'J€T-aror' hy,~· th:i!it can 'be used ,SIS. alJtem~tJv.e rep[le5eJia!Ultion fur ®',P'ernwr 5'~1J61~, Overa:tw;' '~l!Jiflds ,~e liven m 'Cba,p'te:i' J!6\.

x '" (y := ],0):,

or

.:.: = s := 10,

A ¢haltu~141 ~i1itS!teIl\i.ent; ~aIi]'i~t 'be n,isel!l to, ini.ti~~:iz.e 'l'Qnafbles ,Qt '~h~ t:ijm~ ,o{'d@~LS!ra'~l00],. For ,~~QI2d~ tb.~ s1i;a'it!1'l:Im.!211Lt

flQ~t ~=12.34~ b=12.34

Copy rig hted m ateri a

:blbedd,ed .. ~ipn!meot x = b = 510) + :1Qo.;

(y ;;;; SO} is ;WD assign'nlQ:r.lit {JXlJ.h1i:'~&i00l mlo'!.VI:ii as Ii!!'JnbQtktQd. :assi\~nJl:. ,~m', thiQ; Vaihl{l; :5®1 ~, ~!i!~OO ,t-o y m1g, ,tReJ!l tJiu~~ I'eS:IllJit 00+10;;;;; 60, is ass~gDed to x, 'Ibis ~tatem.€:\Il!t ts ii~tlti~al '&0

!1' • 510;

,:( .. Y 'Ii ,H):~

i'iii. . .,. ,,,,~,,,,,,i;, ..... , +.~ ,;"" 'i_="',w'" ' .. '." ...... m.n"":r.~:m,..J' ,"""''';i'l!~ ",.,.,\",,;.;,,~. "1ihiPil'""""",""i" ""., ' .. :t.. .... ,..i!'_ ~\.=-:- . .,J "''''''''-~.''' ..... "'if"; ·A ~~ Y'!.F'!Ii"~ ~~V.A _ 19 ~.Iv .... 1:1 ~ b-V"t!rJ---J2'Ul!l§r.!I-'-~ !a~-~45. ~ .. rl'l!l-'-~F!Io!;l ~"""''I.'J'Lii "iIi~1'l VJii, Ql~~r. iI; ~lUJ~ "-"Q~:r~'ail"'5oi"trMi-!'I"-~

o.pe'fMttor. The geRem foi'l'l'L of the ecm;iJtUiLd ai9Sigmme:mt opera/bot is:

m. ::: ,5+2'. '1S j,

'Wben the oit!imp"iDe:r ent:(lil~J]jlber5i ,an 'ex:pres!5im, it irliivides Ute .e;x]li~5iQ.n,5 i:mJ.'t.Q ~ii;d~~,re.ssdi@,Jles. '~@:nstati!ng ~f ~~, 'l!I!peI''3.'tfW .~d !Wl~, ,@'1" 'twiW 'I)J(!r;ands-... F~i" a binQ!'Y' 6'Jiln''Q.!to:r.,~ if rtllG ~,~l"i!1l1dJ5 ~ d,iff:~r,; t~ oo:m,pi~]" ,C®,I]¥e:rts 1!l1't9 @fthffin ito Dlatm with ~he @ther;, UlS~1!g. ~b_1B ,~ thQJt· 't:b~, ~mjilin9:F" ty~ ~s eon,~8d to 'ih"Q ~~~' '~\o Fr!ni" '~Qm!pl~, :ifOnfl' of'tihe· (ip~,EIind:is 9llL :hiiiC, and, '~_e I!P.'th~I" isa i8&8!t, thl!!i ,~nt i's OOtl,w:iibGd lillirn, ill iIl'lll\at beaause a :lJibaB!t iiI) MoLer' than. i8lD int. '1'he ''W:arooJt''-:fu[i,'' !mOd:~ shO'WJi1 Uri, Fig. 3 .. 9 iJUus1ira1tes 1i~ me.

Copy rig hted m ateri al

''!fUII,,'''' ,'1'..", e- ~L,...4,," t i , ',," "1,', .. , ~:" I ";1-.,,' c, ,.,.j,-..:I ih~" - '~, ;I. "f'I-"' "

¥If .I!lI.e~'!fer ill CIrl!B!r or ,5DA!li\l."~ Uil_ a:.PJI@!a't"S l,n ;fJ!II! ~,p.~$~(IIn~ ]'L lSi OOn.~] I,I~, ILU im! ,WDJIl;. .!Ii .. ms IS

eJ3!lloo. inwgml wd'de,p,tiug OO\fl:!U 1:!1."siolfot. L'ill'he implie:it ,ao:nve'.l'sio:n is, ,ap'p'lIie{]i, oru;y ,a.tlieF eo mple:'tiDj' all mJbegrm] wirleJll;mg' Cml,"lem'oDS:.

~o
>thar ahorl in,' ,klf1!i! fl{Jfi~1 du~bl'e wng dl' uble
LBO .. ---...... -
MID" mt :ilitt iimt ~~ :~DllLt dfiubJJE; :IMtg ,dio.u:bl£l
iiiliort, mt :ifil!t mt LllInil: :nlllEiJ~ aoUb'h::i lo.ng lih:ru.'hl.a
il'lit hrt. ~"rt mt ~j)'rI~ :~oat double :kl1l:,g .dioubJ)e
llQng '101'li long ~ffili!ll roni' U-Qi1t dO'Ulbl:e :Ioog ,d:€i1tble
:FIbliit iD)Qailt f'lilMilt, :ll!Q8it. fUciltt t1nt d~uJbie I[!mg: a:C!ulble
~ble dD~;e .di!I;I,l'b.~i;! ·dG1,l,bJJ;! dll)l,]n~i;!' dOlLlbli!!' d!gulhl-e :~g!lg d~u1b~
lu Ii t1' UI1ib]c: l~ WEi~ !~g Ilhng liong' Looi;g i;oon.,g ,[I Cu.Ila.e
dloi;iMll!:' d{]u.M~ dmll,bi~ dou'blA!!: a: m,] ble clou,lo~~
RIff) ,_ ,nigftl'-'iw.nd 'QP~nd'
U-lO - Ufi~M ,opemna Copy rig hted m ateri al

A.s ~ted ~aTliw,. o~looding mMM assig;t'i]n,g MRreot :meanmgs 'tO:Em ope:rarli®:D~ depelldin~ Q1]. the ~'teKt" (~++ '[pe"rmitc{!, Gl,?-'€~lQ;(tdling ofoffi)eI'8ioomJ thw ~ll~1 u 'b;j, ~!l!igg, m.~tlpL~, me~~ to ,O'pen:ta:rB~ MuaJilly, we h¥e 1LIBOO. the concept of ,over.1oadJimg iiD ie alae, nF'or: ~~I,e,~, ~he ~,PNSitu~ i)l when applied '~,.a :poiillit.er variaJJiej< gi,ves 'the~ value, p:.int.edJ '~ by the n.i"ilm:~ar'_ '!E!iU.rt.ilt ,is!:eJ n; .......,.,.,.rm ... n;I-, .,,<;<......i ,'""'-..,. ',-; " ]~-'~ ,c'. - ~w - ;', m'l·~&rs.. Tihe' rU.lilml'bSl" awm t~!B 0.1'

,1""'. . - _. - - _. _ 'I,;'!"I\!i~!!L_",", ,y ~I;;'!,!I ~VJ:- mU_'~lplLy.IIlg ~ 0 ~;Ui !.1'1;: __ . - - . . . . .;or it"

op~l"8i~diE deciicte, the nSJtlllf.>e ,oJ,~pe~e:tiQn, bli jj'®~l1jlw.

''fhli:: :i npU!tioi!JtW:ut ope:tiB/Wm '<:<; ,Bind >;> ,SlJ:I'e geod e'K.t'lID:(!.les ofQ])elalhJr !!J'I,f-er.JjjJadliEiG. MU"tifilU,g'h the btUitrl~ ~Mm 01 t~he « ®,perj:~:t®r is :fur ~'1ng o:f bl't5;, it,~ alse used ('OW' d~~~l;ai_yif.jJg

th.,. v,~['.'A'" Of"'Vi'ii ' d';o;,i .... 'Ii";liffll ... ..., "1I"Ilo.:i-' ii;. -,' 'Co."", . ,.,.,~.:i- "i!I,.~j:f'll;.~~ ib'lif. ,j,I1-, .. h6""~'ar r~~~ ~ ... .o;~"""'am

_ .., _. ~ _ _ ~"""" ".. ~!.'I:I!. "'.1ll"'~. J!,Jl~ 11]8;9 ~e-1Ji magE! l~",i!.!GI~ ~.!'. 1fll!Ol!;;>!<I!I!,:! W __ ",",_ ..

when a R'UiI_.m'l>et' Ql;ov,e:rleadmg de:l1nj;tions f®:I" <<. ,are ,btcluded. '!hl);l~ the ,~tQtem'e'.~;t

[m\l'~ke$ It~ d~fl~iti~rw, r~it dl.isplayilig Q e'h.' v,aihl~;, However;, rL'OOhQ 01: fih.tASQ fl!~mHo:rn;s iu, ,~$.r,e~m mJ:t!d the buiU.-ln ~e-atIl'mc' of the ®pe;rgliwr,

Simn~rly, we' eaa defiine flail'itio:ru:!J[ m,.e;an~i$ 'b) ,ather (~++ {!pera:t@I:'s" ]1.7i0l" exEJJm~le" 'we can deB€!' + oper,Il)OO;r ibo add two st.Nctln'e.s qj' (;ibject6,. Al~t. pJ[ C++ (Jpet.a~ ~ 'be' ®'VeriMdeirlJ with a ,tew ,~ee:ptionli s,uciU ,:Is t:lil,e membe,r..a(()e9s, opet;"8JWB (~ and, .. "', -CLl'I.>IlitJ®Il!a1J '®,pm'atml' {?:), 8.00'1'$ r.Eso]u.tiilnlll oper,atm: (::) and the ~]:m 'trpera:~l" ( ~IJ'SO'''. ~Ilitton_s f~r '®,peir8/wr mrer]iliiad!iq' M-e diiiU!llilJSsed. in dJet-rul in Ch~pt~r' "1.

Allthoup C++ emables us ,to ,add J]iJiuil,tlple meaJlill'lg5 'te 'tlhe' 'DpentiM.'iBp yet theiw Ml:s~~tl®D and preeea.eIlCle' :r..emarun tbe is!UiIle,, F'fir 'e:K!UtLplJe, the m.u]U,p1±eation, ope:l',albor wi)'[ ,eiUotinue havi/ug;' b.r precedenee than '!the add operator. ''iII'a'Me, a.s pves 'the pJlooeide:noo Imd

. . ,,,.' f "1] 'b C "1I7!L ]. " . .:il· ... 16. ~~1I r- 11 ~ -

IISSiliiitla'tIV]ty illi a!. t!i!iI: •. ++ '~mt~r;R~ ,ur,l:le 1~1,lI~ .Bi.it!E iL9teUi ]1Il,IiLI.EI' wuEiii" 0:: '!llIk!~B~

:~enoe" The ~abeJlspreJh;,MdPfNfft.rli;odjEi,ttiQ:U~ the useS ~:f'++ and --. M90~, the symboLs +, -" "'. ,and.,& :aIree lYsed! as, ®O'~ u_rn:~zy ,lU"!d itJimarrj! opel.'a!~n,£i.

A '~~il1,lete ]i~t ~f i\NSI C++ Q])e.Fa'bo,l'.\li ~~, 'their meQIDri.ilg'Si. li~~~" (hSsnciati";1ty ,rulrl 'IlS{:' i8f1'e pel:} :iu Ap~ildfjx E,.

Copy rig hted m ateri al

.,

-:> . ( ~ ( 1 ~tfi.x +. ,~~ih _,-

preix. + +- pre:m-c. - - ~. !' Mary +- UDm'Y - '1J1~ " '~D~1!7 &: n·~) i:';Ii~f~ d~

.... : ,., -~

'" j "I>

+-

<:.<: ::;;:>.

« .!!! ;;.()o !!!

== = t==

&

I '&&

I ~

1:

:;::;!Ii; =!~% =.+ == ,«. = ;;0,> := &. := i!.= I =:

• ~[l.t!t.Ii!I'tJ..B}

. . - , I

h~_iiil~~

~~R:.~ ri~~

left to right

['hIllt tn left, ~.,tQ q~bt ldbJ right iclt m iiglil't Idw~M'~ Id.to Ii'~pt Imlm ['~gbt lcitro rigM ! eft to righi~ I~ w'rl,ghi lcit W F.LghJ~ Id m clgh~ lfilit 00 f:~gWt ri.gb~ m left ~dw~~~

In Cf.--!l-, :aJ la..l'p ~'ULlIn;bel" 100f fULnl!:ti!):!!~ !iQ"E!' ~~ed that ,~ :me:!!iM-p!fI, !I\i_Rd ptQC:E!5S the dlRih, ~[i)~i~dI in. ,obj'ects, A fUD~.ihr.li. is set, 1!.rPI 'b) 'perl:UI'm. a taslt 'When'~ '~k is oom.pLe..~. m:ar__ny ditT€I:r.e1Di!; iIl'~gt!ritbms ean !be d1es~ped 'ito 8ie]ri~v'(l· t~ ,sam!2 g)Oal., So:m£ ara simp1.G te ~m[llIl',ehend~, wmle Qtner..s are DDt. '!Elqllen9re has also DQWD. that the nmnooir ®'fbu~ that ,OOCli_j;' ia< '~ela;t¥d. '001 Ute furnla:t ()f~be Pf~. The t\~~t 5~Quld 'be ~uch th3it it j~ ,e:;!isy 'QJi t.f-a~e the fl@w ~f ~tkrA ,@f ,i§~~~t~, Th!~ wo~.W hel]) not Qn1iy' in deb:g~I' h-uwt aJJ5@' ,i~ the review aDd! mM~te~oe OlE 'the' ~,aln Latter,.. Ome' meth.OO of ,acl!rie:-riDg'tlhe, II!)'bjemi,"VeI .o:"p aeeUr'Hlta. e~E'1;!s<lsta'ii'il.t ~nd iL'iiI!iim'W[iIil'b~e IOMeI :15 't.(ll ~e ,l!Jne iilll" ~ 1~~~n~ti4']l ,o:f ~h~ f!!)n~g ~.~ ,~jjitm~ a-tmClt;l!lI.'j'~:

:1. SeqrUeJilille struetnre (Str.81igbt lim,e) 2:.. S'eleoti~g Srtne~ure (b1:'mclilltg')

~t LoO'p' ,strn_iI:>tlliffG (iw,a,Mn ,01" r~p;iI:j,tion)

Fi;gm-e. 3.4. ~ bow these :strllietiW"Gs a.re hnrp1!!l!liEumood using lmI?~,n~I!)';, 0I,j!~~~' ,c~l1oe:pt, a. PIl,pulali" a.pproucllt i!Jsed :Un m~d,lUlIT ~l)gmJ!'i:fl_mj:ng.

Copyrighted material I

It is D_P0:rtLmt tn ·tuI];cl.erstEmd tfurt all ~rogrnm, ]}Jro!llessm.g' ctilll :be. oodJed by using ®Diy' itb~S{ji tb1!"{!Q ~!l;lI,gie Si~rliliCtu:ra~. ft.e. .a~~~!!I!a.eh ,af Uls3mg ona Ol" ,UlfiNii 0$ th9S,g, buiA:! le@n.~nt C(i!D..5truc"b in PJ!Vg7.MlIDiTtg, :is b1GMl. ~ rtrwc~ured f)rogmmmi~; au irm,~t 00clmiqu~

H A..__ • ,0,

m :sO\U.lWiIlI!i-'illl ~nn:~.

~e ,If' stalteml~fa!t'

The ~f' Sta'teOi~~ii:1t iEi, im:ple:meoJt;ed in, tWlD :fDmm:

• Simple, :if statem,en1; '. :Ii'~ .. elseffitate:meDt

Copy rig hted m ateri al

----------------------. ~-----------------

Copy rig hted m ateri al

lirf~~II~hl

Two !Haij br:ai'iICh MLIII~ braFith

~ E:m~1

iI.

\

- , -

I -Wlil!!e. '!br I It Ilill"f"'OO Fil:rn'1

1ii~ ......... 'iFI~~. ~ki!Ia1l1.1r[I~.

1 f (e)l;pres.s i on 1 s 'trl.!.e) (

~,

action2'j, act ion],;,

~,

else . {

The swlt:C.lit ,ii'M1eMeot

ThiSi is,;EIi, m.1iI1ltiJ!p1&bt{I!Qchmg .s~tew:Srilt WQ~. based on iEI!, ~:@~Ii,di!oo~, tb~ ~0F1fi:r,ll)1, is, tr,ans!~, to' 0110' of ilih!2 ,m:Ja1f.IIy :p@S$ibi.e' pnm.b" This Is i:m,lomQ]l1too as mF~s:

Copy rig hted m ateri al

S~itch(e~pre~~ion' {

c:II'se 1 :

I

,[J11t't 1 on 1 :'

J'

ca,5.!El2 ~;

{

• ~ctionZ~

1

{ actiQn3i, ~,

dJ@'f'ti;liu'l t : [

act i' om ~,'~

~

'!]"he do-while, is an e:f;it-·(:.on/tr~'l'e.d LOO;p ... Ba.s0d on, ,D, ellJllditt.iiilllli,t~h!tli iOOnt:tO:~ 'i~ '~iIfU_n:.:;funcd, M~ 'to a pamtular JliDintt in 'tftle' pro,gtarm. fh~ b-yrLrtax,]S ,as ,fOllOW'S:

}

wh11~(t~nd1t1Qn is t.~e); ~cUr[Jn2;

The while' shitemeDlt

Trus: is ~lso ,a loo[l;ll S'~eruN, h1m;t is u. en~r:}'£oomroUM ,one. The synt'fIiK: is as foUow,s:

~~1]e(c~~d1~ta~ ts true) {

l'

act i !DnZ;

'lb,e fM ,statement

1'h.e 'foil" tis iiIDD ,El'utry"1El'nitriEdlsd loop iiIDDdI is, used wh fl Ill, ;!;liD aetiun is: to be repeaeed :fur' ,a prie{i.ere1':minedJ BUltlibe;r of "tiil~U;!s.. The s,;yntax is as :fbJlL{!<WSi:

Copy rig hted m ateri al

f.or (1 rt! 1 t t 11] va 1 ~e j, 'tJen; '1i III c:refbe"t.)

,~

ilict t on 1.:.

}

action2j,

'n:U3 SlyrJim ~r..t1h~ contr,(Jl state:Itle:~ts in C++ ~. \~ry DlJucll. ~~mi]ar. U1' that cr.f'C iIliftd ·thcrnfu.ro they arI'!2 im~;tiI,(lm.G'llJOOd . as .ad. w]wn .t.h~. ijin!l l"ef!uired!.

i '

" iB,UM.:MARY

"'~--~--~'~-~-~~~--~~~_-~~~'·~l

~ C++ ~d!2.!!l vmAll'llS: ~~i:.':J!l af toke:tlS tha.t :md'!llW?i: klQYW'i!)1'lU, :idcrtl'tifi!lll's,., OOn.gtBflltls,

strinp, and Il)per-a;ooHi •

. t:> Idoti!iEien mi'elr' '00' the· Iil:lmilS of v.3ina'b'l:es, :fu:m;]ti(!i[[)S:~ B1ttay,s~. ,dasses~1 etc •

. ¢:) C++ ]i!l'urviriies ~ :additio:nalJ '1[l$!9 of 'V:~~d, fur. dat!:'L~!t1lthm IOf ~_~c plIriln~!llrs<, .

. ($ 'II!!!: Ir:~·~ml!:r.il'~~d. !lata toy.pes dff[w ~1JG'l'~ly' l~ C++, 1he '~~' n~m~~ i))ft1lb~1 eL'iltlm,e,:l",8!~rl dJ;9.t~ '~W~ ~ ~ 'ly,e :n~- !hat.~; Wf;!o e~. dle(il~ ~.ew ",~bl~s 'UliiID_g rtb;e;.8e tag itJIa'm:~s_

.$} 1r.tJ C++-;, the ~iie· @'·ehQ.T,a:~ter ra:~a-Y',~htould be ~I ]:a,:r.fiEfI'·'~ '~e·.~~lbe'r'I~f'eh~~;cte'nl in t-h.e Ist_riq.

-$} C+-+- adds, 'i:iliu~ tOOI'il;cept of tOO:Mtao!t )luJill'ter ,Sind ])®m:ter 'WI oallfitEM.nt '~n ease of oo:mcstanlt pointier we ca:n :not. ilJjuJdr'ify '~e ,adJuesa, tha,t 'tilite' .ptdn~et' :is b:rltj:ali~ed Wi' ~':n taEi-411' .~ po.in1tt:g, ~o a constant" ·oo[}'Wnl;s ·@:f·wut n :po&llfitlB til) ~nt'hG; .~b.Q;ge-d.

¢::;. PJi}:.lll]oorn aR' 'Wiidcly used MIl, C++-"for .m.e010IrY llIl~imJ:9t.;;mil to iIl,diie.'I;C: ll'o1ymm']Jmsm,

~ Co++ p:rOi'i:~SS' ill quL~lffiQr' cnl!lGd . .comse t.(l!' ,declilll\Gi ~m.ciii OOI1lS1:mJlJtS w'hlm Dl'l~ jus1i like varia;b~es emept il::bat t!b.eiir v.a[ues i1l-i!m. n.oit IDe ~ged! . .A. ennst .. m.odifiu' defa1iiU~s to an :i_D,t.

¢> 'C++:is V'eIj!" strict. I\~aroimg' ~y'pe chcclWrJg of y,aria'bie.s. U, does, DOt, dow 00 eq;u.are

..... ...; .. iI,.~""''' """"""""'""" ... ;n:d.._'"'t l..i,-+,-. '~;'UJ'bP"" qii,."" .... _·Iw 'I:""!'ItU il'.n ~.....,-~, ~iL~';:, .... c·1 ... ,,;:, ·tM""'""" ... .:. ... ~q ~,I::!I_;JJ .. u.~1:~ lUll ,,-¥"tv. UJI..I.Il,t:;~ ':;_li0.ii. ~~ 1,1-.2 ~"""''''Il ,l,JlI!!I:r u..nllJl.., '"r~' I~U WI"-! II:I~ !.liUll._i:!I !D'"W~ ~ IIJI~,~ ~_"'1Ii :11

~ iC++ 0.1]OW,8 'I!IS to (leflJl.01t"@' ill Vui1ii;M@l mIYW'h@lrlilli :in tJ:b~, WkIrO,~! as Illso :ih wti£tUzation ;E)ll; 1l'II;W, Hm,(l·~, lIl$iing t'hi2= mI::p:res$.iQ!tlIs at. the F~a.oo: of'·d.~rn:M,O]Jl"

e A. reLielf.ef!1Qe varia'b~e :~ides :(Ul alb;!'l1lati,'le' ~:aae ,f~u" Q :p~vi@U!sJ)y dlnfinm3J '!oI'ltTiab1e.

Bo.-lh. 'the 'i,1'$;ri9!b1ea lie-reX bll the ,~ame ,utal. object .m 't-l\e, ~Y'" "ence~, >ch~ .in tll,e v'~['ue ~r Qft~ w.i.n iLso b@ :l'a~l~~ad .hI ~he ,¥,.a;l~ af ~hQ ill~:r. '!,\!'~ri~l(l~

~ A, Mr~m!tl.@'e· vHi~'b~~ mllst ~e imt.i9.n~. ,at n,,-~ ~iJ!tl-~ (iI.f d~at~, which {i$itaiUi.sh~, the eerrespcadeuee betweeD ·the·lIe:rerenre aadthe ,mBltBl, object. that it. names.

Copy rig hted m ateri al

~ It. !m;!:l!jg;f' 3!p:p~ii>t.!:Jti~. of the !300pC reselutien (::} O[p!l"l'.il:l:io:r Is ill 'U1L" C'l:ll,s!:iA..~ 'ttl lik'J,:i!lI.'~l:fjt (tilE' class t~ 1iN)jcl1 it :r'IiIem;ber funetlon 'be[Q'~~.

e ~.~, .f,i;ddilijQU '~O mal!lloeo,J ,~a;ti~ooO .aDd 'free( , fUi]i~ti'ons, C+-"", alse prevides tW~1 ~~fY ~nt.o.~; n~w QQd ;d~~e:l!e to ,enmm 'the 't~5k of allocating and :fr.eeing the, ITUmlDFY ilr.iJ ,Q, bett~r :Q!J1d, II;.'OOiili!t \"1~.y.,

~ Ct-t. alse [p:rovid.es mampuil.atom 00 :Wl"iIIIlfit the uta ,display. LTIW ,mOrS'~ oorttimuilly used iIW!_t!jplIiIl:)wT:B are emdll and. setvv.

'¢;> C",* S;IJ;Qip@rtB ~e\llen '~ype9. of {!·~ressim1s, \\fh·en rliJita types aJ!'C mixed .iJ:li an, !iI.'ifp~~~(lg.

C++ .r.;lIr, .... ,~~~'t!!fi ,the w.n '!;\'~ (;:siUtli :j:~;~W;IIru~i~i'CaJlv tlIsm g eertala rki.l!!1'3,

'¢> ~+ ~o ,~rm]t.$ el'::p~i('H:"t~ !Ci[\![!:v'~1ln ofV'ariaLhl~ and expl"eS5~,{!ns, IIlsmg th~}t~ ~~ it!i.petDOO~,

¢;) Lilloe C, (:++ 8ho sup'-po:~. the tJa:ree 'basic oontnl .st.rnot~ :nruneJ)y', s:e~.'lile:I1Oi;!', £iQlee~(I[jj and Loop" and impl:!:r.m.ellts U1Jem. W!i!l'lC: "i.fa~ii':liil!!l oOOntnlll ii;ti.:!:b::Jille-tiiLs 51l1tili. as, ifi :ifii.eJ.iae, swiikn, dO .. ''W,lbiiil,ec,. 'lWh~lCl ,and :~t"-

Key Terms

'); :Q",~-Y

:. n.:ss.ocia:lti,tity

::. iP:~t~:m:mt1~' OOCIiLV,efliliOIl! ,. baekslash d1;;JJ["aeiGl!" ). bitw,i:liie e~pu~~o.l":L

:. boo~.

» 'ooo'L~1Il. eK.:pIr'essi,CI,m. :. bii'u.nl:L'iiii.i:~g

)- call b~ l"ef~ii:'@J'l!~~ ). e,aDoeO

>- ebarseter constant ). db;a1tlsd ,a.ss~Ent );. !olam!.

); oom.f.j(i!j~Qul a;sSligJil:melJ! t ') oomJI(i!J!lruj, erx,p:re$~I)li!; )i; co t.

:. C(l(TI;Smoit:

» oo:.nstMLt .eltJiNlSBiaJm.

). QQ]]:~rni 5tr'lI.lct'lll"e' > rlla.ta typos

,. dletimu] ~]]te.ge]" >- rl~!J~al".D!tio!ll.

,. dle:fete.

,» d e l"e:ten::'ll.C',i]JJ~· ). del'"lVedl-'type ». 'a .... wh~l~

);. embedded. aBsignment ).. ebdIJ

>' ,gntry ootl,trol, ); eiri wner..a:tiw ); ,exit ~ontl'"Ol

); exp]~ei,t ~var.siml )-

~.PJIe;SEI~o[Jj.

,. :Illiililld expm~~Dl!ll

'); JJ!oatB'I;1i!ll' 'f'iOii1.it fnte ~T:

-"II:!! ,F - -- - ~-- - Gl ;s

..

·01~.!~

. "

Copy rig hted m ateri a

=======----- •• _" 11

» Jjo'I"m::JJittillllg )- :lift e :slt6re ) &~~[)

)0. ffllllttcti O:J]

_), bmu~iI~cimaJ. :in~~I" )- identiflee

.» if'

)i!. i.f:, •• e~se

); il[l!pli;~it c(K~lVW'iSWc_1\ ,.. ini.tiaUza.ti.Qn

)!., 'i:fli.'l~ga r !l':{j(nstm~it

)0. iJl!'~~.br:ral e.'!::PiH!iSBlon )t, i !lI:~~~'1 widt,;Uli~ .); i:~eIl.'D:~1~1lL

> k~ywon:ll

> U~a[

.' ] '~'I •

u gJI!l,;""";t;U. f::X[pIJ.'l@S$.1fMlI.

,. 'loop

)0, loop stru'i::t'l:lnl: )., 'mollil~U

)0 illl~U'ii~U!I.fJJtw )0 memozy

); nm]u!ld ~t~t )0 new

,. oct;d hiLte,b~t )- oper,a.to:r

). ope:r,0<itm' 'k~o:rdJs

)0 0p~':rijJ'ml" '!l)vQrbdi!tlg

)- _.l_

OpeF.aJt;gi]" iPl"OO~[)~'

:" 'Pnm~u'

). po:i[iJt.~ laxp:r.agjs&!il~

,). pointer 1I,t,anaJliJile

.. :r.m:e·:renoe

)!- refeJIeJl!tle varia;Me

.' rnbli1i.onm e:~sj).otlJ. » [''ClPetitlO"itIi.

)P' SC(lf8 li:'.@siI)iiuiUP ). s.e]etition.

» se[ootlon structl1Ire » &~lJJfl[JJ~C'

» tru.ct

sel!IDu,~~ s ~ U!fl~

)0. sem

)0, s!lliJlI~-:h 1ll11ld. as $l1~un!IJ:mJ.'l :>. s,;i21eofO

)0. stli:'aigl'b.t HtlG );. s~['li.tl.g

)0. s;tring eenstant ). S~n.Il~

)0. stn.ct'l;U'{::

)0 ,stru~tlt[\ed. ~1'a:~1U~mc: )0 ,swireh

), :sym'boHc ccnstrmt ,. ooken.

,. 'twe 'C35'ting

). t~~B oom.:p\i;rl1mli'~y ~ ~!Cd!ef'

). UiDJi~n

)0 us e:l" ... fkl.fiu ed t:;rpfll )- v,mab~j]

)0 Wloild

» w~t,cr-rnn model » w~;_t

). w:bW)~

'» widJe .. ribar,ade.l"

,3. U ,En,u.l':OOfiale tlw rw£s ofna.mi.ng ooriables iill: C++ .. How tUJl tk~ It:i,'iffer-lrom ANSI' C

r,rdC's~ .

Copy rig hted m ateri al

ll.2 M W'U!WIWd ,1'iPjJ~ ,~ili ~, ,tw~ ~ la;~e ,~ i'lM: ,signed' i'n~'" Expl'a~n ItoW'~ 3.3 Why d~8 C++ katte' ,~yPt madi{ie.r-8 r

3_4 What are ti~ (J;'ppliCtldwns {)f· ... ·o;id!' data type ~n (~*+?

3.5 Can ,we ,rM!st_en a; traM pmmer' ,t;o oa11< "n" ,type' poi;nf.er? If ~ot,; ,!.41h:y? How cg:~ we achietle' ,fh.is r

~J(; ,De~.ribe'. :wit' ,e.1t:l1:mpie&"\!- ,~ ,us..e.s o.f i!:]'1,WJ.oornlion d~tB t_yp.es'.

,3.1 ,D0scr.ibe' t.hf! (;Uffer-eoo~fj' in, th im:pltmen~1rlio\ii Q{ en;u~ darn type t~ ANSI C' ,~i:id 0,,,,+.

,3_8 W~ is: ,~.n 1fI:~,y !Jt.dooel a ,die\f"~!)ad data ,~y.pef

,3.9 T:kEr s.i;u' of a char army tkat' is, ihreiarod.. to stLJiiliC' a B'.tl',iJW' ,s-koul'dl' b.c (i!n~ larger t'nll];n t~, n~mb€r of ckjl~~F8 i~ ,fh.€ B~ring. WkJ'?'

,~.1{~' Thft e<!I'J'ni" W~ ,~~ken (F"Q.7H c++ and i'l'i!!co.tp'Gr~' iit ANSI C .. ,a;ld~'tJiIch quiiite di!fe'l'i@/llJdy. Expla,in.

,3.1,] .How d{)e-s a (}ons~'a~~' ,tf.e:fi~~d by ,carIBt ii'i/fer from the ,t;lonsrant ,df,fin,~d by tke: "w . , 'F'- . - - t' 8i~-'<1l!ii' iliJe,~-""?'

IFqJ' ~!'.!:o - ... -"_ .. .. \f~~

8.12 ,t:r!, ,e",""+. a ~l'i~b&i:1' ,1l~n &:1'.thtla:red lltli}'M)/wrrg' ~.~ UU? ~a'. Wkat is too sWn.lflOO1.t~

qf tAi8 ~~"re?'

3-13 lVJu:tt d'o YDU ~an b:Ji! dyn;~mic' .imti~lizati~n at (pi varike,fiIte ~ (j,ir.."'t a~ examp~. 3.14 What' i6 a r.eNTt~ lvar':~bte ~ lVh~'~ i! i~~' ,rn"(tjDir ~e'~

3.15 LL'!f at lea.~t fr;w n.ew O~~'f(tj"~ i!td'ckd b,. C++ which aid' nop_ 3.16 What is th€ appli.C'f!l.~ion ot. ~!I!' ~'I!llldu~w.n Qpem~qJ" .: in C++ ~

3.11 WJ~at are the aditJg;ijta,goo ,,,f u~~'nc ~~ (I:p.~ri)t'{),y' Q;!;' !Nlm~t>d' ~o ~'/1~ f"U1<tJiio'ft nMJkJe()?

3.18 lU~~'ra~e wiJk ,an. examp:tc,ll MMI! tile 8~fw mangndamr works'" 3-19 How dn ,the (olJ,'owhw: .stliitemfl'lIt,s: di:/firl'f

bd char 'iIIr 00118"1 p~'

(b} r;:h~.,. 'Ci!ilQ~: *':1';

3.1 'What will happen wnen you execute tbe foilowin:g coo.e'?' 'i~c]ude ~io~tream.h~

~ol d 'ma.iIl!lO

I

Copy rig hted m ateri al

~ n't 1 =0,;

j "'400'!l!",4{lO/401l i, ceut ~ 1'i,

}

,3.2 Id9'~tlY 'the error ,in the f~)UO'wi'fjg' :pmgr,f!!,m;

,1 ii'i:C lude' <~ o~nt ream,. It> i10~(1 m~1 nO

Ilflum [1],"'· [l.'] num ?

}

3J3 lbtib Um ~~ ,m the ,!loELowi~g ,~,~" ,"111 e'l IlIicl;e' <" i;);$t'f"@illm,.nil!"

yo~d mDJ'1 f!Il[)

{

'i nit i .. 5; '!'!!Mlle(O {

's.hI!Hf:~('1) t

defii!Jlill t ~:

lCiBls'8' .ill ~ case ~5:

cas,e' l~ (:!iJllI'Ilt11i1l!,1iei

case 2:, cue 3.: b're-iik~

~

1-;

,I

3:.4, :mde:lWti£y' the iQ~!'Qr i~ the rull~wj~1 P:T'ogr,Qm;, 'ii ncl IUd@ <1 @s:t r@a~" h~

'defi fie pi 3, .14

1 Wilt SCI]U'!lil'eA.rea (1 nt !J) ,i lllilt e'i rc eAred (i nt iIi) ';

Y(ri di rna] n 0 ~

tnt ~,::l[h

C@l!Iit <0;\0; :S'i;lilJliI!lI'\eA:reiJ {a} ,~ !i I! i

----- ....... 73

Copy rig hted m ateri al

Clout <,< c i 'rcl eAiflE!1I hi) e N • ,j

cout ..oo!i a oC\< 'i2'mf1~,

}

11 lit. :s,q UarMrea, (i nt ~i3.J {

}

'; IilIt c i 'Ird >EA.r~ilI ( i: IlIit ~d

{

~,

:3;.15, Identify 't.b~, '1!UJ)0'i: in 'the :rQ]lollN~n:g p:rQgr~~. if~ lfie 1 wde <1 o/s.'t~ea;m. h>

"i Iflt'~ !Joe 'qma'l] 'Qt JV,·

W!J'i'di rna i ~ 0 I

C hiIJ'r:t' ~tlf'~,

str ," ,[11 " !J,tat~m!Jr''' () ~ cout ,~ s 1!; If";~

ode le-'ite 'str:

5iti • II

ICll)llIit ,« st 1";

M.

~,

}

ena,1"""'" aJ 11 oca:il:eMefOO'r,f ()

{

:s.ttt ': !lIM~'i"'Y ~J 11I/liC!!!'t1:oj'j titS,t.o II ~ 'retUf'1iI1 it t r~

~,

3J6, ,!rind er:rnm~ if tlRj!'~. in tb_e :following' C++ SitQJe~Emts", h0 lM1{g flo~Jt x~

(b) ~ :"'cp' .. 'Vp; II ~ is, 8l void po4[]rt.e~

(Ill:} lilllit ll1od€: ;;;; tt:lu'l~j, 11 ,~, is iHLn I8IUl!tm~ra'~~r'

(d) mt iP, ;;;; new; 11 aJfkieElfOO' me.l"iI100"Y w~Ul, necw

(.:;:,. .. ... ,!IlI""fo f: ~"''''' 'I.;' ... 'n'I""W· ;r'"\Ci~ ~;,

.!!!ill. !!iiL!!~._~!! ~~~~~~II ~1§'~.:..Itv _'_ II "'~UJ'II

(fIt int Cl)"~~ .'p == 't.(!ital; ,eg, OOlEllst ilLlJt iIilT,!l,Y _s:im~

ell} riM ~i:;;:;ll.; illllJt i<mOi;. it+-} 001!lt '« ] « .... ;\ Ill.!!!;

Copy rig hted m ateri al

(i} tll1'~ ,& n.liI~~r;U:' ~ 1,00:'; lijJ ~].u~~ ,fj:p E! !n~W ~ilJit tllOI]I: (k} h'J.'~. ,ubUc IC: lO®O;

(u 'hu 'n:!i:.m.e~~:l == ""U.'~~,ii!i; ~. . .. --- - ~.-:I ~ •

8.1 '~\!'rite Ii)!: fi~r~~l'i~~'lf. ~'ljins nfer-euf;.'f; ua.ri'ables Q8 gr,.r.!l~~t.s to 8W~' the it.t"dtp~~, atfJ, pair ,of illtll#rn_

3.:2: "1tji;,i~'C ~ r~',~l_(;'~iilu~ tl~~'~ ;t'f ~~'~~.ti! {.!! ~{I(;~'t,;Ii!" Q;f ~~'tI':·l}ir!eJ~, ~i~ M 'U~i. Be~ ()pe'r'fl.Wr. 3.~, WrU6 a. J.l~ ['0' ,prW ~'k6 ftJil(jtcii~g ;Q;~~ui: ~a~~ Ibr l~~.

J

12' ss: 4444 S'S55r§'

3 .. 4 Write ill ,rngrnm, tlii €!Jal;uate' ~he' foll~wint· inoo:s~mgnt. ,eq~m.i!1 V!!!!, Pl.!. .. rl,lI

allt,d prin~ ,~m' ttdk,s oo.hrch W'Qukl girm tIr.€ ~ue rJf'V {oJ" Efari~us' (i&mbiirttatro.~ of

~b - t..u ... -·' '''-",,tIl - -l- ''''' - .... f'r' i[); ,- ,- ..J' C' ,- ,

,,"'_.e: s ... ~ ~;ijW~.\..;., iI,;Ig,~ .. 8 ",,' ~:. ,F ;!;I:i!'j:y: ,!l].~'

P: 1,000", ,200D~ 3000, "' .. ~ 10/)(J-(; 1'~ 0, 10~ (),,1.1:', O"JJ, '" .• , 0 . .20

,i\i; 1. ,2, 3,. n e, ••• ,', 10

(Hm~; p ,i~ the ,princi;Pi1l am@~~~' ~rtd V ~ ~&e' ~~~,u:e of moltty (:!li' ~i~ end {jf~ ,e~~. 'Tki~' 'eq',u'atirm: (Ian. be ,Mt~'Ur-s;;v!!!'iy wl'Uf;en as'

'v!!!! ,P(r -+ ,~)

P-V'

In Y~'heF-' wonliil', ~'e' ~lue {Jfm~il;~' ~~' ,~k-e' t~' of,ffle fi'Nft-,y,ef1:F-' ~m~ tJ.ie 'Tinr;~~l am!li!I'ln~' fo!' the iI'liI!'Jet, yeail"~ ~nd';w !!\in:.

,l5 An eltoc'~ti:v,r;~ is oontes~ed' by ftv,e' ,ca~1id'id.ate-8. the' can'd~da!es ,aJ'e ~umh.r~d 1 'w 5 ~nd' • ~Dting ~ d~;IDE!' ,by marki.~ tlw ~~did1'a;~ 7U'lm~1l" an, ~,he' ,~t!ll!iJt ,p~'r'.

tv .~,; .. 'l' "'- -. - ""'~ c,dl' ~l,.~ l. -lr:J.' ",.Jr, UJijif ~.a"r., ,;1\... , ~ ,~--" :~ , , ,tiJ'il ,t,

"",F~!!'!O' ~ p~ '1iV ~!i!!' ,~r~' ~I~~t_~(i'.w. g:1!l!~' ,C'(1(_ ... AJI!;;i ~I"!;~ ~.' t!r'r' ;jiH~~l;~ ~;r;!! ~_!;L~U!'

1U1I;~'ittg tl-l:!! tlrrti,y iJ~Me (\t:nlJl,~~ JIt1: M~S'; a ,nu:mb"er' ~~' ts' ~l.oiits;~~e' th£ m~ 1 ~'Oj ~ iI:..~ it_.l'hn: ·.i.,·ul.dl L~, " • _J _.J,. ' i -- '''!'t h -l'-,,;!J" - - . .d! '~k -__. - - -- -: 1:.=- :'..J -, i'.- - ~ ~~' ~~~_~: _ ...,rw .. :,~ i!Je W~B,~iUie"m: a~' ~ ~",!!:_'_(i!!~ W ..... ,~.r;ry;\ iii. ,t p:~ 6~WU~ iCfilc'tlil)!

,pl!lI[;I:nt tM ,1'iI:~mbel' f)f ~pi)iU b(ll11I!i!t-s.

,~Ul it, c~i ~!H.,m /Ms':(M ib.UiJ.W'~ng ~oo ,f)f~' ,(iguns fo'" a, ~~s ~rt~s~' mak-iws,:

'P~~t .'. '{t~., •• :o:';' ~ •. ~,,,;.r,..,L:-.;. "_ '~~~'- .',-

~I ~

,~ihiD 8430 280 18

SaU.M,v 430'0 lSO 9

:~1iIl :33~O 105 '1ll

Copy rig hted m ateri al

WritB, ,1ft ]Ill'iQg1lUm W Mad ~b' f'W,tliJ'€S sd OM~ ~'lol: ~''hR.' ,ft..DOue ffJrn~, to' otU'culat'B' ~'k£' batting aw~ ,t]:J~' to llrin.t o.ut til!e' wmpletyj' ta:&le includ'iJI,g' ,th~ ill if.! eroggs ,

,it'1 Wnt.B' pf'Cgrnms to ,~ntdM:al~ the fGU,owing fu,n,r.Uons !':.o O.ODOJ~ U'C'U;ll"I:WjI.,

a .1Il, ~. j

I l' 5' ~- ~

'1;I;li.!' s·m,x;;;; x--+---+-_·_--

S:I' ST 1!

(})) 8,~~;;;; 1 ., (11.2)2 '* 0/3f' i' Ul4yll ,., .,,' ...

. ~ '!J .G

. l't ~ ~

(iC) ,cas x ;;;; 1. - - __ . + -. _. __ - + ". , ,.,

2'1' 4f sr

3.8 Wr.f!fe a progmm to pri~t a tf!Jbie of" ooliU~8' ,af the fundtan y = e~x

fof' x ~tJaryi~ from (] ~Q l'O.i~ fJ'feJ)'i1. qf 11.1" The ,table ~h~uW app.tWr' ,~u falJQW~-

1Al!iLE FOR Y':::; E:XP [-XI

o.J!'

atl

(J.B

9.0

, N'

1k,_ - ~,'"

W.liWTli!i' .::t: ;;;;; -:- ,~,Xl

N .'11.

j=

,9. itO An. e.le.ctricdy boam ckarges the {OllowilW raie« to domf!8'nc usens' ,w discf)~~ ,'ar,gte' Q@il'Uilumption at if!'n.e~,;:'

F01' the /l'FSt 1()() unw - 60P' per' unit

,Por ~t 200 units ~ flOP' per ur.u!t

,Beyoncil "'00 un~(;,S ~ OO\P' per' UJ1~i

AU ~ am ,[Jk~~ a mi'nim.um o{ Rs. 50'.00" If tit£- tf}.~al. a..moWtf, is ;t?J:on th~n /!lB, 3QO,()() the.~ an add#w~aI6urr:karge ,of 1,5% ie r.u:I.dOO.

Wnx:e ill ,pT"Olram. to nad ~he' I'lrnJitlil!!S 'rlf ,U&€flj: ,a.nd lMtmO.t:f1' rl[ ,units oom,wood' ,wid ,pr£~.t @Id' t'hfiJ' ,c'hfj~' ur#h n~~5,

Copy rig hted m ateri al

I

1£0," Concepts

,.. lletum 'tnes. 'in mamO ,. Function :pmOOl1J.11rn,g' ~ O~U 'by rn~~~m.Qs

,. Oan ~Y' v,8Ilue

);, :RetlU'U b·y rd"-e'l"etloo·

')0- ]'n'I.ii[Jjil;! f.lliliCil:.~~::ll'Ii('l;

). :[le.f8iuh, arguments

" Cl(1!lJie1!Q111't ,ElIl'g!Il.m!l!ll'Iit.s

'). i\lJUCUOfJ. ~}vt!rl(ii~dJlitg

• C',

We kqqw '~at fOOCtiOM, ()lQ m\ ~~t mle ill C ])~,~, ®iOl'e!l~'l Di,vltl. ,a_ Y.D'(l,g1£i!m, :m.to fllif.U;l,till)!jj[ij is one ilJf the ,m~!iI:J; p(lI."ineiphi'8, of till!JiI.dlll!wnt stll."llIli:!tu:r~dI. Jl!m~g. AnrnID_e:f a~v,lmtage ®:rUSlllg lmctiOM is. itbaJt jJt is. ,(XIISSible 00 rerliU!1l!l1! 1tlll_e' s-i~e ,~r a l1~,W~ ~y cani'.- and 'UIj;.~' d'i~ ;all; diff'~t iE:dace..9, in the rnJw,Qrn,m.

~. that W{j, Mi,w ~d! ,9, syn~ i!llm.iI.' to '!he' f~U~l'j~c'm, develo~~' C ,~~~,

'!oi'l)hl 'SihGW (] ;, ma,ililO

~:

'S;ho.wr ~ e ~,.1 ~I

Copy rig hted m ateri al

'Il ~ ~, ••

li,tVhBri thl';!i :I]';i.lltc~i.(m. iii; c~dl.c(IJ, ,I)LJnl:.:JttJ~ ,is ti'HH. 'It' I I:ul L n L ~ m Iiln;l ... 1,; I. ~ 'hll' II i I,n I] n1 fu nll.'1 iml body", Th@, @ther stammerd$ m t'he :&LilCUetE. ~y ~H th~n ex~t:uted mdJ oOO:lJibQlJ lI~ '~~ thil!l ,main 'f"!Ili,~, W~,(ln. thi!l closilDg 'bmoo i$ e]lOOwttBr,oo. C++ is.ll~ IB}l)_oopti.on. ~IDm.s eentlaue to :be the building' ibloclm of ~ PlT'QKJ.'Bl~. ,bi. metJ C++- has adldedl lIi!Utlll!Y' new fe~tti!_r;es, "to ~wrm to m_ab the:m :mal"e :r;eli9ID'le' and flexible'. Like C++ opera tots , a C+-+ fl!JiIlctiDn. em. ~e iilfveitoiMd~d W rn..~-e :i~ ~m ~ll1r-eI1l;t. '~~~'M d~~!I1i!.:~il!l!g' un it:he ~]).~lilll["'l1ih' ,a~~ d":til) it., M~~!jt of' th~~ mndJi6c .'!1~o:n a~ a~ !ilE:',d =l ~ n u.,t·ti li~ II U' ~'l'q I ~ I :'t ;~lw~ II. ... fIIf nh i~ '1'1 - S HeliL'ted faclU1fu:!{il.

In tbn'S ~pteir~, we !5._hailll, briefly drisew~ tile ViLriDUS new featuH!5., 'thart ,are' ,;)}d;dedJ ~o Ct+ ~cti(ln~ liaRd '~f' :imwplem_'3llitaitiOfi-

C d~9S Dot s~~fJ".D:Dy ~tllli1'D 1:yjl@l,:m tbJ2 mwilnO 'fUillCCQ(JJ wbiiClb is tb~ .swH:'ltiMiC poi,~,t tnT' tll~ BHBClIlJticn of ,a, prQgrBlm" ''inllB dG:6fl~t±D:HJ 'Of m.:abIO weuld [OOk likG ,tll.iS!~

rm~:lIIII()

{

'~i'it ~1~U;

~!'It 1I\I3j~ 'n [1' r1it ,i!fr-gli;:! clh.3!ii" ~ ~,~V 0 ) ~

The :imct~ t'ibat hare a retlJ1ttli, valine S:bO'uikl UB.e' tke 'retUl"li, state:me.IJit for termiInaiWn, ~be malliO fun~tion in C++ ie., t:lUetefu~e, demteiDJ 8J_.9 fn]lo,~®:

Sinee the return, t;.ype ,oflllw:utltlOirull ])1 mt by dle:mll.d't" 'tJ1e '~eywm'd iinJt in ili~ m.:ainO h~~ i:E f.l;pi:.1Diin~]_ :~oot C++ ~:(!IitIil]llilem 'wil] ~~~te' ~,,~tIItu,,'!Ill'" 'W~intt i:f t~ i!ji ~Q '!tetu;_r,n

Copy rig hted m ateri al

------------~~~~7!

and then p[loveeds "Ito oompil~ the Pcr"®,grnm. It 'I:s g@od programrmm;g praCltlre 00 H'CtUl1y :[-\eP.:Urn a, 'VtduiE! from :ma:ilDO.

,Fl:Jmcoon.prototypincf; Isene (jofth~ m~j{Er jjm~~Iru}]}Jts w:1diXI. W ,e++ nmetlOO1l..S. 'iJIbe Pl'oto1tyjpe d,~rib~ ~ fiI;m:etrion woorl'D.OO to 'ilia MMpi~~ bf. ,ghWrlg ,d.e:talils s1l.l~h u 'tlFoo: D1!l]UOOl" and type' of ;rn;rgu.mn:lls, and 'Ul.~ ~ ofutllll'IIl VaJiUl.GS, 'With :fitmctiOliL Pl"®ibJtypiQ~ a tem.plf[lt~, ]S ,alrways 'wed Wh£!JIl, declarilll~ and, defining a 'run,lllouo_n. Villlium, ,a 'itlmc1i~i_n is ~!I1ld ... thi]l oomJlilfrl" U8€:S, 'tJ!rn, t~mp]~ to ii}JIiSIllf.':il!l that pr>OEieiF. a!~JlL~, ~' ]liass!l!td~ and thEi: m'it.;nm, v,aJllJI_ill: ]S treated IIJoRi%My. ,Any"viamtio]11:m. :mgj.t~lhlng' Ui'@ ,~~"f.iitS:O:f tha :['l~!IIm ~ 'M]] be caqht b¥ 'lill.€:' roID!:P]~J" ,~t 'the; thnB of ~m.]l!i1i1!'tiO'M. ,i,tGeU;, Th~e !!!~hQcb, alEuj] ~_ntT.OJs ilia net ;Q;Xjs1, in 'l~:u::' OOl1l1ieJil.tLon..aiB, C funetions,

"rhe IllrgumenMist itO'IIl.t~iu 'Ul.e ·~}.'J)es ,and names of.:ugwneIlib that mllSlt 'Eiie pused til the Rm.ctiQJiJ..

N.olo' rthDJt Gacll ,~~tvl0!rlj[J]b1e :m!iUi~ be de~l~d i:tmde,p;!nd!ent]:y [ItS ide' Ute ,pa~[tilile~.

Th:mtt Is, ill !ootmlhmm::ll d!~1a'mttki1\ U~~

Copy rig hted m ateri al

Fn ,1iI1. t;uncMml, dilld~~oj;'i"'ii'ii '~'h.ri; ii'iIoiloft'ifiiS Ofo;li'j,'Iit~, 'i'!ir"ffii'iii'mo;i;'~"" ,;;,'t .. .d!-',~ ~ ,',', '\i'6~oi'Io,"'_I;£JoI!' ,o!Io;n...:Ji .'h,~~~'~~

, ,. ,,',., _ _"",' ~ ""'~,~, _~ "',_'10' ~'I1IoI!'!o!,""" 'I<'~ 1I,o,!!R! ~!e""'..!Ic!I.l!l!rnl"",, !B!!, .... yummy ,!<YO iIO!A'liJ ""'9 .... ;u!k!i ,~ _W:II;:;!!I!.I!~'''',

'~y ,are' optt(n];~]. Th_8:~ JjEl~ 'the futiliL

'fl iJ.ilt vo'~ Wile (i IIiIt!, f1 oa t , f'1l ea t) ~

Jlffi, aceeptab'le ~;~ tie pl,IDiil!c O'fdecli8Fat,iol'Ji. At thls ~e, 'the CfJrn]p,UclI" f1nl.'If' cilf:i[:,J,,!l' fnJ'" the t:'"]Jit of rnr:gwl16DJTIs wn,WiL 'ith'i2' fu[l]~i~n is: ealled,

m ,gfllli!ll"ru, wo ean li2:i!thru" ~n6~'IJ1de';j)l' ,sxd1i1de '~ varia'bie rtl~maS, in, th~ argtll!E1IU!inrt !1m!

."" ',' """T'"+-OI'T'bC' l!iJf!1"", '" ,.: 'b,lj, """,., ';;'h' " .....ii;, ~ ,.. iI-. .,.-It,. ,1:_, 'h-".,lI , , .: ·.ll 1"1,.._"""-, "

Oil. llifiOLV"'J, ...... s. ,W.fie 'Y"a'fl.:Bi ,lIie iDBiIlD.es m. LLe Pl"UIlIO'''V F ~'UlS!I.i .a_Ij;I~ as pW6ewu_e:f;S i8JDu, lIilJi!U"lC.W!n!,

if:fLa_'~!ee a::~' ~soo" they dO!J/t ha~ to 'i'iti~:tm the :1'!J1'm.OO iiJ@edJ Lfi t),e f~nrNi()~ rnU ,¢Ii" fa7lc1.'i¢ti ,rifl,p. lJj i ~'i(Jn ".

In llhe :im.ction. dcl].[)jit!iOP.i.~ l!Ii.:EI!Dlgs: ~ '!reqmm ~use: 'ltffi: ,~_@fI!tg must be ref:'9D.eed. ii:ooide ,the :fwlctm. EKRm:p]e:

}

TFru 'l,Tmiabl(J' 'bll~, w:nlt mld :hl ~re :lmown. as th~, ,actual ~ru':a!mflOOni 'w:w,cb. SPG~.iify' tho d.im.easlons, of IDlIIIIlJel. Tbci'r' types, (whlrib. haw 'bean. declulell ,ea::r]ied s]].{)iwd match with the! '. types, d,«Hared in the pro ootype " Re:me:ml"e;r ~ the eaIl:ing ,staJtem"ErriLtshou[d [Utt include 'type' ~ . :~-~s in the ~7U·ment 'Ii-s·l

lID. C++, this means thEft the :nm:!:ltiiO:IIi ,doo~ not [J;lIa5.S anJ,J'":pni.rammlrs;, :rn;t is :idhmtic:d, to the· ISm:tetD.elllt

Copy rig hted m ateri al

===--------11

ill, tr,Slditiortru C, (i, :i:lmictioltl CBJU ,asre8 ~9ts by' 'vale,. The Ci1~wdl' fUjWct.i~ri ~te6 a. !n~W set of vtl!rit~ih]e£i, Dtili! OO,pi~5 the valum of RJ'iUI[)JleD~ into the:m. file &_Ilj,JCt.i~n d-»es not, harve aJcCe9s: 00 the aetaal va1I.i.:8Jb]es, in, the ea]UlIlg pfiogra:nn ~d C81ll cnJl.y' w{R'k, an 'U1e ,~piEC: (lilt" Y;~l~$. '!hi~ meehru!rlsm Lei fJijje ff&e ~~g.]l d,005 n~t need 00 ,alter the va[u'M Qftbe Clri-1rinQ] variable!] in the ca]~ program. lutjo there ~ mise lSituatio_ wbelie we 'would lIke w, cMnp' the Vahle.9 ,of' vanablec3 in, 'the, ooUing progrnm,. 'For e~.atm]Jle. in b~b!tdE' ~ 'We CGmpar-e two; a:dj8.relil!t elements m. the H~t mid. mteiitb~ 't.heU-"w&llaes 'if"the firat ,el€'m'e1l't 53 pe.arter tbffirl the seeond, U,a 'fimct:i.o1Jl iis, USEd! f:til" bubbl;c SOl',~~ 'then, :it sbouJd De :able w aill:ter 'tJm.e'v:ai1.!l!e8 of'v:aJriaWes in tftoo, w1.mg :ffiLmctWl1i.~ which is !not [possible' :0. 'th!l1i call~bY'.va1.ne! ,Inetl.od is, 'usel!t

Provhr,ioD crJthe whrence 'I'JQr~fl:bll!!iS' in C++ pernriit;S 'U'B, 'to':pa!35 [pii!tn~ii'liiete(!fS to the f1lltCtalfM hy li"€lfgr~nuf1l_ \VtU~:D V!/JQ W!ass ~~ts, 'b}f rnfI!UQnOi3. rt:hi:!l 'OOl"m:EI!l' i8!r:gum§]lL'~S m the coJ!l.OO, fjjfil:ltU"'fi 'L.:~","-"_",, ,'·.~i' ~ -,- "', """ ",'b, - • -;-I-, -~, ,~, '1 ~ ',~ ~ c.",,'- ,~ ,t.1r ~ ... ~ l'i<i; ... U' :F,-' .'Ii'I .... ,~ ...... , 'T'!b~"', :rnti ... • .. ·,,'" ,j;,'h ... '

~ ~ ~ 1!lI~_ ~""'-""''''~'''''"' ,""",~:BMit'!!'lI w !.'De a;1l,;1~u..aJ1L :a:l'gumelJ ~ 1n ,me "';:;Yl!cllllc~m!' ,1!iL__!!Yoo""""'~"'. ~ ~_"'~!!';oo '" _@,,..

Whe:D '~ ~n lS ~'Q:rlking '\l,I'Uh, lta Q:\Wl. argu~,e:ntc6" it is ~~]y '~Illl"kin:g Oil 'tJW; ori:ginaJ ,t\aJUiJ" C®mlldei' the 'fo]]owing funttiJlJiIi~

'w~'1 d s~~p (i Wit !i~,! 11 nt ilb) ,~

; nt t • 'iH a 'C b;,

b := ti

}

'!o!I1)1 d s·'WiJlJ)! 1 (i IIiIt 'It'!l,,, 'Ii!'it r!IIl:J) /~ F'11)I1i'iI!tt i~!'II l!!!e'1'1'!'11~ t ~ !l!inl I

(

t [iii riI;'liji~ ~'a iil ''''\b~ ''"'lb iii! 'it;

,~ ~~s1gn th~ ~~l~~ at addres5 ~ to t ~I r' put t h@ Vii 1 u@ i!j:t b " I!ritQ a. 'ill /

Ir.· put t ne Viii,] U~ ,Ei:~ t: ~ rrtQ b '~I

Copy rig hted m ateri al

SW,IP 1 (,l:(:i! ,ly); /'10' cal] by ~!l5s'i n,g ,Ii!

/* ad d rsss eli) ef va r1 aD] es I

T"hiis :!I]J.iliu'ljJ.:3i@h is: alse aBBepbhl~' in Cf.+,. Nom that. the eaJIl-by-mfurelJicf:: method, is neaterin its a:pPI"!lmcli"

1,4.,5, km1F:lD by Reference.

A 'fu[ru~tj!]lD ,ean also Rturm ,a, 'reile:r1fm(e" Consider- tbe {uilllowing l\mc:tion~ tnt ,I, mi;!':'; (f nt ~'X:I 'i' ftt ,~y)

'I

}

Sinoo 'tbs' ~tl!Lm tY]l£l"ofmPlXO is lei ,ii, t'he :fUC\l.6ll w~ums l'.e;(t!rence to x iOO'" Y (;QrLm not

~ ~ _"

t:h~: Vnllll~S), "beD a -rll!D0ti.on ca1] iSllelh as m.DlX(Olj< b) will yield iii :r.eh:RDIOO' to either ,Ill ;j}]" b

~!'md.ing on. '~:iirt vW,OOS" ThiS! m~s: thilJt this :fi1rl(l:tio~ crull enn. ,~,~p;i}M 011 '~.f:I' ~.e'.ft-~rl ,sid,c O'f. BID, iBlSgignm®'nt ;s,mJOOmmt., That 'is! th~ smt~ment

I·" ,.16 :rmume ~ocdons

One' 00: 'the' objectives of ~m.g fiwlctkms in a ]lIm,p-aJl1Iil is 'ito ,SRVe oome 'l1J]e:mOl'::!, iSi!.la.ce" 'whi.ch ibecom.es ,appt.«iab~e wlilen a fiilnc'tionls like.ly tlo ~e called B::!il)Y times. Huwe'\!',eT', every'tme tIj :~U~fi i~, ~~ned. ~t t~it,~, a ~~t ,O'i'el{.'tim time ~n ~ee~~llJg II, ~rieB ~f ~l'!Jfitm~t!g;g!S r'Q;f t~w suc'b as jiU~IDin, 'to the, f:ufim~o. :$8Jl'ing reIDs&efS4 :pUl~hl!Qg, ~:rgg~etlt!1i hlJ.'to 'the r:3,'~au!k I' ~lid :N!tUirniPi~ to ~he >C'aJJiing f~ti~U'jL '~'n :I!I! fUn(l"O@U, iE ,small; a iliilbJ;mnHal pel'canw,ge '0'" e~~~,tiWi bm,e rn~_y be Spefit. in :ei~th ®vei'hetu:1ls"

O:J!lC S.cd1l!tciJO:D to this, lPI1ilbL~ is to use maUCli ,~I]iti~, 'pil~Il~1l"ly' no"Wn aJS m;~il'fiSi_ fup[looe;ssoll' macres are [pioplWlU' in 'C. '][be maj,OF m-:awl"Bi!~ik 'Wi)tb maeroa is U1~Jt tbeY,He Dot reaU,Y :l!itn:Jm~ and therefore, 'the usual eilTO:r cl1~lIlg dees lWt ,oocO!r diurill!,g OOi1llpi~D!I:;i(!lr:Ji .

.04+ h.a..s~, dii~nt ~~Iuti~~ 00 'tcb~ p:rob'lernt, T~' eHlmiinate the coot gf~iI.liIs 'to s,'n::uill funetiens, C++ proi[ilu!ies, a new feRt~ (aUoo ~~ine f·~·mdi(m.. An imine ~mV:JiI, ]s It :Nnmon 'th;f!lt IS' e:~~uu1ed" i[j, ~ i[le' when it is in,~k.ed. Dat is" the OOL]fipi~e:r :repla~effi' the tugmOn caU wiU1, "tke

Copy rig hted m ateri al

OOf.'N$Jt!l1in!lH!.il1ig 'rulletioo ~~ {~~'IJetI'ili-lfIIg s1~dLfJ!r to ~__BCHS e~m;l__si@~), 'Tlt;e iulnu~' iIm,cij~ns ~ de:lined M rul~'S:

t n1 t l!\le J~'nct ~-~-hMder

~ -

:8xam.pi~~

.

~'11'l11 '1 Rilt d,{lub Is cub~ ,doLlib 1 i!' a.} ~

e ::l: clwbe(,l,O) ,j

!!II :; eu be ('.2 .!5+L!5} i

On, 'the' ,eKecwtirm oftthe-se St8!tem9'ts~ the v,alilles uI'i::: 31na dI vri1], 'be, :27 u.-d 164 res;eet.Weiy'.

If'tb.e a~ents are eKlpllessioJiJ..S sum as 2',5 *" :Il.:5~ the fim..ct,i{)]]J '~B~ 'tie v£illue ,of'the' (lR!pmssioll, 4: lIltl t:lns MS!2l. This m._IRS, th~ [.JiHltl,g f:'aa;tIlI'B rrur Sill.lJKlriM to macr6S.

l"L iiS easy' to ml!!i'~e a 'mDClti.®:l'II illllme'. Ml we need 'W do is 't;Q, ~, the '~g.lf'WO:[ld i.nJme bil, ~he funC.t:i0:D df!~tiOil. All :inJline :fimCtl!lIil:S must be ,(i~, lJefime 'Ute,. ,aH c.tta.

Wift. mfi:l!lld 1~~i$Gi m!'G bero-n' m.:i:1Jkmg D, functiml iimUn~. Tih_~ ~~, '~fits 0" billn_e, :iliIm.ction.8i dimirnish as the :im.ction !VOws:]D. si:u:~,.At SODre: pomit the ij}_'l{:eJr~d ofthe,:fi.metio:o, etill Eliooom~ small com;Pa:J'{ldi to the ;j}XOOll.ltW-n ef tn€:: :fum.ctiOO'l,~ aad thtli, ~b of'iiDlliite, lm.c1l00IlIlil mq Dif: 1 IlISt , In sueh rnBeB", 'tie use' oF: 11'!JI'lIIiaJi :ftrmctiOD 'wilJi ~e more meuirQgjWI. UiB'!.1:any~ -tbe runm.onlili are' mme in'line when, they' a:J:Ie B-]'[))iiliH.l elU-ough tn be defined in tIlJJle ilIl" mo lines, Elmmple:

Rem:embe-r '~hat 'the 'i.nbte' ~~ ffie('ely ~n& a ~,~~, ruJt ~ l~ruW'j to< th'e! oom~ilQ:J\ The eO'm:piier :m8J,Y ignolle t'll!rn :retJ,u:e.st if'the ii!mcti9\!:1, die1iio:i:tiDJII. its ,too long '01' too I!XImp~ioot:e..di and ~o:rnpi'J)e the ti.methnl as :a n6nJiLa[ fun~tiO:D.

]. f'"(!(I" :ill.mieotions ntrmnmg \!',a]lIles1, j]: a loop, ,3i. Bwii,tH~ 0(1" a row exis~. :2. :iFo\i' -if'UllIli.et:w.m :n.ot rettu~g Vill,iLl€tir. jif a return 5tate:m,eot if!_XiEitB.

a. :M 'fi.:mm{!m contain i.ti~ -vrnrialbles,

"" mr inUne K1JWlct~om are'teClrl:r-sive.

Copy rig hted m ateri al

~

bil!in!2 ;rrX'p'BnSlm1l. makes ,R ]J:ro~arm run futer' be&RBe tblil! overhead of a fYnl!.-tiOtli ~al] a.nd ' :I.'1MUTI1I. is climinstedl. How:ever t. it llll_:a.lres 'tae program 00 'take u~ more mem®zy bee.au~e , 'thr::, statlml,e'lJIts '~h.at dle:lID:e 'tiliae mUD:€! :fimoet.iOOl ,:iiH repr;CiduredJ ,a~ each paunt where; '~he

'.,nmemon i~, caJ.edl. SD. a tr,ad!~ beeemes necessary,

usin~ names pace st~;

inlin~ flo!t ~~l(flo~t ~~ flG~t y) l

in11n~ d~ub1e d1v(doubl~ p~ d~ubl~ q) {

ret u rn {p! q) ,

}

"i nt ma"inO [

flg~t ~ = 12.3~5; fl(J~t b = 9~62;

C~yt ~~ ~'(a.bl ~< ~\".: cout ~o(, £Iiv(iI.bl «« lI\n-:

}

PROGRAM 4. 1 I

121.,228 1 .. ~51113

c++ ,aJjl£IiWSi W to ~U a :fwJJ.eMml vritho1l1t s:p~cif,yill1g ~U its MgmReP.I.t&. In sueh e8~, 'tke i:mctkm, assign~, a default :ruli'lue 'to the, J!m',aHIl1Letler '~~b. dees not ha,VE!' :;I, '!OiIiH:t.¢.h±ng ,a~mr;mt

Copy rig hted m ateri al

fJ nt rtu 1 (i nt ti hlt j:=S i i nt k:c lOh tnt mulOn! lll.51, ii nt j) ';

f lilt n;.u1 (i 011 llll!ll" lIIrt j ~ i ntt k.!II UOh

. i'~t n:ul [jnt i""2., "ij~t j=5j ·i lit k=lCf):,

II ,!:e.!1O'J II tH@\gal II Ule,gal II !eg~!

,F.u~.;jOM :r1t C++ ,----------:--- .. -" 85

in Ole function ~U. Dei.rut 'vRl)ae~, ,a)iI."e spe©med wh_eIl the :ftmtMOE is dec~. n.e~ compi[er .i.tJ(bkB at t]n.e protO'~~ to, :ili_ :hn' m$!fi~ ~.en1:$ ra ~_~if1D, u~. iSLfiId alaM,g t'h'!;!i pf.\og'f,aM ibr pJabible' dt!i!jult VtlJue9. H~, ·is LFj, eKam:p],te or~ poowtype' (i,e, ~~ ,iecla'l'ati@.!:d with d~a,1(a]t valu~s:;

TIlls da:f:Qult viiJ,U{I::is ,s~tlGd! !in a :mQ]Ub£!!]" :8~«iml1\y simiiillarr W ill. v.ma!blo imnwation.

Tlite' above. pro~o:~e di~l:Elr'Q$ ~, dsf~u1t 'value of O'. i6 fa UU~ ~nt l"llIm,. A ,SUhs~!.lC!(lft :f:umcW:m, 'I!:lO:]l Hb

~aS$es tb~ v,~ue @f ijOOO '~@ prinC'ipa:Jl ,~, 1 t~ pQ:riod end 'tlK!n :1.G:tm tb~ ftm.n 'USQ d-Qlbuil:t v.ail~ a! (D_ t5 {'Or ram, ~.e; c:a.1Jl

A de:JinilJt ,atgwIlmt :00 checked! :&ir t,ype at ehe time of ,uclu8itiu ,e.ndJ eflrailgtedJ ,3It 'the 'time g,r call., One im~t po:mt '~O DOtE :is tut ,oBly the 'uariRqr ~eCim ~ ulVoe dafaU!l'~ ·valueB btl 'tJ'terelF"o:t.e we :mulii:t ,~dd, defal&lJt;B :It-<rilll ng'h1 t.'a' ,kfi,. 'We camm~ ,m-vide ,K dlef8i~Jt ",roue to It ~arttku1ar argumellit in the mitdie o.f'mu a::tg1LlJllli.ent 'Lia.'t .. ;Smme e'mmple~, olllUn!:tiO:fIJ d.eclaratiOOl 'wiith. ,de~,uJit values ,BlJre;

!intlude <in~tream>

us ng 'I"Iarnes.p2lce s.td;

(Can:~

Copy rig hted m ateri al .

i nt JJL;I i n 0 [

f1 oa t amo unt ;

float 'l'alL.L~(flo~t p, lnt n, ~lo)~t r=O.15): void piintline(cMai en=I .... ! int l~n=40) ~

II pro tatypf' II p rotQ tyP€

pri ntl i neO;

// uses def'au It va lues fur arguments.

amount = ~ilue{500Q.OO.5}~

II d~fmult for 3re a~gument

p rill. t h nd I I l •

II use! def.Jult \l'alue for" 2nd ClrgLiment

return (l~

li-------~ p-~-p_~-*I

fl edt \f.!lltle{float p, i nt n, flQ.;lt r l {

tnt year 1;

n oat :;,u.-n " p~

wlli 1 e (year ...:" I'd

{

sum = surn" (ltd;

j ca r )l'B1I1"+1 ~

l retl,Jrn('5um)~

~o1d p~l~tl\~e{e ~~ c~~ i~t l~ ) {

fot'(iM i=L: ic-=len; i++J p'l'lf.ltf('Ih;"~r.h}~ p r ; n tf ( II \ n II ) •

====================================

Copy rig hted m ateri al