0% found this document useful (0 votes)
45 views12 pages

Opp's Assignment2

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
45 views12 pages

Opp's Assignment2

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 12
PARRA fmafele comahu ctor: pats uc too U1 Can static variable access Dyex, Tin crt, We com access Stetic vorrtobles Popa tele Stotic vseiables ae associated esith the class rather thea with com be actersed -brom ary rember v 6 Twstonces of the css, So the Pes eireteleg eoustruchte TAD row victael aleatructors affer from nero! deatructows? howe a class pienanchy Fs A virhol destructor: (4 used when OF trveluing. poymorpiterr. The mom chigfenouce Lefween a virtuol destructor aural normed clestructer ies Tr owls they esalle. object olesteus tow iy podym ery re cceuasioss Usivy uietuolWalespuctoy ensure thot the -lestruchy ch att clossesa fm the hierarchy are catlecl pry when deleting om object-throvghr a fase cod pinky, tle ty Lftoent i Le - (31 Hew text file te bho fem oh Pe cei oh ple Ava A text ple aud a Bek fue axe 0 ik ar bd uses to steve axel mavoge Nolote. The key difference ties Tn he? zjes stese clots or he ented. Tent 4A es steve clon in ik Mae ra the dats is stored aud 30 readable text, ote binery he stores, # bina fe [4] What is pure Virtual, tion 2, Hon is 0. virtuol tumtt par A 2 virtual toe a. pote class but et no Fenplemertation prov ord. A class canton! ts detaxed using the “virtuel” keg meee pure virtuel bons ts Polled om ostract clost: tual pase lass? t claw Oo class thet UY meant to be used ara stuol inhexiteuce + VUirtool ed Tn jor thet is decle wdeol fn thot clo i Bne or (5) Whet is vir ftir virtuol bose - BS base class other classes wsing vt fnhediemece 4 8 en tid tne exection of meMuple Futeneet oa bose chord wher | oppeses multiple times Prom Inheritance there [eI Hows mong oy to ope a file Mpello-txt” fy C++? Pras - nett, tee Ke ceyenod te open 9 pile using the ' fel: ifstream ame fess Ve provides fovett be has file Sopot acd output: Hane, one O cermin, OE Fe to ope a te ermiee! “hatlo.ixt.” - Dafowtt csutructor a> Srput ile ctream (ffsheam) 2 streor (ofstseam) — 4. Bim gla. ettwols has 45 sponte tie eee » 3 Output $2 Each + ese ™ © scanned with OKEN Scanner COCO lLlLlllt—S— TA nasty’ cen, exception? faa > An excepting is am uaenpe thet oceuuns ducing Normal fou of tre Uprogram Exception and exception eee ede Pa Peon csubrllad anol otrichoved way thay troclitional erosr-checkivg menor » (8) Differentiate Leheten class templode ond fev” femplote- Ass = Claes femploter one cteol ov expesfed enceptional expen the exeartion of a peyeom and disrupts the axe Used to howell erorong used to create gue classer- These claster cau wesk with crtbeak dota types wohile Pansicting the same fakenface ox bohowter. = Fumetion templetes axe Gsed to cueote qurcnic punchiont« Wiese ehiows com openote ov obiifencet data types vithoot the to coer fe seponate hae iad each “are: (9) Differertiote between enor anol excep tiny fur Gere? Pr evn in & he picot| nefers to a problen tin the ty Esumus can be c Feed fato hoo mo 2 (lb -fime ili eae, eas Ercagtion + Pr exception in CH ib 2 mechanism a rowel va Fae een I a maxe Catholleo| aud struvtured e Jetting the program temminolt obrupt\y, Excep oy m0) t Pole eu 4 aia esas as Ree opprepricte po ts tne Progen. [re] whet of correo Hy + jo you mean lote birding aol conly 7. - Bony Bineting (static Biraing)! eal Vircligg Hafera to the proceat eagociating & eae cali with the actual cade to be executed Pe eer ile eae alles ees tant oni ot compile ~ ation to col & male me aad the acldners of the fraction is Lowad to tre coll: Lee Brey Copter) Tete erntiny mefens to the proses 4 associatirg “0 ee call with the achial code to be executed of pak The aleaisionyebouks taille ekion +o cot is atexcferned aati 29 . ‘ oe sity roy arcocioted with pelfmerhen et © scanned with OKEN Scanner CC —_—LL———————<—<——————— tum ey) LUFT “En plas PARE -B_ “plain coustant tote member auc corstart member ust +t program Ani In Cit, a corstart dota member with the ‘coust joble of ih @ memben vor foi Holized, " pay wore, Once eis class {rat (1 declared the value of 0 couatert cjota member cauthot be mectifien Hough ti the object: Constant clota membert ant ogten out the Aife'time Used to Preprese volues” thet could not be chasse! opto tot object cs created, ‘ nection ke a memb paretie A coustamt member fe gd, Tt @ promise that the f or qauction tnt i dec laxed with the Naoust” kay wer not medity the stete sh the objet on cohich it is catted, Cons membeX wetions ane US choy woskivg tly corset olf pee coeneiore to Sure tot colire go member fenetion aoearnt after the object's stole. u Jerat clata memioer and dlocta mente Here am example tUnabeoting bot, Cos fonctions Pear a tt Include < fosheam > class ais 4{ public ¢ cost fut constant Value 3 class Link vale) : Coustenct Vole / anitioize coustout J/coustont alata memboet fm (wedi P< é ho < ) clota member [extra tor to MW cexvstout member peas void displey ©) coust t kd: 1 couk<< * Cmstant Valne ."<< emustant Value << std zsendl; ag [non-constant clots member fonction iby Volue iat nenvolue) t void m 1S yee ale 5 a }> cmvat_ casts fut &> Ceonstant Vata fut moin () 4 const MyClass olf 1 (42) 5 aif apis O> Myclass olof.2 (9995 obj2- disc! a obja-me hy Vole (11) 5 obja lisp las vetury 05 oe © scanned with OKEN Scanner OO 2 : A a U 7 Wihet ta qeuuete, proprammine ? How Tt Fenplemented fn c¥ #7 nite Prqram to Tenplewnerted or wing templates : Fins: Geuerie Pro, a ae hag tn ott Pow Being code ty @ wooly that is Tratepentient + dota type, adgor ty aud data pleetes te be wiitten! and & doe eg. The methe eae ipa geraminain (4 Smplemes Yi fe preqrarcesig p Yue cole Mnerease the efficieroy Cease» tJ. Code Revwilty * Acvautege et Prenat oe Py eararan 2. Avoid fuuction Bessie 3.0 once written it cam be Used hr multiple times aul eal lotes. HD Cre qouete proyrarinvg implemented vsirg 42 FJemplatet cllow to write cade thet wosks with og dota types by a basic ovediod: Porameterizing the typed. Here's Ie Function Templates: cee calcu template : templote templote x ty gename T> Space (vay, ae) mee a : bee et 5 Pubife : Coutaines (7 vel): Value Cuar) 4 > T getvatuet? cost qfyehumm volue 5 3. Tenplote Speciodication : ms template <> clase Cautotner 4 chore Vole 5 Cortainen (char val): value (tslower(var)) 7 } private : peblic : . chor get Value () Cost Tovey vale, 3 ie Feurckion Template ith Muttiple Pasometer : template < a fae tc T; Spano: U> T custom Cast (U vetue) 4 qetus Static cost Value) 5 ag Be 1 Crt program ing to Fmplement Bubble Sort alg templat fan us H fin cludes fostream> using namespace Stel late void bubbleSest (T at7, fut) 7 tem © scanned with OKEN Scanner 44 (acii Ree old t,t Fut a5] 410, s® 20,40,20}3 fut n= sizer a /atzerh OOO) bubble Sost < Puts (arn) eoutces Sorted Ud * 3 et cout Pe ciiiiicoen wee tout =< end 5 pepe (°3 t Joy tems «+d a) Ithok is aynamie Biroling 2 explain tne omeept + virtual qonetion usith the help oun example: Drona: Biratin ayer co the pr the ackuol metho ow potion coll ts determine! © col determine ab suutioe other thay compile times Lr object erenten prayers ths opien envolves CLINT uirdual t — A virtual fosetion Ba feretion declared In a bare Coe trot < be overridden Q derives! lok: Exowple ye Geet # mncudeciostyeom > class shore 4 Poclice wmsiwenies <° 22 cout << “proiny a shope tee stds dS ys Putt Dynamic Binding: >| draw 0) oveuside 4 tat Ge or es ere sts * ends py > clos Sport > Public Shope x public? ela obra O weet 4 2 ght cout <<" Drowif ° square” stl: Beate Ty; jut mo O ie chape™ shope | cones rece); eyes ee a squane 3 shape | > apa) > 7> dow 5 delete shape 13 | dente Hopes cretwuy 05 4 © scanned with OKEN Scanner EE : poe of a number. The OY] Kisite am tetesactive prgrmam to find, Aaa f japakive, am Input valuer must pe tated for validity , 4p % 3 exception must be xalsed by Ure" (his tnd Power of Ava‘ ; norm trot coleusotes the | b Pai Hexels a simple c++ preguom MRED apie? : Naud lug: A number handling negative Inputs vith fe q H Inoluole exponent 5 1 cins> bases Aoulle result = power (hore, exponent) 5 Stas: covt<< base ce "Ace exponent aso "ec neult at Pndtudle< fstream > a Inclucle< egte Ub> using namespace stels am thet courts Limes aud choracten fut main ©) 1 ifstream lrpeeainle C'Demo.txt") 5 If hack if tel fee cou ne opeted | © scanned with OKEN Scanner C—O 4b CL inpotetle ts oper) 4 tre !Demo-tat! \!'5 Com <<" Erv0¥ opens 6 defuse expt pAILURES } Tot Une Cant = 05 Tut char Coumt = 05 chon chy 1 (oop Hw each chanacter wv the fue Urdtle (tnputFreget (h))t char Goumt +4 5 U check ad ess ed fo count Unes crete) 4 eomeert ss ST Un input File close Os Hf close the file As eas rs Unes "<< Une Count << endl s cout ce "Number of i ene cout class member access appeal yo (2) > Stope score lation (22) > See operator [sizerg iJ > Canali tianol openotos (~2-1—) such specicel * The mechanism of avin 3s kmsven a8 openator overloading « J H Hone are some surle to follow orhon overtooshivg oF rexotors 2 It 1. Oveseloacled ator: 4 cab Jesst One operare baa ae pie) pe st have ct Jeaat one ope of operanels ts oe operator ¢ cd Quertoad exis Die pBEeii atic Pore. the nucbe 3 We com not create neo operaters, ones: ae F Us Te ovectoosled epercturis precedente anol agsoriatiulty sremainn the same. tH lets cr0eole ionic: ott ees 4 exodtrs overtoadivg te cancaterrote two strings uaivg the "#" opecotor? Be Tyclude oan namespace Sts Fut mon 6) 1 string sty} str2, veal (3 jut TS cout > StTI > eauted “Enter the seem shig "5 cinm stras wp (0204 Ce Strtsizel D5 c+Hd wesudt = veautt + seqCt] ; f te" (t05 ( ft freludle < esuio > F ag veeespeey stb clas Pose meer eae Crea]: public ? jak wale 5 void grt Ot pace ates tree bite ra cinys name> x arena ete eg code oh pect :"5 elem aes, Uke, so classp & Probie Uy cin >> ic UO yor tapleg Ce acer Aye) ates Conte off the pan: nectndes ate class geo 2 utvtuol public person 4 eae: ¢ Hoot pe gu it — ii "Suter the ree? cin>> pags t Jecnomes ”s > © scanned with OKEN Scanner void displ U1 ; coat ceed ce "Poy 2 "<< poy 3 Vs class admins ufyhuat public psa 4 | public 2 Rfecpeces veil grec t aie Reena te eden the capemat’ > cin >> enpestionte 5 3 votd display 0 ¢ ; aS. Pee erpegeucesfecexpencute; J)? class master? publte Peccucs pore “Amn AE puldic? cyan ntiee]) fd get tot (4 Pe vei apace eaten tHe PTY dine ns f Aven, 53> ot i Mg ee teeny yome © scanned with OKEN Scanner

You might also like