programing in c ++ with oops, Exams of Computer Science

manisha maam c ++ oops concepts clear with all programer question solve

Typology: Exams

2023/2024

Uploaded on 02/10/2026

divyanshi-sahu
divyanshi-sahu 🇮🇳

1 document

1 / 20

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14

Partial preview of the text

Download programing in c ++ with oops and more Exams Computer Science in PDF only on Docsity!

> TOOTS CBHI) OV pomResbmata dim of 00? > iat.’ bind» kogether the and the -functiong -khat operate on Ttnem/ssiet mo otner part of the ode “Con access this dave mlign except this -unction + : D/ : = e f > (VT T Class + TRB; a user defined data types, Which hey. _%t3 own data members and member Runctiona yn con be accessed and used by creating an insta of -ynet clase. Q ' Object : When aq class is defined no memory is a\(o | but When Ft 18 “nstantiated Cte, obj ect iS created) memo 1S allocated, By Encapsuletion: In ooP , Encapsulation (iS defined ag bindia together the data and the -functong : i} that mani pulareg Abstraction : Abstraction meang display ing Only essential information and Hiding -the — getanial,, Py ° Abstraction using claskeg « Absrnaction asi, Header Piiex (man nH = pow) E € a __ Polymorphism : —th Simple words as -the 7 We Can define Poly ability of a meSsage +p be display ed “ q more than sone form, + Operator overtoa ding, + Function overloading S fat sum ClO, 20 30) E ‘mt gum Cio, 20) Be me anberittance =comthe aed tba of QA -elass +o~ ee a Properties and charocterigticz from another Eee | | & ig called | fherttance.. bale eel ; « SubClass =| ; & + Superctass = ate 5 % | : Keusapiiity, : q ; Dynamic Binding | Th dynamic binding, tne code to be execureN 2n Besponse 4D LMherion! ‘cal VB ® decided ar yun time, Congtructems: A constructor i8 a member function of a_class Which “nittalizea objects ofsia?, class iq Cr+ Constuctor {B autermatically called When “the object creates . TH has *Same name as Class Stseft .GHinM 8 | Censvsuctor don't have a setum “ype: ‘A, Defa ule Const wuctor CNo pera mexer Passed) Re Parametrized Constwuctox : 3. Copy Gonsrouctoe Supthedo? losidaye7SS Alaa q IR Desteuctos tn Ctt * Derived claay destydector will pe Invoked iret , then -the base clasa deatwuietor | Wilt be Invoked, x, — Accesa Modifier: fiblic — can be accessed “byony clazs Ty Reivare i= canbe: accessed ony iby 1a 7 Fanetion 1@=a E - claay Linaccesivle ourside stheidclasay+ nuh oe -&, = foxéected = Akt if also “Ynaccegsivie outside ~n Class but —p—_,* Exceptfon Handling “ =o ae te er fur mat = = se wh 5 Sy + a Beatie to. ipvint Gris See Ree : Ee pcvr COTA eri 2 “aa i (I3a SS ee ; ; Smitar Blér Eire, pea Coleen wae Scie « Static «Members in C+* Se ea. function : When @ variable ig *Static variable in declared aS. Statice, space fer it Jers aiecated for UiPerime of the Progrom . (defaut @arialized to 0) Even € tne funcrion if calied mu \ tiple times , space for 44 3B allocated once. ae « Static Variable in @ class . a — Declared ‘inside the class bedy » xi => Also Known ag elass. member. variable . , > b> “They must be defined ovtside +ne class. > Static variable doesn’ + belong sto any object , Bur K) ane Whole class . a a Oe i Weeemere AWwill: . be only ~ Copy of Static Member varia for ~ne Whole clazz, sf Exs Class Account- i 1 petvate + os : Fax balance ; Static dre 08 y publics 3 Nold SetBalance Cent b) 4 balance =b 3 5 iy. “linttalised ovtside ass Float = Account 3% Yor Void main i Accourt ai: § ~» Bbject mean arab ee ‘be declared’ * ag. “grat Sate Accom Qi; , - eine Bd ee e Starica Function THIDITHS oD i > Class 74, Ansara HUF ena ye St "FG = 4 Static member funcriong \ >! are aNowed to acces only —ne Stone data = membere ot other state © member funcsiong , ; 8 e Constructorg ;, YT qa (a yatignra) Hunt, : a Constwctorg if an special member. ysfen Chionniof + Class. =+ (2 av tomar'ca\ly fnvokea When an by ect 1S created. ; - 0 ae >It hos no. return type is. 3 k B) 4 Censtructor has Same vame as). Class Manca of Be ace! wes do mot specify gontn CNeidCars: dompi\er generate Q default — Cormp@tructor for ug. a SOPOT le = a =S Constructor _ Pee rons 5 \ aa—4 Yas oR} +o Awe tof De favtt Parameterized Copy Clase¥ name): Stmidiags Name paramererg)> S-Giess_nat Sy laser Update ) sd t4omoupdore Ctm x, Auth) oF a on: a 4 P Sani BbGsni0 jh iudw ti| n=trO=sOHleue seeq Sly som Upaimipet2a9/T p> Ich imeny — vatQUYy enoge P Destructor > Bepentctes Ag ad A: 2 > member Pingel | | cron Which -destructs 7— deleter am object — > DesWvuctos don'+ Be | Rake any" argument andy don't F have Sn Yexuan pe, > Only one destructor \ => Desrructor eannoy he Poss ibie Srotic. yi cy i ‘ Le a 4 doean'+ destwy Ob\eck 9) Tr Bowne last Lunetion thar 5 nvoked before object destrey. So Resource 2 Actvanty destructor Destructor (% used, So hat before deletion of cb} we aan free space alloazted for +hi& resource, Ble iP ob\ es deleted then Space Allo cated for ob) Ml be Lree but Yesouvee = Coearn't . Operator Over\oading 1 C++ neve “tre abitlty to Provide special meas 45 4ne oferotor. v ; J Class Complex ) q Bue, Complex —operater + (Complex Lei) A Gmplex . vez 4 EG= eva; TBD = C2} —— mog directly . Sot As '-+' canl+ add Compex 6 Can define a fnction. “wit name Ve : — meed write operator Keyword iia o Sag Soy weR" use @ qi’ operator Bice this. > Be v Si ; et a r Friend Ci\ass A friend clagz Can omess +tne private and» pro of ome class in Which it is daclaved members friends) vt al Tere Ga be Fiend case and friend finction. ; | ER: Clase = BOK i ] ; 4 privere 5 a | : dwie widin ; 10> [ee poblic » vA 3 bs £ friend \oid Prinwidth CBox box), Noid Serwidin( dooble wa); sd 1 eye >) [po COM 55 92 Nold> Box>t 2 Setwid+h.( Box double ANI) f : € 4 WNT dth = Wid’, U > lee Nold = ; Pein Wiictty (Box box) — Covt Maing) PID S9a" Sele " 4 Bok Box 5 > wd : re ay Baxi SeoWiati( Kz ald PrintWictin box) 5s % S. j “Ss Les, = San B+? Yul AZ c). Multiple “Inlnevitance WOUAASS LAL... BI1t elogs AZ 4 4 q7 cy t ; 2a! Class Be public Al, public A2— B ord ye +14 3 § A ¥ a). Helrarchial Inheritance Sa Class Bi: Poblic A [ iz j = —-z_ $ } eyo > 7 E Clegg BZ: public A ec é + i ! 4 © S50 i espinal Sienied Be f iho : | = Ez 2 Nisibility Mode i Privare = Oacee -——_—__| i frotectect a : ubric a A- bose aloss A ae ee 2fertivedal— jsvs/phoiee AT Private A - tT 7 PretCcregel i E Weve] a id ug S220 os _—Rebtie = Crotecte = = : tug \B Sub Claag = andornisibininy Mode te port te . Class At [poi @ tsydo | Waray . a alist — oe Wy anen public member. Wilt be publics tn B,. and — MEE aorcrecac, will Protected , ; ee: ar 4 ae) visibility Mode ig Private. then both Protected j and poblicN member of A wil be Private member gs | .-- = =\6 a Relationship 12 always “Implemented aR a public An herttnce . — Constructor and Destructor %n —heritance Firat ehiia class Constructor will tun during creation of abject Of Ghild close , bot as Soon Ys ob) # Creqgrxed chi \d class Conetruc+or yun and % wit cat Omatrveros of Aa porent a8 2 and attres Ane Getutte oF parent dass consisuetos FOWL «WeQUME FH ConBT Neer ection , rer hi = potent: construcns = Call r Sy Ga min VAG) 4 Constsuctos Qkea _ white en cose A AeCLES v COs; Qnia cena fiat Chita destrvclos exec | i ce en ferent “deze, eeCuted, Ss hse ie Caer (Conky 2. 23 Ay bv ms6b complete). OF enV ak aoe ee Compl e+e iA me+nod , ae lacnievea at Gonpile Kime. | | Claas Gri — A - | rivate 4 3 | fat gearno ; ae ubl\te 4 = : : | e@hange_gear ( Int 927) 0 x T_N q _——— : | i eee) | a i S t ie 1 Clase Sporis Gere Portic Car A | Noid Change-qearC Bnt+ gear) § 4 TL Gear > 5) | . year aS y SS | ante omdin | a 2 Sports Car acy | Zc. Change -gear (A) ) | | as g | function of Sports Gr Crass Will be called. © et ioe Calling change-qearC) , fret Ft check if any fon =| With 4nis Yrome Vglet+ in w se calling C1028, oth erwit) (8 ; Ls gcezg 4D base Css. | M2 Vike. we. Neve . Change-oear for all except one ¢ ae Fave vnique ~ wewed oF qarcane 4 | a | E a Koay -BATR Sligma) 46 £°N veal Function > A Nirtwal fonction ig @ member ‘function Which is — declaved with a ‘virtual KeyWord’ ‘9 “ne base and vedec\ared Coverridden) wn a desived Class. When you refer +o ay objet of derived Clasz Usi 4 pointer to a base clases, you con call a virtual fine foe that object and execure, the derived lags’ g | Nlersion of -ne fonction. ° “They are used +o achieve Run time Poly morphism . ¢ Virtval Fonction Cannot be Statice and also cannot be function of anotner clogs. Compile-time Carty binding ) Vs Run_+ime Chate Binding) ¥ Saw @loss bage 4 Public yy Nirtual void Prins C) 4 Gourec “ Thig ie bege print” pailleD ax Sao 280. fi VilMaus scar Gey wed- a oeeena\ Fe i, Noid Show l) S20) Same or Pee TyS2x> 4} Teduh seo ae tne Sues ometunaee * oo inp ig OOS So.plaG Seq ates i at TT On + e n ze during Early eid L— ; —1— z NTABLE for ; NPTR ; ; bays} binds 1-4 sm nv \\ aa ; ez ' ee, bails ai derly Ste Slrqmno \\ Y Pure Nivtval Function cvibat 47 \ and abstact Cless : hog fribaid plod | Sometimes implementation of all funcHon cannot 5 fm +tnes base. cla 2%, Such a Grass tg. calied i — => draw * ogy 2 [Shape | S (Bet snere: ant vibra 9 ohana iat tm Plement=aten, | : f 1 5 WE J Equare | vA in baa ~- ad a | e = ; ici ad te saviierd jeter SMe Cteuyle+ca Vintoal functi _coliwinien Dowe o don’® have any “implementation, wee Qe. = W Aesrrack Clags ae Gti 2 NOES STI ERY A aitsn 7 PUTTY Fo ts = BSc 7 UAW“, 4 a | aes : : ’ 220/25 Ubiic + F(do 9m pysus : tors Nive vat A See A Petra ve ton yes ino hae “1B 5 dostracy =e eH Fay ae ie — meee (Wes: Virtual: > function, ts 3M > trues 7% hr ls bo hie Re SF OD We ¢ganuot declare | oa pobject ofa abstract Cloag. = p Ex: Tear KY 2. WIR er Showletror pnirsisd S - ai We) f nist? Saad a ‘2 can have Polnver or reterence: oh. abseme Closs, —- | 3: We “nN Access -+ne omer functions EKCe ps Vira) 4 by obyect of tS devines ciaaast | a. Ne we dont override -+ne puve Nivt+ua) Puntton 4 fn derivea cr e y | : SBR then f+ becomes -AhSract, | 5. An abstract Class can ane constructors, 4 (Read from GfG) ‘ 4 Template \n C++ 5 4 temp late {ar Cneck Cita, K by | LN 4 i ib Car b) vTeturn Qa} t : 2iae = seturn b) Ace doe \ust neiP in data type: Se Anat we can Wi +e generic function -anat can be vse for Aiftererss dota Aupe. NS a ) at Pyne mic Constructor When allocatfon of memory ts done ay namical memory Yoliocator “new! in constructor. ysiag dynamic class GKS 4 . pobiie Nola fnQ A p= new Chav C61} } nr main’) A geeks oS New QeeksO7