Download as pdf
Download as pdf
You are on page 1of 53
Bolton © Monolithic Programming x Basic Astemmbiy dang uage Programming ALP) > Pata declared glebaty AS Statements are wnitlken in Sequences ‘ Disadvantage 2 No data protection + Readability is. poor xe Not auitable fo, large prazams. Paotedunal prognarming.* % FORTRAN = -y CoBOL > sub- prey aon wed 74 Ws one urd An cequente within subpropams Awadvantage: x No data protéction sh ees ¢ statement 10 hangfer control between dub- proprams. Not sale * ony suitable Jor medium sized propane Fowdeed prognamring + Pascan we p Use defined dala types were snbrocuced % Foch dubpyogiam has docat data vtage. Ne data yywteclion \ . ‘Object Onieuled foragrammeng Coop) cw Java oop ge more imponteurie to ats) tem toy fun choy, . tn Program divided into classes and their mens, on -fanctions . Data can be purivate, proce (on Poblkic, & enasy, ‘ e data yrroteckiovrs Objects can communicate with cach other Maing: furetion Medutant ged speogneroming objet 8 objed ¢ obj A” Dela riables Kota varuall, Membr Surdion es [rembe erat] Member Foner | eta SeeNEreneeT Tee] Palo aviables ow Nanially Dai varcall, 7 | ff San | | Key emcyy 4 Obed ~ Onieuted. regent | 4 object Primany runstome entity 4 : aD. rae lume entity im an oljeck ovieuted perm + Clays Grrcupuy of chyecls with similar propeilies , Cermmm behaviour and Shand Puelaions trips + Mevhed ° An operation required for an objet when coded th a 4s Ae claw i» caUed metho * Dala membew | Syntax for class declenabion : Cprivale» public. Prokelt clas A # Wemba Juncker : Priva. Aaka member t 5 data member 23 | —> data memtey | Aaka member Cri) 5 Palowe Bley methods h 3 > Methece @) metnad ocr AY method nO AY roemnbey « Sun cliev a; t Cat Bar types , Derived dake tyr Rasic dott tye sen gy = date S Pants Sucker class unton > EAUMEALi > De ieee | Saveger Float ‘etal _ Slot ant . Acute Rae dan tyr [rye - 5 bay * Chan chan - Vby te a) 2 eet chan 7 Ai bes chan . e an Rant - 2typpe 2 byes = unsqqned ime + save tat y show 4itt © wmignd shew tat 2 signed shew and wat - 4 bytes pg unsigned eng fl - Sig ved oa aud 3 Heat A byles 9 Berube x Double ~ @ byte * oa Aeubk - 10 byte Frum — abyles 2 Bel - tbyle whey coneeyds of objec ontented forograrnrning. 4. Poin Absbaction « Relens to Me proeedure’ of negrunating on object vatheul incuding batlegactind dates 2. Eniopoulation: The pa bang a, data ond Gundione as a Single wi ip Seren on crcapsuiatim 3. Swhevtante: Snhustane ya method by whide objet ay Close ges the properties a oljcds a oChin clas, A Bigmerphieen: The mecd allors e Some qundion '0 OU Ailtently wm dij Uasses. Botled Lure | Dulied tine Single Lune Asptay v0 | Aisplayty atsptay 3 | 5b Resucability : Object Orviewted programming ‘a\lovos reusability by extending & class tO aucthey clase uavag inhotitane, Example» if Class A class 8 | Advantages Of objec Oriented, programming: # Oat oneuted jugrams can be easily angreaie % Couey 4 Savhat hance allows ficient useage Ct code * Qala Absharion qmovides data sporotealion potion | : net Supported an carlin froperning on HOOP tedsnique alles rapa Aeetopmen ef new YS" jAue to the Comcpt ef ncusgability. Paogram objel- 4 [eo | ) aun pacese® [Funan 7 objet 2 yo abieet 3 [Data’) \ \ / joma) \ oo [uncon] Object iy Ure Mey | A object oriented peopennng Avy objet consists af its cum Anka and —fundions , hopes wm Cate Where axe totally 63 Kojpane in C44. Ot of uich Zeme ONL common to cand ¢tt. ome one Speafre to Ott. 1. Class 7. mew 2. Pubic 8 Operator a: priate a. virtual A paplatted to: dhis 5 Jriend : b intine wt 4) M's! variable | | Bdentifiass Use defined | Ml i Requord Menpfas are MME A} Vawabless “hotly, ovr Wdentefiens » ¥ daawyins shal stay wath a characlor aug Ve shea vet dlevh wit alg x Thee showta net cing spur t ace is nel allowed oo v ideniyfiew) # Herpes arowd viet be a Reguoanet e Latifins aw te a combmrativys Q) \epp ere and owe das clavacteay Renwore \ sale N Meme, toate typo ) . ae ' “Yohays ee asse rived Pointer Rate type aw? data type @ J tat vants wo, int epee Ryayts Mincude > mores adders uw namespace dlls CEN MEE Porte, Aatatype ue Me key int man () 4 ana mie Pao, Mwy int ADRS int # ps -— ‘i Pe@ry Using vauaby ¥ act 5 200, * Us aang Cour <4 Ving vasttable ¥ Nn"; a a. tonlenls cout 42" yalue d ye" apn ze ~\n"s & addeer Cour ze a ee" Adres a x "ce gee An", vasa vriaioleP s | Couk 22" using vantable P \n"; ‘ a | 2 padre ah 2772 Cot . " | ut 2 Vawe a x Zee pee SNny | ont ab cour 22° Addyex ob ee" aep: NetUIN Op 5 Taegey vaatiable p—> vari Memory addin Porter vanald< ay) 1060 ——— Pint 1000] aEos Bul Weve, 100le address, Since normal variable youp- address Ane poivter venisele Sundiows : A fundio 4 a bet ontaivrd rock by 0. dub- propa” thot poyorrs a Specta task- wid maine) Aura O 6 ae 6 Fnatico ee oe 4 cs > funeBO Sune BO, ‘ | aa . Aaa is a colldlion af similar date Vp The clmens 4 an aed ane stoned in Sepurale mem in Aocations + frample: int bE al; > Inder Cement | blo] bl bo] brad value £ a 5 7 4, | aes 00 Avo2 A004 4006} DS Fs used bo combine ome Lm) more Ayyoreat databep Mee P dis annay ii assed to otere ny imilay data bypes @xample: — dlnuct tem 4 int coclemo ; pleat poure; lant 4 45 45 uy. auest sonable Shuck ium a, eb Tile A, todeno <10 5 b> palges & 30; 2] Unio ~ Unien ‘us Similan to éyucture becawe it 6 used to grr Apostate tyne The dip perente betwan Sbucare and Union i that, Union allous Aariables to Share Bee as ae voluacas Aouctru dow Nol allow . fxounple? Siauct emp uvtiun emp 4 A co oe Mernoy allocated « fea te maxirnum 4136 4 Ue data tyle in onic 2- 4 byle d 3] Cnumerated data type Cenum) * nese types ane ued fo Senporove dhe neadabilly 4} Be eae ey eesgny ruaningtul words tratiad 9 tepbaes. Example: enum cceteny,, a Monday, Tuesday, Wednesday , Thursday, Friday, Saturday, Sunday Ys 4] Void data type: Wid data type is an emphy dataty pe Case 4: No whan fype void Message C) 4 Pring ("Hello ") 4 Cove 2 Ne panameley Int funca cwid? 4 nebo 4 3 Coxe 3: é No vate Janez Cvord) A pruniy (end propam') ; % A type modifier changes whe sneaning oe dota tire be prone a new data hype Kegon Such as signed ak , bnsiqned bare shot cre USA 0S type Modifiers. ae! fample: int az 2 bye long int as (a4 byl 2 z mq double @3 Clv byres 2 a Type costing “Type cashing is used shen wolves of practicueles ned to be wonveded prom one. date tbe to ansthen my example: To tonwes a Tntiger data type 4 float yr an ee Srmplicit tyre . casting Seplcett type casting (Done A compile? Done by propammey Smith type casteing » Sept’ type ' include Aincude wing namespace Ath 7 de conegeu ade ee int maint? wnt js 29 4 int as Als ; tour ZdAaArl S756) 5 chants 84-95 nckusun 0; toutes fo" eeg 3 % cour ze “Az" ee a3 Coukee “es "Zee 3 srckuan 0 Cowtown in CAT: Gat Supports dipyrent Types of consbants 4) litmal wnstants x des anes assigned 20 0 variable con be changed during program eecation . hr craynple, tat a= 5 3 2 Ae costal * Adepine Prample: define souls 152 Using const Jagurora Cramrpie: Const fink pole = 192 5 * Veing enum Jenyuoord enurn Apia 215295 Fyre bolic wrstauts Cannot be chenged duurceng pouyon veution . 3) tonstat pouba UE Oz10 5 Bi tee Hy int a= Ba; ink wot ka2 Ga; 4 Le] x [oo]! ron be changed during toratant and pmoqnanm eke asin favnot be chonged Auaing pop” Yorvltn +p a tomstant Cost int as io; int x= baS Covetant jpéuitea tp a constant cowsk snk azo 5 Mr Covet kas Bas Operators im Cte: Operators dapyponted a . 0B] 100 v ¥ | too Thus value connot be changed duating program retin pe igo x [5] | Boty ane tovutankh | Operates gupporled C and Ctt by ont Tyr_ob Guenter | opaatos | Apmbel Type, operates | symbot Arithmetic. a Snsation Relatimal = Kextradion Geope access or New Memory alleca dealloe | —* BARES Operator Detde Memory malloc yacore ", wy sor Operator evteading faa * Thu is O feattore supported in C44. SB cpmaten Cephenling epenaien oveilendding peryeun aypprent actions depending pon ster coven om uted unt bs Gerace a ciner'b cour <<" value o bist eaub 5 u Insertion Exbadion: Sthracting Bre value rom Pe: Onsetion: Sruerding me wolue orto the Alaplay _ Stope aceers. ¢ atinudeslostncam> Wang namepac td 5 W svape Ocees wperatr erample Conplicable only fo cm) intazto; I/ Cilobal variable wt main OD 4 AM Scope acces oyunotn “s Supported only Oy CVF int a: 20; If local aniable cick sae ee sake? SQ y 5 Ot cecess global gibi vasvoble yaotae toupee az"eeaee™\"; adusn 5 F toe varrath nee dent. c we Hincludeciosheam> using namespace stds Int mont 4 int bs bzto3 . mo tour ce" value of be” ee bee ee tout 2e* Value ct Bb tee Rhee “\P"s Madan fb cour ce" value of 4 CQ@b) = "22% (&b) using namespace stds Juris 0 program do Adda fundion poretoly pe 4 a fundion suc) UY Deira tne forcion gam and wre: the apprepoucte stalement ink main 0 £ float sum Cint, fleotds W Fancton prolotyre int: az20; float Gb= 25; Dab actual arguments se sum (a/b); [Calling 2 funtlion toutze” Bums 2455 deluan o 5 g A fandion Acginclion float sum (int as Jload ? { 7 xy formal a netuon (XY) 5 a Seri -¢pp Hinclude using namespace std 5 Void Jane AQniy, // pass value wid func Btint @); y pass by addres tink main 0) 5 Me Seay dune Ar); Cour Ze” pw oy fale \n, 2 Nate g S$: ee See * Addvess ys "22835 func Bs): tour ce" \n pass by reference \a "ze Naalue 5* ; Addhess 4 ilo 35 actwin 05 % BF Sword Sune a Cint x) a X+ts gy Void funcB Cint wk) 4 ek tr 5 Udine - punese Pinclude Ziosbeam> using namespace dtd Ménard of ceastion is thread Msige of prego is tama Inline float square Cf Loar) : return qe a 3 int mained A int ge 3.5) 6+ squarecg) eee cout ze" "22q ster yw pepe sting namespace Shc 3 int equare Cint): Sloat square Gflvat); int main a 0) Wt arib: \ 3 oy. yy en o\ floot b:2.55 of ee at) i , ae Couk 22" square a ag equarela) ce “\5"; | we tout ze" aquore 4 bi" 42 6quane Cb) < “\n 5] Yetuan 0) 3 tak Square CneD q rutuan (i * 1); 3 Sleat square C4teat G) 4 neuan qr) v4 Bar o) bt we Re x) ee Thee eperatns ow wed to access are value od oddres 4 vaniob tes, yur gp variable name value adhe? imi be (a a Ee | 4» Cou £e"Value y bs" 2eb ,——__| Cout 2¢" Yalueoy adds q b> "ze Bb; dour ce” Value y be" Lem eb) ; Seope acters operator [: } Jppicadcon: : ) Dijgeren Hate betwan local and gtotet ; 2) Used Be Class declrdli Umiol siakmat Decision making Sictcrmens Uneondi tional ze Control banger Feons v gum YT, statement Suriteh Croto lop Wie Do -oshil ‘ loo h Ly austen > break Pleo ae Cone 5 tontinue Nestea > | a i Nesled Soule, fo. Named dee Auviten case bey de ladder Spat fourpat Stcttements in Ctr: 1) Cin: The woe standard sinyust stclement for obtaiving sApur fern Keybodrd this’ "i Similar fo sean] C This statement uses exbarlion 07) operator to gt the. vols from she Keyboard . : Uh a standard -funchm 12 Adaplay ae WW) Cout u ne I : : von. “4 ub pw mm monitin: Jia similar bp prt} in 6 This Uses insecloon 677) Operclor bo Bina, 4 dhe values on ane oMonler , Nove Both cin and Couk are Acfoned in Tosheambh Junction. Protoly pe: void Main) 4 floar sume flocu ,imt)s // forrton rr Olelyppe) “float “ye DAS im zens p> Aetual ergquenents X= gum ay Be M fusdiow cate b 7 > Jorrnat eaqument Sloat um ¢ float { tnt ke) f Mind ae M forciin bo 5) Junction 3 12 aa A funcion jwotobype Leth the Compiler Une fotowrng datos» 4. Name ef tne function 2s xt bare Y Me function 3 Tyke and numbe a arguments to the function dhe onqueneisie iw athe Calling fundum av called | actual onguned ne angunents tv the called funcion ave called -formal ong to Fundion Auginidion : dunctim Acpiviciion ds wre Slode 4 okatements whith arcluds ine jection Audercition , Faseing orqumenta do fancies: ee ee prosed to functions sh too ways 4. Passed by value f exon 2. pass by naoene J fur? fundion opp tincude Zioghcam> & wid funca cin) $ ree void fune B tint @) iMmg-matn 6) 4 - wr 45 fusncats)3 / pas by value cau" pss ete Vlas dss" ebae" Address a #° “~ fancBOs 7 poss by” ene ney Cous ce pass of edencenes Bee "Value of s = eG ae “nates J vduane 5 se "428 S: 5 Vora funca Cit 2 3 05 Foal oper ct Atts § Void funeBCine & &) 4 KK g value addyeas s Gt tac fe 7 a ¥ [=] 200 Poss by value valur of S24, adldves ef s+ woo Poss by Aelusnec weg Si 5° Adches 4 $= 1008 when a forcion wy declevud inNine » the compl» tepiv Bre Wwe of the function in de calling furclion. The tode rite the orction, vw duierted in Me plot | junction tot Aue to Ahin, the combrol peeing belween calling function and calivd funelion, 6 avoided Sample : Inline void addnurn Cinta, iaby) & touree Wome g) sponanidon = "Jo x vey cour zz.” Sum of Pananicles” - ANY 4 void maine) A addnum (2, 3); adanum (3,47; addnum 4,5); 3 void maint? a cour ce "value of ponanilas “Ze 2208 : cout 2c‘ sum a prada > “ward, Cour 42" value a) pananiels = "22 32247 cout “sum a ponamilas 2" 22 oy Cousse® value of poromtls =" 2242s cour ee” Sar of pmdlin "oe 4 +8,: A Spend of exeattion 4s Sunvoued » because Corer sunichiong we auoided Broadvantage: Tre aye of ane pre we inowased because of Weedion code In Me main functiove Note : Sutin pundions ore best suilertble fy smal -funchinn Ove ing. | tancum eee ded Jn Crt, A ds fussible to Use De cone Fordion rome Wit, a dipyaent panameters Papen mulkinle funclions with 2 some snome We done as funda eisai) eae polymorpha Rules of Junction overonding : fg] Te Heo fpenctions hove Ae are and: uenin s onguenerls Bren the funcion cont be evedeadsd. Jomong wnoage Hearowck uscoge ~ 4 Moret vscorge -2 fune 4 (int, mt) Fusne 4 Lint; int) Punca cint , int) a 4 f 5 § June 4 Cink, it) funca int, float) 3 if & func a Cint , int int) f 4 4 + De Passing coelant Valu iwead +4 aoiables nok advisible ry} wrong ¥ . y | Mange Murr waay Sum 67/305 sae orn, 585A) 5 aural tb): 5, vohenun funclum everloadsing is med, Hee eomilen dru. do Ros an acustate maich yf the unde math Wo nad fort Men tee ecen pen tides Seni coneeviions and finds a match Qassts ANp oBsECIs Class - Specification - Member Junto - shatic dota membes- Instone Mec - “4 Of objects ~ Aynarnic objec - static objects. Covsuctors - sponamctiaised. Constructs Overloacka towiurctrrs - Unatructors vith default eogumeils. on COuPuLDs - Aynomic consbuctens - Stiparrie Initial gation vag towtew.iens - Destrurctors, Chass Spactyivation : Dre concept of Classes tn Cit cane wwsiduud w an extevisumn o, Sieachu in C- Shur dilvocion in ¢: Stuck iM int Sloat — chav A ‘ : Wt code no; ovary, | / pleat poiges [ r int 1% . cee . / | 4; Slauckine Dloadvantage 4 Structures 4, Aeuscwous allow goorey 4 Af fovent data Wye Bur functions Are Mot Allouccl inside shructiores D. Seourithy 4 data jy mb provided tr shruchure, ol data members linside sioudtiine pane : public. a eee ee Envapauladt ert, Acta hiding pchivnd using He Legos i goiwote 5 quustidied « Templo ay a daw: das name of. class Ah freee /paabtic | poctedlad + D duerctiom of data poniallcs pruvase/ puadite /pavolicted ¢ Uprotdtyye Auluvalion 4 funilion 5 Faamp\e + Class Hem 4 WU Dora members private: ink eodenos flow: pose; int aby 5 Public: wid display er; UMerbe Junchen 4s Type 4 wrembir Aubin in Ctt + ts Public : Natamimbes and memba jJundion, wn be otc, ge Ea On wel as tre obgect smembers | 2. Private: Data members aud member fondiions con be accessed be clans -members, but nok ey he objet Mernbes 3. Proletted * Protected members are similar to spovival but normally Used duning tnhoutane A corn in clan a mpl l pe" J dinclude 2ivsbcam> Using Namespace ste ; Chess item / & dass dedevectien Public: int codeno; float pu; iat aty> public : void display oO § course “Code nos “ze coceno'; cout ze" price = "se price 5 cour ze” 4ty aty J 4; int maine) rah unk ay Tebjen Arcleralion a -tode noz 203 aprile = 05; a a4 = 1005. a digphory 07 Jj HK Objed rsbeanee af a dass 3 ing clans, x several objet ton we) cuales froma cing) object Not accessible Accessible | Not aceewible faeces of tember dunclions The difference belween: wonraail jpncio ond Junction © thot , normal fundlons can be called anyichere in the pangpm, vohuwor member junds cone cailed [Only by tu objeds a the Clase Slack dleap | Meron emend _pfunaios in Ett. on os 4 namic alecalion i Hunporh dy neoee wales “yew and ” de ate” epenabos . : 2 the equivalent ¢ equa ipacenane Ore Maller « , and “ dealloc . . 6 dn ole: is mea aeywamically ssing rao oresaty i : , and dusdreyed mang Adele operctor. Memory map — . ») Ys Stack ? Vbed to shore Antal vaniables = Heap ?. Dynamte ‘eeneg allotakion Oata éeymert) 9 Wbed to ohne Gilobal & Static data aniables Jo : tohe tegerent| D Weed deove Papen dntruclions mero aM grey Bar Aaunuonds seer anne. My Yen -rpwanrcs Hindude ¢iogheam> Rinclude Zemnio> vaing narnespac Stet ; int 25 > Gikbat vamable stored im Code “qe wl math ¢) 4 im sples Ycode ex) ment a=5; data fgement Snheges $ ebyley Pls newint Cm] > M1 lap btmeqne ste by ke Veluwe 05 rode ZL 4 Lee! These 10 byter 9 a ai ve w tere vou dopey int 4) ‘ohacke) Vereen writ be FF 4 ?) toa ze“ value 2 "ee v | | | | | | 3 | | | Compilation jphae > Memo allecalton fey Lecal aud alelerl | Cxeusluon hoe Meine allecaen fa aynomie variable new’ @ delate ~ day prsgram wil Ie tn either op tue Heo phase ) Compilation phase 2) Preution phase loco and giobal weriobls axe allocated ( = compiosion phase Dynamic sarkable tovoled sting neve ein “dul quncins lone Stored in te neon Sener « - Mernovq odocation jor Ayrosnic wwoniables happens deur Creudion phase Foros ‘and global vantable rmalin in she memory sa wine pape teamivates wwhwuas vorpbles cuated Aygnamicall CON ee newnoved won wae apenpiicnn during spregron ekeustion On. iern 4 “Wt bodeno; peek poua; inn 4h 43 void maint) a a Warn Orbe tAgl] ob. tdore objet 3 Merny mop J Se oe obo TI, Oy beC avd A ore Aeeal ot) Hen, Be ene bs almcldA in Tre Statk . a. be . Stoke inti % 0 otic yeedabl which b sine a & Dio Segment .Aradie wordolsles any Ard only oe re honda | ou the oy Stodte Jundion Like Stotic wartoble, qunrlicns con algo e malt aces Bion. Whar a function in Aufined as Zeasic, A can my Staite Aonialte, of Ae class . The gtaitc member function Canmol access non- state voriakles. Enampe for shake memnbey fund : Hinclude viding namespace stds class add—data 6 : private z output Static inte; vou 4 cro Public: Value ofc = 2 State void Count l) 4 CH; 3 Sratic wotd display 0 h cous using namenace std; class mydlass 4 public = inta; int; int 5: Public Vout display () Course’ Value yas "eas a ye lpr valu, fe ey zt i b Pass declenation ends tor en Tevature oy eg) Voi man (> 6 myles A 3 Arinihaligo- A. display 0: Ourpat yalus of aso Value ayer value of 55° Wek a C4 program fowunr ao clas cold student. Declare Hoe pak dota woriables Indice the Class, The Gaia voniaites pave tp sine Aha regis enumber, eqpa and Semester datas. Crate tewe objects Si, 5 Ond Sz. Wre member funclions fo get Ame shident dete and Aicptay on whe Since induce <10sh using Namespace 45 sudan juvrale: /) dala meee int wq-nos ' Pleat capa Int gernestes Public JM thember Jundcer, void geldatan; 4 ster nurnlosy = tout 20 Xn Ener "rd cine " no, Con ze" \n éntey yee o Cin>> copes (ous 42° Nn Entty ow sernedtey delat”: Cin >> Someday ; 3 Voie. diene >) 4 Gout 22” Sn Registen numory = "ee reno; coud Le WCAPAS” ee COPA lout 2 “Nn Semeiey » "we Semutey 5 eB void Main t) 4 Student Si $2, 55 Si. geldatacy, $2. gelaaracy, SE getdatrac 3m. display; $2. displagey Dalagey, ye" Favic objea An objec lbecomes stabil, when a Shane hegquord oMed in js deletion Brake objects one iba yed emly one y anc nema in we = UAL He if. nam laminale, | drake objects One Stoned WH the Aaka deqmant of a Amedlude using namespace Sle: Uoss bik a 4 pautvade > Mb cy Int ky Public: vota ps vord Showet) 4a tourer ee cre \7 5 Cou ze k= "Ze Kk ze An" 4 Sie im main O Static biba; Ww tout 2" Shitiah ye "20 a. show!) » a. pun, tout 2° Ayer inounnent” 22 °\n"s a. Showt) Meluino j | 3 Output Tnitiauize cro tex Sn te above erampl, a clas caled “pita” % enated. Thi cou two yydwat data variabtu and dwo pubic Mmeimber functions wide re class. Sn me malin funtlien pr objet Sa? is uted This objet Wa obatic object, by duclaning ib 0» dint [The yotiow. data varvobles mannaly Entigerc ancl andzge K Tite ona mk kK] ay didecheal inchioniyed to gee Menu ne ovtpur ts cro and Keo 4 calling the plu Juseluon , the Valuer 4 Cond * Om moumented “ a. | ‘The dilfoena betwen a static object and % hon- Statte object \’ Anat, ‘nm Shatic objects the data ataltes aut x Les ane sc caiacaal ar| aintialiged 4 Fow, whoa in nen- Static objec initialization has to be peyorred by am ea teora Brae oy objec crcarted, sang wre epenakoy are called dynamic obec. Thee objects one deleted cea dade cpewin: Dynamic objeds are Stoved In Bre Aneap memony , uolurcas Static obyds ote sired In ihe data écqament naemony Ayrtax or Aywamie ojeds Clasname objeck name ; Objet names new choasname ; Barnple + bria x bs be naw bikas Arcos af, objeds: srow a elledien ey sienilan doike. types . Arvoys con be wed to sine, poly: datatype Sunn 04 inugey Jioaa, CManacty coke froys con also ke used to Store user dafdined dada ‘ype such as oljcds Create a Clas Coded qaye with @ folowing data memkes wnilz two member horace Chan name [20] } int ages. Sundions te ga tm dota ond display the data Sn the Main fundcion Guat nr arvidy of 20 players and Wee O for deep fo get the Ona eg onlay ae dame - LCOnis were ss. Cat yrevicles a spatr 4 barild - tn fuvidlions CoWecl fengnuctars and Aestuctas. Cortructeas are Used to initiabge tre data membeas q wn class. * Dehetre, ane Used to Aeallocate paca wpa Oe wyried a whe object - Coshucims and Debuctms av member Sunckens 5 a class, They have the Same name as that Othe class, Detructors ave preceded %y “A Ciled) ayrnbel . Both Consrucins and deshuckas ase functions thiak om tas fkecuted i ahe compilen | Weide a a gran to oars A coveburctor ancl initialize te dass Aala member vevriabtes, tHinclude wang naenespace tay class (Wurm) & Prrtiverte : mia; int b; int cy pablyo: /rovtrue num 0) \ void Shove 4 cout 22° \nas"eraus*br "2s bre 3 3, Mer Meres mt mate? num x | X. oho mebuen 5 4 CNP aso bi er 2 ‘ 24 Sin sme aleve example, & wonder num” : > we close, Sn dhe main fundion , an objec * Adjined imide Cualed, Ausing vuodion of tre ebjed, Bre compiler ’ ee eK excoul, Mae cowstauctrr. Tyg ol connarts: CM Suppers dierent pes of construde 4. Overloaded Worekrucns 5. Dynarniec conshructors 2. Panamadenged constructors 3. Combaucors wie dapouut fe aaa A. Copy tonstructers . gincdude Zrostecam > using namespace sinks clase plager @ public; Choa name [20] 2 int ages Public : wid gelelatat) - AR Couj ze” \n Entu eur name ein => name 5 Coutee™ No Enter ee age fs Cin sage 5 4 Noid display ¢> d q Buree* 9 Name : | ce nayne + 7 <20G¢ . coud ze Nn one 5 43 void vnatn 6 4 Int Fgrecoy int player [20] ; fon Cis os icvox ian) yf 2 o 4 Ws 4 cL eae 1% a Z 74 Player [i getdata 0] é 2 4 a é Le et -_ 5 iF plage: [i display]; a 2 3 ce ee? ¥ 4 8 § J Panameeuged tonaeuctors. S A consinuicin Ys a merrier fuundlin ahi nor One Same name as that af a class. Conseco axe automatically chewuted by Line tommpiler when an objet of te clam is Cuated- | Corts can nave ures nob one posed fo inibiaugationA Condeuctor with one io) move arguments Cold 0% spanameleouyd Concbruclns. by posiung poraméleow wwe tan Cuaie objets votn dierent tnitvaliyotion valses. Baromple * indude using namespac Stel f Oars nun R pala Me AreoF imt by =2) Pubbes void murnctnt js int h ae fo biz ks ho void matnry § num 002,39) ; num 64,5 dy 4 | Advantage | peramdyused condourdins is ty crtote objec with Autonet Initial values, : |? Owloaded conaburctors « Overloading rnvans hating dipterent uunations wid He bane narne. Ine purdion, have dippervnt number la poremain, $68 Hoss to, sveitead: éevidtanitts by. cnn ng fee ren of orauunund said. Depending Pon phe sumnorn of areca fe | Gonewprendiing lovitbuct, in ekeuted, by the cornpid. Cramp 2 Oss num A Private : Int aizoy mt bi=o; Public: vor numd eoratuete «4 vore num eink, int ¥) A pasanedoniys cera acter at rhe bieks x dy void. maint > 4 num a,b(3/4); 3 whin overloaded comiiucins one usd Bae compiler decides which Urrsiaucion dy de 2xeuted + Bepending upon dhe frumiben 9 vangepes posed. 3. Cour clon with Arfeau angurncits Enample: Clas num. 4 Private: ime alzo. int bieo > Public Vord num) R Aizo; bizo; 4 Void num (int |, mt k =e) h ap 4 bizky ys Void maint) h hum Ab C34), C65); 5 | Like qunciiom tds poze bo decane constouctors with dejoutt angen, The balue ° Me Ay cull argument v laseumed when the acual value “4 vol prassed - os. ne object ¢ 4 Cuatid 4d. oi, Ahm. jAswonam, | aeadie ea argument, integer] Fantajy totes ten |ralure a} Ale anqument and te value a) Wy taken las 0. Jude the output of te follow | Wouring m qm 4 rae Hinclude usdg namespace skh; ' Class num ¢) a petiak + int a; | int b; tate; tard 3 Public » void numiint a, mky, inky 20% ine voro) a az25 boys oz; d= w; 4 int sumo natan (aibterd); 4 3 43 Yota maint? 4 | Num aicto, 15); hum bi to, 1, 25)5 num ci Clos l772, 30) 5 ieee ae ee ee ee | cout” Sum q as" 4 ar. sum (a 5 Sen am, of bi" 22 bb sums Bude A ef cn" 4e et. sume; i ‘ Output : Sum eo az 25 Sum of b= 50 Sum of C= go ale ry constourctoss ey “ A copy comwisuuctor ib a member durin wat WMitializes an object Using another object A the Same clas by using or comsinuctos, the poocers a Mitiolizanen ib simplified: $b possi foia rbeeg ene to declare ond wnitalige ene object uth Tajerence D ancther Un an object Based as ruference, Linen Une Cowboy b&b cad On covustructoy, The wero object Crualid 5 will nave tne same data Mmembeas, as the ouge! Check 5 Syntar num a ¢10,20) 4 aa um 6610/20) ‘om nun béLad, Hindude ciosb earn > class num Ah private : intn; Public: num 0)' J default condeucter hzo; 5 , numint «) Fasamelngea cevis beceln § nek; 4 Da Tae on consti elo R ee g Void maint? num [leo 5 heme Ku)» % Dynamic coneturcten ¢ when alocalion 4 aaa be doe Aagnanht cosy maing sangre Mertoy allocation operator Sew’, when Une Condiovucion vs coved Auynamic covstnucter ae Uovelusctrs ane Weed 1D ana a initroline Objeds KMe cowsructor- | Banaue initioligabio Using Cost uctors amid The data menus of O dlase can be initialize wsing printers “These data rrembers one stoned in Ahe heap ey Tws TYPE of ibatigabiow is cali are ic initials ation - | the Advantage " Aqnamic Initialigalkon % hak memory aur be allocald and aaa duvoung gee Cheadion « Slate altocatlion Pyrannic ollocdion tnt a5 int prs Plre Wes inn 5 2 bye af mene 2 bytes % memoyy Yaowed tn et atin ‘Aout’ wm stack ia | Mist can be cleleled Menno can be nclared using only Aurung yore dele opunator durwag prepa, teminalion eeculluen Bestructns - * Destrusctas ane special member Junction tke, Construnctors. | & beitnintoie Aart a rammony otabpe by he oYerts oa Jnave Dae Same name as Wat of Aw cleus, Pueseh ry bled ayenbol fo KA [rogram commer Wave mow ‘than ove Aestnacth X Destowuctors cannot be overloaded \ue # Beshuctos requine no ia aa and ‘elu no V objet x They release Memeng Space oc cupict by ee = Gi one Cede called ‘oy Bre compiler caen Ane eager tewminales Destructor Ecample : tinclude Oleass Test 4& public : best? Yeovslrucler 4 cour 22° tonetauctoy called \m's 5 ‘ antes 0 // Oettucter h 1 cout.’ Destructo cata "3 4 a> int maint) test T reluan oy wut : covsteudor Coled Dedowuem called

You might also like