0% found this document useful (0 votes)
66 views

C++ Assignment 2

Assignment

Uploaded by

hodibaaba1
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
66 views

C++ Assignment 2

Assignment

Uploaded by

hodibaaba1
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 27
ASSIGNMENT fyhot do yOu mean by idheritance J wnite fis type A) INHERITANCE Tnkeritome i -the called dhnived loys laws The olenivedl claus inherits all the % the base dam but can aol Properties TYPES 4) singe inluridance \3) Multiple inhuni tance 9) Paubilevel inhwritone procs Y treating new class 1 rom wanting dan tall base Copohi dither U)Micrwnchical inheritance 5) Hybnid inlunitonce 6) Mubtipath inhenitance, 5) Whot bs single inheritance | Explain with an sample progr oanple psrogram A) SINGLE INHERITANCE th Aingle inhuritonce , class bue dann otter words when a 4 tly from one bose clas, inkonitorce Flouschaxt [Pave | Soined) Y it dwn, is dovned. fram onky one| © bs Known ax 4ingle while ‘nlariteg class Base Peay of the Base cay lb das Derived £ Qcters 4peuifier Base | i u Becly Y the Renved das b | PRoceam Hinclude s xz J fe: inky, void getyt ) 7 coubee’ enter value of y+" cin sey. cy i on C+ public, publica WC ts durived porn Claw A ‘i and dose Q | DW tae publics al | yor'd sumty i “ext | Wubee"Sum > "ce x +4; } int maincy { Coby); My object 4 derived Clas, a | ob! get x0), bb. get yo; Obi 5ct sum, Melusn o, ’ ovreor ] enter, Value e \f sii Ue puldiveve! inhunitanee ? baptuin, with an exanple praam MUUTILEVEL INHERITANCE Wid types Jn multitevel inhovilance » a aledvedt laws inenits al hs poepentien four a tage that thd Inhontts prom Anolin cag flour hart A | be [a | r t 1 nce | Sytan | Ua have SM Berks of the class bewe | k claw dlenvedl 1: acces. specufien nse M Body of Me claw dloyved! 4 hi cla cloivecd 2; access specifier duyved 7 1 Bocly of the chau aleniveet 9 inky PROGR jeg, HHinclude >2y s voiol producto cout ce"\n Product of XY, 2,velues Ub “ee fa ne } be if Maint) doriver a; Votject of derived class a-getdadzaly; a seaddatary; aindatot); apreocluctoy sutwin o; prrate! hi | | ible ere indaiad | : | cout ce" Entor value of 23’; cin 992; \ ; void producto | ie: \ | L ) ¢ out ec’\n Prout of uy, 2,velues & :"2ela*9% 1 ) | int maine | cloiver. a; Wobject of deivecl class | a-get datary; | | a-suaddazary; a-indataty; \ | | | a.preooluteys | | i | seekwwin 0; | eee | | iat ood 8 obi, ZZ | oonpur | Enter value 4 X51D | Pater value of y Jo Enter value af 2:20 [Pract of ay 5) What is Hlenanchial inh ample propram i) Hlerarcuial INHERITANCE vz values 6 + ay oc mnt! Explain vot | Whur a muito fe wit teers | winperties jum just g t j | Properties fom jus 2g lass. Us called Hienarchigd inky Flowchaxt [Clas 4 Clas B (les C Clas) | class Cass F Clas 6 Syn tox | Class base t | 7 Body Y base clay Ais derived | + access. Spedpion base 1 Body of lass derived } low dived 2: access. Specifier hase Boy of css dlved 2 ye dais denivedn : access Sptifier base : UBody of das deriedn, p PROGRAM include ciostseam s wing nampa ‘4d das Side t protetted: int |; public: void set values int x) —— tex } | i | dass Sqpore: public Side ™ int $90 i retwn() *)); b = Cube: publ Side publi: tht cube) i setuan( | *] *). \ int maint) 1 Square 5. 5.seb- values] 5); coukze" The Aquone vale Hs "ee 6. Sal) ccendl, Cube ¢; | C Seb values 10); | Coubee” The cube valve ths "ee c.cwAl) ve endl selwin 0; | | cn | | The Aqpore value bs: 25 | | The ushe value is: 1000 (09 what te Hybrid inksnlance J Explain with | tannple program | 4) HYBRID In HERITANCE This type 4 inhurilane essentially Combynes | mone -than lwo forms inheritance. desi b fon tstonce, when a child clos, inbenites p ior vaulliple base chaser ond tat child class ite sone os Qa base clan jm 3 y ite olemveot classes | Flowthaxt (Clos A) ‘cuss 8) daw ¢ | class py oo (Clas €) [clos F) tas i finclude ciostueams using Namupae sid; Can stu prctected : int yno; public: vord get-no(mea) 1ndza; : void put_nofverd) (OUL ce" Rolf NOC er nO diplayiy, | bs dda; b> daplayiy: | relusm 6, | ieee A anes | UTAUT I om in \ Tost Derived clay | | | EZ am in Second Derived wre PROGRAM | thntlude cipstreams wing nanupare std; Uo, Bose i public: | void cbyplayes | fl P, day Derived: public base i (ub display); a 4d; i b> displays; Cody Boal occ subwrn 0; | I Youur am in Base clay Toiam in baue clay 3 ie

You might also like