Download as pdf
Download as pdf
You are on page 1of 125
Chapter-1 Principles of object oriented Programming [ 1. What is object-oriented programming? Ans: Object: nted Programming : "Object-Oriented Programming" (2020,2018,2015,2014, 2012, 2010) refers to a programming methodology based on objects, instead of just functions and procedures. These objects are organized into classes, which allow individual objects to be group together. Most modern programming languages including Java, C++, PHP are object-oriented languages, and many older programming languages now have object-oriented versions. An “object” in an OOP language refers to a specific type, or "instance," of a class. Each object has_a structure similar to other objects in the class, but can be assigned individual characteristics. An object can also call functions, or methods, specific to that object. 2 “What is Procedure — oriented programming? : . (2016, 2015) Ans: Procedure — oriented programming : A program in a procedural language is a list of instruction where each statement tells the computer to do something. It focuses on procedure (function) & algorithm is needed to perform the derived computation. When program become larger, it is divided into function & each function has clearly defined purpose. Dividing the program into functions & module is one of the cornerstones of structured programming. E.g.:- c, basic, FORTRAN. Scanned with CamScanner —— Object Oriented Programming Pa = ving ject-oriented programming different from procedure-oriented language ? 3, How does object-oriented programming ao a i :_Provedure Ori Difference Between Object Oriented Programming (OOP) & Procedure Orienteq ming Procedure Oriented ied into parts | In POP, program is divided into small parts called functions In POP, Importance is not given todata but 10 funct as well as sequence of actions to be done, Object Oriented Progra Divided into | In OOP, program is di called objects. Importance | In OOP, Importance is given to the data rather than procedures or functions because it. works as a real world. ‘Approach (O0P follows Bottom Up approach. POP follows Top Down approach, ‘Accessspecificr | OOP has access specifiers named Public, | POP docs not have any access specifier Private, Protected. etc. DataMoving | In OOP, objects can move and|in POP, Data can move freely from | communicate with cach other through | function to function in the system, | member functions. Expansion (OOP provides an easy way to add new data [To add new data and function in POP is and function not so casy. DataAccess | In OOP, data can not move easily from | In POP, Most function uses Global da furiction to function, it can be kept public | for sharing that can be accessed freely or private so we can control the access of | from function to function in the system daa | DataHiding OOP provides Data Hiding so | POP does not have any proper way for | provides more security. hiding data so it is less secure Examples Example of OOP are > C+, JAVA, | Example of POP are : C, FORTRAN, L VB.NET, C#.NET. Pagal. | [ 4. Basic organization of dats and function in an object-oriented programming, 2016.13.10) | Basic organization of data and funétion‘in an object-oriented programming: Object-oriented programming as an approach that provides a way of modularization programs by creating partitioned memory area for both data and functions that can be used as templates for creating copies of such modules on demand. An object is considered to be a partitioned area of computer memory that stores data and set of operations that can access that data . Since the memory partitions arc independent the objects can be used in a v: if : arity er ? without modifications ania Object A Object Date Date Taste aaTTanctons ia OOP Scanned with CamScanner Object Oriented Programming _ 5, Describe the features ‘Ans: f object -ori 7 , ‘The features o riented progr : ® Emphasi ramming: Programs Data structures are desi Functions that operate structure Data is hidden ject oriented programming, (2018,2016,2014.2012,2010) is on data rather than procedure are divided into what are known as objects. igned such that they characterize the objects on the data of an object arc tied together in the data and cannot be accessed by external functions. New data and functions can be casily Follows bottom-up approach in progr added whenever necessary. am design, (6. Difference between Structured Programming and Object Oriented Programming, (2012) | Ans: Difference between Structured Programming and Object Oriented Programming: Structured Programming ‘Object Oriented Programming Structured Programming is designed which focuses on process/ logical structure and then data required for that process. Object Oriented Programming is designed which | focuses on data. Structured programming follows approach. top-down, Object oriented programming follows bottom-up | approach, | Structured Programming is also known as Modular Programming and a subset of procedural programming language. ‘Object Oriented Programming supports | inheritance, ‘encapsulation, abstraction, | polymorphism, ete. In Structured Programming, Programs are divided into small sclf contained functions. In Object Oriented Programming, Programs are | divided into small cntitics called objects. | Structured Programming is less secure as there is no way of data hiding Object Oriented Programming is more secure as having data hiding feature. Structured Programming can solve moderately complex programs. Object Oriented Programming can solve any complex programs. Structured Programming provides less reusability, more function dependency. Less abstraction and less flexibility. Object Oriented Programming provides more | reusability, less function dependency More abstraction and more flexibility. | [ - Application of object-oriented programming technology in various area. 2015) ] Great deal of excitement and interest in software engine Applications of OOP are gaining importance in many ar interface design such as windows. It has also got importa and OOP ca Very complicated and use many methods includes the followings % Real Time Systems Design Simulation and Modeling System a is the user s s they are ance in real business as they a The promising arcas Scanned with CamScanner ndino prepurys op owt pewOSUL woyHoD aup St “,iPHOM O[J>H,) SOrOND UME douDNUDS v “K4peURA “INo9::pIs owt POUOSUE St SNOTIOS Jey ILM SOTOIPUH YOIUN “(») soHEIOdo HonsOsu ay) apnjour# OANDAP OUP “asvo sp Uf “sosssd01doud oy se UMOUy st Jes apnysuyy UuresB01d oup Jo uonduosop Azoronponut Joug v s4 1 ‘ase sip 4 werford 40 9po9 ou Sulusdou09 suomearasqo 30 suomeuE|dX® Loys apnyout oF WOK osm SJouUEISONg “wweTo1d yp Jo 2o}Aeyaq oy} Uo I994J9 OU axLY pur JoWHURIFONd axp q Suoumutog ore (//) suis Ysejs ost ya SuUUIBq Sour] 445) UI ‘ wIBod 449 o[dumes 1) re 10) 9301939 PB = luaysts Bueuedo oxyseq 9 pues —— qwauamsineine 179739 “OT on 0 uxng03 = 201590 JeBuuwbog - t sotwunteg ———. (Jute aur ssn cvostdsowenysium—+ pas eordsoweu Buren & Hs eumeazqsoy> apatoury + uexhord +49 atdums // Weid01g +49 & JO SUeg ay ENSUE] SUTTMTETSOIT JO FFD WET TOT . é suy Con “aBunduyy Sunmuess01d yo 445 Wed aolem au SquOsSq (s] swoisig vodyg pue py swoISKS WWO/AVO/WID swoiskg UoNCUIOINY d9LyQ pur yoddng uorsio0q, SuumuesTo1g Joqeeg pur Tunpoayon jesnoy, vipouuadsyy xonadsyy woysXg s9Aaeg-1UdI., aseqeieg pamnquisiq pag 190! asequyed powwoug 199f4Q SOOT H ON TN Nua BOre ps Scanned with CamScanner oe wonouny oyroods out uuoysod 49119 UO . ors "0 39 01 SUODE 9UHOS SUH snsouy | #ououd griqow tjo IND UL | —_ardurexg . ! * yonvinsdeous ysnosyy poaoryoy poaoryoy : ‘SuOp st sno0d aq pnoys ,JUya,, UO St SNdoF sno0q 2 sunn pxoy uBisep, Summ | wonRanddy [ee THOWSAS © pring | oysss yo syxopdioo ayp SOPIH | _ oF Atmss9900 91, syuowio]9 TEUAA o1seg = worejnsdvoue ved uonoensge Bed “aonepnsdeoue eyEp pur Tonpeaisqe vyep UsaMyoq aIUaIaTG ssuy Guonumsdeaus vyep puw wooEAsqu LEP waamyoq a9uas9y1C “IT | [ aioc'rroz'L 102) (108 ‘OArdurgsr ‘(Qozis -sopdurexg : uonoRnisqe se UaoUy st spreIap 9up Surpry pur sfenUasso auf quo Suiptaosd Jo ssovoad OYL “MOA quopuodopur voryequowioyduir we SOATS JT OSNBD9Q ,JOBNSAE,, Poe st 3] “suonesedo oy) Sunuowojdust soy posn oq [A sumpUOSIe. yeys pure zoWOUT UF poziuefio 10q {tas erep stou Xztoods you Soop 1] ‘Paruowajduur aq ypas suoryesodo asouyy Moy JOU IG pounoyrod aq 01 are suornexado yey suoNUoU <|UO LAY JO YoRULJEP oy], ‘suoHeIedo JO yes B Pu one yo ws & Sq pauyap st so1ABYOq aSoyM S}99{qO 10} (ssejp 10) ody t st (Lay) ed} wyeq 3eISdy suy, 7 LAV) oda wep PEASGE S1IUAA ‘OT | “soenidueT| pomouQ, “Sena posta wofqg jo ojduexo ae vAVE ‘+49 | 19f90 Jo afdwexo ae qa ‘iduoseavp | aduexd yo Supuig atureuaq * wonseaAsqy | souryOYUT Hoddns you soop 197 ssEID req —“souroyyy. ——-“tustyduoursjog | soipoue wioyy ssej suo usyuL youues ‘uonensdesuq = weg = oy] SdoQ | 1nq x04 yo!GQ pur sseo ‘gu. UBD) jo sidaouoo oy) fe suoddns 1 asnvooq | nox osneooq ofenfue-y Sunmumerorg soBensuey pow welgO we si +49 | posta ipofgq ue st oiseg _penst oydureg asureu5yu Supnyour sdoQ Jo Somyea,| | —-soueDyU > MER] sdOQ = i aij je suoddns aBensury powoug wolgo | ION sooq ofenFue] poseg a om sdog yo soame = f : uy ye suoddns often poneuo a you peas 9 sama} ame Hedias [Sue aBienTuUw'T poWIa1IG 199!9O ind paseg ypalqo | so uoddns endure] poseg 199/40, ‘oxen, (e1oz'L10z)'se8enduv7 poyuat49 199199 pur paseg, algo us: ANT} Es 7 THEMTTET PMO DITO PUT PITA WTTIO wasRIG STOTT uy. qaouareyia’ 6] Scanned with CamScanner my : . “sod wyep quosoygip a sub ours on SuuARy Se sssypo 40 suoNoUNS oseyT ouLp on Sige LL EUSIUCAOUNK Og “polgo uv jo souvjsut UOAIT v oye] oy 9s 0) 2IQEHENE axe Yep soumEUIs yp pu “spompau 30 tony 3o LONE Y"3Hep9}0, ‘rep pur suoinou yo 3 HMO Sa, SEY 1 UO pu seep quosed a st ey} HONDAS, aJoyN w sey ssvIO PIIYD ais ‘os aul, “SSBIO JOMJOUR Jo AypEUONOUTY apuOAo 40 pudIXO OF SSOIO v JOF AGE OWL, :IUEIEIOyUT $sb[9-BurUMo 21 poronioid 10 o1aud sv porejoop 09 01 o1q4KUIEA v o]quta OF spromdoy oeNTUE| rei panes st na " sanqua feUsoIXe Woy 19Afqo oY} Jo sIUoUOdutOD awos ros}OId OF AUJIgE DY] :ONIa}04g IEG (ssejo 2 Jo uoREIUaUIA|dunt a4) UOYo st 20/0 ue) yolgo 40 ‘seo e payed st Sty, “eIEP ou UO'ID a suonoUry JO SpoyOU OU IA saMonus Prep Jo UONEIOOssE 10 Fuydnoo YSN y : uoNEINsdeouy :Soureu UoUWOD asoq]1 onigyos uoyo are sompeny soy, “Odense SupuurexBord oyp owt eng axe yey sasnpeds [O49] £901 ps § ay, sidsouoy osensue] uonewowodur ay axe usisog poqwaug r09!9Q Jo sideouoy o1seg “Auyeoo| igus s0iseo sowiogaq SuSEngop pue ‘suesTosd pouoyio yoo{go-uou wey a|qepeos o40W ayo oie sumtsdosd. asoyy “soururesTosd ou) pre 0} [OO jenjdoouos ¢ sey yey) odensuey ‘SurmuresSoid se poulyjap st uBisoq pawaug 1alqo, FPEOIMUE WaISSP payTaHO- aq UF PIsToAME S515 2961 ut ‘uBisoq pom9149-199(40 popin soded yssyj 947 101% POP pean jnun svjndod owoo0q jou pip wo auf, “MIBL [ews pue vinutts popnjou pouoddns yey sasensuey assy oy nq ‘ponegap st uftsop poquo.i0 190lqo Jo suvSy40 ax, wressioud Suismoyf J0110q v 9ALY 1 40PJ0 WI 9p09 sro yno ueyd 0} ssoururessoud soos0y Wey WooUoD AH St usisog paiwauig 10149 TWAISap WHISKS suy (z107) eer uisap payuats0-799!qo Ut paajoaur sdays Out Ayersq yeaa Gudisop waysds auyad “EL sssvjo paatsop Kysnotxasd wiosy Sse]9 & OALOP 129 $1 SSv[D POALop oy} pu “4OISoOUT JO J, 49410 qesnoy “ssvyo suo ureyp oxouu wo4y paatsop 24 wea ssPI VT ‘puiye ‘ssvjogns por 0} sjqissed osye St 3] “Wopusasop 40 ‘py “sselean nlared ‘ssvjo ans paypeo osye st ssvpo oseq up Ampiqestios st doueysoytt JO auoarno ‘Aqpiqesnos pu owen ou “OOuEIHOU giuisn poaotyse st Ay peo woyy juosOJ!P 20U HE posts qjog Jo soanaeay 9m) ARH, 1, suo Bunst%9 poy pur plo " sunvass £q 91415504 5 aug wo4y sto avou @ Buneas ns aan gogo 0! id ; Auyiqesnay * s orsodoud Jo asnos oup surat SUsqesnOeL ay Apyequsni9s St TEGAN, ‘a ) ‘seep mou parHo| St ssejo aseq oup “(soourt OyUL 8 ssepo ANou OU “sseIo BUNSIX Duy ur sounpeay BxIx9 PPE UO ONS Sossajp poatsop eu Ul sseyo 9864 9M JO apg ee srg anongu nO OD NOH (1102) HO ws Scanned with CamScanner souny una pue oui ayrduuo3 “ynog 2 poproap oq WUD OYOAUT 01 uonauy ()10]09 19S OUP JO WOH yotyas “08 ,40]09_ 19S, HONOUN . avy osye ue 21qe) Suu, SEI : panquuny, 8 St 91921, & 'z pur s0}09"¥9s, worjouny oacyy | sv “sannuay, Ssefo yp Jo oxnTeay sje uvo ,2jqer Apnys, Ssv]> ULL OU TOUT US ,91qe}, SSU[D JU f, ojdurexg “souvyoyut pugdy + (Burpusoao) pur souRy yur jeoryosesoNY usrydiowrsjod oum-tm 0 “goueyoyut [oAorsy|NUL (Stpeoparo) wsiydioursjod sum } ‘souejoyur odnynut ‘ooueyoyur dyiduios v og Avar wstydiowsyog p[durs v og Keur doueWOYUT suog -(Smpusoa0) ‘duin uns sv [Joa sv (SuIpeOpIOA0) url ojidutoo ye “uoyat -apoo jo yysuoy om payoaur oq 0} uonsuny oyp yo woy | — ssonpax pur JOO Ut Aupiqusnos DIA Opr99p 0} 199[qo SMOTTY Jo ydoouos, oy yoddns o, | ° - asp) “spoyjowluonoury uo poyuowsyduut “sosse[o uo poyuowoydut Aqyeoiseg st wsiydioursjog Ajyeotseg sr oouryoyuy | woreyuowopduyy “uuoy 'ssvjo Surjsixo Apeaaye adiyjnus 105 soxys0}u1 uowuios | a4 Jo soqodosd oyp Bursn ssvjo Aqfeoiseg st wstydiousjog NOU B Sunvodo si oURILOYLT oiseg x NOSIYVdWOD WSIHdNOWATOd AONVLIGAHNI Yoda SISVa :suy ow Asowout ‘SILOO||e I,USOOP SsEIO BJO LONBUNIOS OU, ‘promAoy ssvjo Bursn 4q posejoop st sseyQ qeotoy Ty. ‘Ayowour sounsuod algo Jo wonea1y “Prono moun Aq poyoaut st y99lqQ Wears “yoal4Q sv UAOUy st ory qias qUysdonyq 40 oyeAcuI9) y | ssUIO vJo.doUR)SUE Hy uoweso ype 1019} diowdjod pu souuyioquy ayy uddKgoq YSINSUNSIC'ST | uonear) Sququo jo aL uomuyod. Nosrivaivoo UO SISVA aq wai TH] i paniang HOMO Scanned with CamScanner yop Sproarday aup are (SioyrTeNb od& sv uMouy os[e) ssoyIpoUr osouy, “sumLjIpou ody [e1oaos q papacaid 9q ue sod) yep quiod-Sunvoy pue pessoqur omp ‘sodéy -trep osom Auowry “ads crop ploa pur aurod Sunvoy ‘Tessoquy om +49 YW Yoromoy ‘saquta ofduns axej0p 0} pasn oq youUED proa ynsox v sy “Buryysue auoys youues YW “oouoy pur poywoo}ye st LIOWOUI OU “PIOA JO, ‘onNTEA
    apnjoury ‘ “vonyindiuei sm diay oy sit suonauny dod puv ysnd asaya yovys & aywindyuew 0} wesBo1d 44> ajduis aes Of “Sua7 Sung ysope|Sueg :Suung Aue. su, yndyng, { ‘9 wmar squnos>>,, Bur] Suuyg,>>3n09 { “+4 3un0o } (+8, 0\=iLty9:0=1205 “(p)sEs juLys Sue 1g, >>IN0d Sfozlys aeya sg=qunoo"t yur i (Qurew yur > In0s } (0 > doy) jr ; } (Qdod::speg a1 ‘ony winyas x= [douse } aso { Sosyey wanyou Sy NOlJOAQ yous, >> 309 } (xVIW =< 40) 3 } (xaupysnd::yoeig 1004 4 2QSadurgst 1009 «()dod qu! (x qus)ysnd joo, {51-=dor} (yes Scanned with CamScanner Syuns‘ut roy, }( jurews qu opnyoury > (dod's >> 109 S(ogyusnd's ozusnd's scopusnd's ts youig PMS } (Qurew qut suonjoury aaoge 159} 0} wwesSoxd 20ANC // (0 > dow) wna } Odadugsi:you1g [009 Sx umyar Scanned with CamScanner mt BE . a ie) gue ssvia THN” ssv[Q aseg] [BUNTY JO SSe[Q PSALIAG Aq UR MOD 4ug ‘oq :ajdwexg ‘ssB]o Bursixo ayy} JO spoyjout pue Spjoyy 4) Sursnos aiv am “siyy Bulop Aq “ssvjo Sunsixo ayy Woy ssuJO MOU INO BALJOP UO dA ‘TUeM 9M JU} POO atf} JO AOS SAPNjoUT kU} ssepO v Apwauye S! 2404) PUL Sse[O Mau E aqeaio 0) uea om UY ‘9'T ‘| ArtTIqesno4,, Jo }doou09 oy) sHOddns oouvyOYUT cAnqusnay + ssejo 10dng 40 sse|Q aseg parqee st sseo qns Aq paupyut ase saredosd asoyas, ssej> ey:sS¥{D sadng + sse[Q paatag 410 SSUID GNg pay[ed SI ssejo JoyIOUR’ Wo soredosd spout WY} Sse] OUL “SSP ANS + “BurumuesS0rq paquaig-9afqq Jo sesnjeey jwewoduis sow 94} Jo avo st ooUeILIOYU] “souPMLAyU paleo SI Ssv[p JoloUue Wo} soNSHIaIoLIEYD pu saiuadosd eAtiop OF ssv[o v Jo Aupsqedeo oy, aoueaquy 1 OMsuy uonensdysug weg “0 uoKINAYSGY FE"! aaueqayuy t (0Z0z) suzzay Burmoyjoy ay) Bua “IZ { sg wnat SINS >> ,.: St Solos oY Jo us oYp,, >> IO? { . Sy + ums = wns s(rypasod =4 VGH apt t0=o ‘y= ums su >I? ~SuiuiuBisory panTTTTG 1510 Scanned with CamScanner Aurxoqduog SH SOOMPAI OF Poroouu0D 94 youNLD Adxp os worsés amp JO sured owos sopry, voneinsdeoug woIsKs ou Jo sized snouwa uosatteq suorsaui0D Jo apmnynur B wog sosize Aqureu Aarxojdus0>) ‘909 no4 ut Sutjdnoo x9A0 jonuco TY/SASSEIO J9I}IO) S$¥ID B JO syUDIIO Bunejost ur sdjay uoneinsdeoug B10 NOK soarSpur “(ssejo siyy Suisn ose yey suorou 1 pasodxaro1aeysq oy) woy syeiep uonejuawajdun Suruanoid ‘ssejo e apisur yoafqovyep posmonns e JO a}eIs JO sanjea ay} apy Oo} pasn st uoneinsdeoug Bip yeyIUO ayesodo yey spoysaw oy YIM BIEp Jo Surpung oy} oO} ssoJOr Y -(SuTwMUMTeISOId poywaHO-F9e!Go) qOO Jo sjewowepury oy) Jo suo st uoreinsdeoug HOMsUy ZIOT PIOT OZOZ) “UoMsod anok Ayysnl -_,Aprx9{duro9 oy) saanpas uonensdeaug,,-2Z uor}oas Jayp10 Aue Woy UappIy axe sjunosse Biep oy} ‘a]durexo oAoge oy} UY “ere ay) sopI ‘ uonoas ayy Jo Aue jo eyep y eee eo men SV “Biuply Lo woHDUSqD PIyp Oo) Spray os[e voNe|nsdeouy Osje uonyjnsdeoua Sujsn s : maiyeqiadiesig cleat p}op punosSyovg ou) Suipiy “plsoar opisino oy} 01 eyep ayy So ee ao aniaeid 6 sape[uoteneas EFC eIND sa SRG a eS Kuo Suikejdsip suvow uonoensqy ++) ut Sunuwersoid PE OnEU aaa nyvay JULLOUWE puk [ENUASSA SOW at] Jo 9UO si LONOVNSqL LEG Paquarso-yoafqo Jo SosnIwoy t * anonnaqy ict 7 BuiaseaeaBosy PorVwszcy TAC SIT HON A Scanned with CamScanner ‘SIALIONTO Os|0y pure ‘ony ase spuesodo si yolws “CNV Uoneiodo jea1oy wea[Oog ay1 0} spuodsaxi09 zap soyeIOdo YL ys B UIFIGO 0 stoIssordxo ony SuNENyeAd YOHE9PIsUOO Ur LOFIpUOD feUIBu0 yp Jo uoReNfeAd Ww09 O1'pasn are sioteiadg [eorsoq oye rodo TESTO] uorssaidxa ue ayninsuoo spuesodo 8 OY PBO], soAsue peuy v apeqnopes oF (spuerodo pojjes) sonjea om sosn weeg ‘snnpow om Suze) pue ‘vorstarp ‘uoneondajnut ‘uonsengns ‘uomppe #889 AY 405 sforesodo sapraoad 1] “onauysure op 01 sioreiado soon HO HUY (> | =< “=) ame storeiodo yeuonejos ayp 30 awiog “219 101 30 putisdo saittresy et 2218248 st pucsodo ue “ou 10 pusiodo so1po ou ch ayduwexs 10q “spuesodo om Jo sonjea oxy yo Wostedutos sof pasn axe sioreiodo jeuoneiay FSIOW!IOIO [PUSHED ‘PawuDyUT aq touued Inq PopwOLIOAO 2q WED Yor oTezado A[uo o¥p st zoyeIOd0 woMUBISSy “(onye: -A] PolTed) apis puey-yo| SH} o1ut a4 Adoo pure (onqeas pojtes) opis purey-aysts ox Sorgen an uouuusisce 20j pasn st ;=, soeiodg, SoyedO WMUsISSy sioyeiadg ostnng storerodg yeo1o7] sioyesodg onsumpuy sroreiodg jeuonejay f storesodg iwowusissy = storerado Jo soda Sursv0}]03 axp apracud : diuew [Lo1Fo] 0 yeonewoYpeUE a1jId0ds woysod Pur suoyeiodo ut-ying ur YoU st +49 “suonyini 1 f z jo 91 s911du1oo oup sijor TIP JOqUIAS v st sowwsodo Uy! SSENBUE[ FUT POST TOTTI OS a [ (i107) asodand soup ayes puw adunduE] 45 ur pasn zoWiedo jo MAU OG | Scanned with CamScanner S9INJIN.YS [0.13U0D puv suoIssa.idxy ‘susyoy, Taajydeyy ®aIp 4 >>u= BSH INdINO AULT >s3n99 ‘0z=r, ‘Stur mou =e, :o1durexa soy ‘a]qeuea s}I0d ar0,0p 4-4 ur soreiado a10j9p Jo xeIUKS jeiouay “Ayowiou Jo aseaja1 103 s0;esad9 1919p Buypuodsou0> ou asm OF worougo StF “pasn st soqexado mau B 29uQ “Papoou i070} on g veolgo omp uous ooeds Stousous Buyse9jou 105 pasn st +443 ul soWeiedo oto|op au, TOTEDIT a “poreoo}qe sovds Ssowiou Jo sSouppe auf sploy ¥ ajqeurea roqod amp “yurod Sunes sw 0} 1o}uIOd susMIOX pure uy adsiewp 30 s09fqo amp Ploy ot Ksowous auoroygns sopeoo}pe zorerodo mou ou ‘a[duiexo anoge ain uy : (ogy wou = vy tr 39 ‘oc=%, ‘aur tou =e, au idurexs 104 odkierep oda yo oqqeuea & st ojquiea sowuiod om pue prom.Goy wv st sou ‘juowroyeIs aAoge arp Ui soddqerep vou = ojqenea soqutod “449 ur sorezodo mou Jo xequAs yexoU99 “adh Aue 30 yoafqo oy2a39 0} pasn aq wea sorerado sty woneooyqe aBexoys oureusp J05 pasn st 443) ut soyeIedo Mou oy, TOWISIOMIN, Awa JUOTUAMOD pure yUaIOIO ur 899019 zourow Buroo4y pure SuEOo||e 40 posn ose sxoyexodo yuoUIoBeUEU! LrOUFOUH OM: BSH aap MOU gy S444) UF sioyesedo quowoSeueut Krourow Jo soddy ony ore S191 FO Ul dojerodo jusursseueur LOWY :suy (i107 7107°9T0z) “H+D Wi Jowwsodo juowoduuwut Arowou oy 9qIH C T T 0 0 T 0 T T T T T T 0 T 0 0 0 0 0 0 byd bid bed b d smop]og st 2F pure ‘| “97 49y sojqer yin ou, woneiodo 14-44-19 wuoys0d pur sug uo sysom soreiodo 2siNNI Sr0;eI3IO, oo uTCNRATONY paTUaLIG WTO FON SRR Scanned with CamScanner OO Ut posn Apoarsuo}xo st UOHezteIyTUL OTMeUAp sz +P uowssordxo Gutsn ou una ye poziyeniut st aqno o1quUEA ajduiex axoqe UL { {9 wna fy By, B= oqno qe << uD $8 JO On] JIU, >> ino seu } Qurew ur gjduis v jo Asowour ouy sasvojox woWLoTeAS ISI oy puoods om 2 ‘sroquiod [Joro,op 1aqutod ayojap . :S1 xEqUAS soy, cqyajop rorwsado jo asodind oup sf Smif, “Axowous onureudp Jo sysonbox 10Wf0 105 US aigerese eunonoq S10UoUr up TEM OS pady 9q UeO I ‘papseUt JoHUo] Ou st If SOHO ‘uresfoid se oud agtods SuuNp papsou 1 [9p []Mou !Mou sso;es9do UONESO[Te op puL UOREDO|[E ArouoU TUEUACL ] “PapeopaAo 9q uvo oyD[op pur arou‘soyesodo Joyo Aue OALT -poeds Arowrou otf Sunvaro aya o9!qG0 amp 9: ssod sta “ysvo ad} v asn 0} past ou st azoyp os ‘adéy soqu1od yoaut09 om suumax C|yeoreWOIE I] < {Qgoazts xoyerado ayy a8n you paou 94 390fg0 BIep Jo 921s amp soyndutoo be allocated using ‘new’ and release it using ‘delete’? 9. How can memory atone Answer: C++ supports these functions and also has two operators new and delete that Perform the task of allocating and freeing the memory. Memory allocation operator new , The new operator denotes a request for memory allocation on the Heap. If sufficient memory is available, new operator initializes the memory and returns the address of the newly allocated and initialized memory to the pointer variable, Syntax to use new operator: To allocate memory of any data type, the syntax is: Pointer-variable = new data-type; Here, pointer-variable is the pointer of type data-type. Data-type could be any built-in data type including array or any user defined data types including structure and class. Example: // Pointer initialized with NULL / Then request memory for the variable int’*p = NULL; P= new int; Memory deallocation operator delete delete-expressions to deallocate storage Previously allocated for a sin, the standard library implementation of this function is undefined unle: Pointer previously obtained from the standard new(size._t) or operator new(sige_1, std::nothrow vt) Since it is Programmer’s responsibility to Programmers are provided delete operator by. igle object. The behavior of $s ptr is a null pointer or is library implementation of operator deallocate dynamically allocated memory, C++ language. Syntax: Release memory pointed by pointer-variable delete pointer-variable; Here, pointer-variable is the pointer that points to the data object created by new. Scanned with CamScanner object Oriented Progamming Page No #125 [10 Explain the use of Unary and Ternary operator (2013) ‘Ans: 5 ‘Unary operator: Ithas only one operand. There are two main un; 4 increment operator + decrement operator Increment Operator The increment operator(++), ‘nwo types like pre-increment ary operators ‘hich is to increment the variables or the constants. Increment is of and post-increment operator. The pre-increment operator will assign then increment the value by one. The post-increment operator will increment and then assign that value to the variable. we will use increment Operators mostly in the looping like for, while and do.....while, Decrement Operator The decrement operator(-), which is to decrement the values of variables or constants. Its similar like increment types. But here it’ll decrease the value instead increasing Ternary Operator Temary operator is also known as conditional operator. It has three operands. Syntax: expr?stmt] :stmt2; Ifthe expression is true, then the statement! will be executed. Else statement2 will be executed, 11. Role of scepe resolution operator in C++. Explain with example. (2018,2012) Ans: Scope resolution operator: In C++ language the scope resolution operator is written C++ supports to the global variable from a fun function name. te iction, Local variable is to define the same * "dentify variables with use of scope resolution operator when we use the same name for local variable and global variable ( or in class or namespace ) Resolution operator is placed between the front of the variable name then the global Variable is affected.If no resolution operator is placed between the local variable is affected. CO lution Operator Syntax ‘identifier // for Global Scope class-name identifier // for Class Scope namespace identifier // for Namespace Scope “simple syntax *global variable name Example: finclude “sing namespace std; Scanned with CamScanner ';// global variable int main() { char ¢ ='b'; /Mocal variable cout << "Local variable: "<< <<"\n"; son operator cout << "Global variable: "<< ::¢ << "\n"; //using scope resolution opera return 0; } Output: Local variable: b Global variable: a Scope resolution op in class: #include using namespace std; class programming { public: void output(); //fanction declaration 1 // function definition outside the class void programming::output() { cout << "Function defined outside the class.\n"; 3 int main) { programming x; x.output(); return 0; } Output: Function defined outside the class [ 12. How does the following statement differ? 013,201) _| i) Char *const p; ii) Char const *p; Ans: i)Char_*const_p- char * const p is a constant pointer to a variable(i.c. you can’t change the pointer) #include int main() { char z; char y; /* Invalid, gives compiler error "uninitialized const p" */ 1 char * const p; // Need to initialize at declaration time char * const p = &z; // Address cannot be changed, Must be initialize at declaration time *p='AS Scanned with CamScanner Objest Oriented Progeny. J/ const pointer can't be change, must be initialize at declaration time printf(" %c \n",*p); return 0: } ji)Char_const_*p /const char *p and char const *p both are same] char const *p points to constant character(You can change where p points, but you can’t change pointed characters using that pointer). #include a iival gives compiler error "assignment of read-only location *p" */ '; _ // You can’t change pointed characters using pointer printf(" %c \n",*p); return 0; } 13. write a program to evaluate the following function to 0,0001% accuracy:. (2017,2014)_| SUM= 1+ (1/2)*2 + (1/3)°3 + ...(1/n)*n #include #include #include Void main() { . clrscr(); float i,n,sum,k; cout<<"Enter the last number:", cin>>n; { kepow(1/i,i); Sum=sum+k; Cout<<"The sum of the series is:"< #include c #include int fact(int n) { if(n=0) return n*fact(n-1); 3 void main() { clrser();, long int i; Tong float sinx=0,x=30; X=(3.1416/180)*x; forli=1;i<=7;i+=2) sims=sinx (pow(-L,i+1)*pow(,))/fact(i); . Cout<<"sinx="< i#include #include int facttint n) Scanned with CamScanner ming else return n*fact(n-1); } void main() { clrser(); Jong int i; long float cosx=0,x=1; X=(3.1416/180)*x; forli=1si<=7:i+=2) cosx=cosx+(pow(-1,i+1)*pow(x,i))/fact(i); cout<<"cosx="<> nog }OAe (dsp pros “onqnd Indq sso { { £,0[]94,, >> 3909 }Qejdsip pros jenana coyjqnd } Bssey :ojdurexg “seep PeAtiop.ut uop aq Sfuo ues 1 “srojouresed pue odéy wunyox O11 omyeUdIs sures WM ssepo paauap Si UE MoRDUNY ssvjo oseq Jo WORTUYOpor ou st a OWN UNE Je pordtyoe SuIpuxsg uonoUN{ TSUIpLaeAQ wOHIUny °(q aur °e aur)eare pos <(e aun)eare pion soydurexg Ssb[9 PoALtop St JJoa se aseq UI OUOp aq ued 4] “ajox Aure Kejd 2,uso0p adc twmo4 “syojourezed Jo od erep aueyp ‘siolouresed jo saqumau Stnueyo 0-1 ammpeusis SB 4 wonouny yp JO SuorMuyoP ajdiyjnut sopraoid a “oun apsdutoo ye porotyoe Surpeojsoao wouound TSUIPEOLTOAG uorUN :suy (Ot0z‘T107‘S10z‘9107'810z) {3uypy49A0 woNDUN) puv Bupeojsoao worsuny £q uwaus nod op WHAT ++) Ul suonouny “BuruURIsory poruDtTG 190 Scanned with CamScanner Object Oriented Programming (2011,2010) Function overloading Function overriding Function Overloading happens in the same class when we declare same functions with different arguments in the same class In function overloading function signature should be different for all the overloaded functions Function Overriding is happens in the child class when child class overrides parent class | function In function overriding the signature of both the functions (overriding function and overridden function) should be same Overloading happens at the compile time thats why it is also known as compile time | polymorphism In function overloading we can have any number of overloaded functions Overriding happens at run time which is why it is known as run time polymorphism. Tn function overriding we can have only one overriding function in the child class 3.When function overloading needed. With example. Or,What do you mean by Describe with an example. ‘Ans Function over loading is yet another feat function name but different class area int sq.l.b; float r; public: draw() {cout<<"no shape"}; float draw(float }; int draw(int ); int draw(int ,int ); h float shape:: draw(float cir) { cir; return(3.14*r*r); b int shape::draw(int sq) { return(sq*sq); overloading of.a function? When do we use this concept ? (2015) ture of polymorphism, Different functions with the same arguments are defined in a class, Dui function is called depend on the arguments passed. ring compile time the appropriate Scanned with CamScanner int shape::drawCint Lint b) I-(atb); retumn(2*1); he so depenids on the argument passed we get the area of circle square or rectangle. [ 7, What is an inline function? (2016,2013) ‘Ans: Inline function: An inline function is a function which is expanded in line when it is invoked. That is the compiler replaces the function call with the corresponding function code.It's general syntax is as follows: inline data-type function-name(argument-list) function-body; } For example: inline int sum(int a, int b) { return (a + b); Inline functions are best used for small functions such as accessing private data members. The main purpose of these inline functions (usually one or two lines of code) is to retum state information about objects; short functions are sensitive to the overhead of function calls.Longer functions spend proportionately less time in the calling /returning sequence and benefit less from in lining, : 5.What are inline function advantages and disadvantages? (2016,2013) Ans: Inline function advantages and disadvantages: Advantages :- 1. It speeds up your program by avoiding function calling overhead, 2. It save overhead of variables push/pop on the stack, when function calling happens. 3. It save overhead of retum call from a function 4, It increases locality of reference by utilizing instruction cache. 5. By marking it as inline, you can’put a function definition in a header file (i.e. it ean be included in multiple compilation unit, without the linker complaining) . 1. Itincreases the executable size due to code expansion, 2. C+ inlining is resolved at compile time, Which means if y function, you would need to recompile all the code using it 3. When used in a header, it makes your header file larger wi care, ¢ e of the inlined ‘ou change the code of to make sure it will be updated th information which users don’t Scanned with CamScanner syoyouq Ayn 3 OU} WIA spuo pur preys UOHOUNy oy} 5S ‘Toquiés uonreupusy ou | Jo “yspxo uouoyeys wmmyos v Jt ‘sonea SumuMa1 10M suOHOUTY JO “s481xo 0108 v 40 “youms v ‘doo] v Jt ‘onyea Surwsnjos suonoUTY 104 come 9404s Jou Aeus worsuedxa auyjUF d194M uoNENyIS 1p Jo oWOg “uonouny jeULIOU v se UOHUNy uonoury oy Jt sonbos siqp ou0Ust 2 odwoo pue poyworduros 00} 40 ose] 001 St UOLTUYOP UOL eu aida out cs oy} 0} ‘puruuod v you “Jsonba ¥ spuos Ajo19UI proxrsoy ouTUE OU, I (€10z) ssuy 320m JOU SOP WORFIUNy SUE! DIOyN HORETG'S | sjuesysuo <10WOW O} oNp W]e ye pasrayard JOU st ozis opquynooxo oBsv] OLOYAL WOISKs Poppoquud uF o[dureXo soy [MYDS JOU soUIOWOS “¢ -souvunopiod wresoid sno€ uatop SuFuiq ynvy o8ed Jo soquinu ao tows uy Surysesrp osnes ALU YoIAs ‘OzIs o]qLINOONS OW SOS72V0UL IL DAOGL PouONUOW Sy “p iutuNBOrY PET FF ON deg, [ qpionyoureu uortouny adAwamay nok quoumndase ou Soret HONOUTY ® Jy ‘(qsu soyouresed)oured-worOUTy Pros :smo}]0J Se paxepap JB umnjas Jou Op yyy suoOUNY 303 odky fo ue sougtoads 31 eq odky wyep PIOA INOge MOLY Nok (gu muy ‘yu au) = 38H] OUNCE 6 uns - uorouny ou jo owe + qur-odxy wines # ‘ose (a jun “Tu urns yur oy] 1 pron dpfoads pInous -adojosd qeip uornouny & ‘STULL ‘one 1. e wmmyas 101 SOP sonea jo 198 dl st ony’ suanyas at sv past Sf PUP stp quounare woroUny auf) JO OWE a odAy mimes « sured Sumoyjoy arp sey adatoyoxd wonouy & “Burop st} MOY pure Suiop st uonouny oyp Tey mesford oxp s][or osfe wip uorETEpOAp & St UORIUYEP & seoroys Tresfoad axp oy oureu (uorroury) @ soonpou! WORee|99P V uormuryep ® pure uoTTexE|ep USDA souoreggp aup ou} TOK OU) ou St SUL “SUISSTUL st OpOD SH 91 Apog ou sey 3 romp 1420x9 uonmyap uoRsuTy @ O11 ysnf syoo] uorere|99p adAjoyord ay, ‘sonpea wmyos JO addy ou pur sqoumndire Jo ad4y pure soquin ox se YORS SITEIOP Surat 4q soptdusoo amp 07 eowysoqur woHSUTY soquosop adoyoud uonaury y “wonouny +0 Jo oumgeay [yas AoA auo s} Surddyoyod uorouny :suy, “BurdAyoyoxd jo apAys juasaypup op oqu9sed ‘Ol (o107) -ourey YOVLS amp SumedoITE 99 TH 18 uowp outjur asm quop 9% Jf pue apoo Jo Sout Jo soquinu oup oseosoUL Aoso gen oat J] og wrestosd yp somnooxa pue o10uf1 Opo9 ou SoMa Ajduuys 11 "uoHOUTY Te) reo 0 ‘oxouoyps ¥o0I9 9p09 eM saoedox Kuo Jo]}w09 sno-ouryur Buysn yoge Sump penyoe ovp surerds? siu-Tfeo worouny ou are axayp asneoog ourexy LIOWDUE YOYLS ¥ a1ed9ITe (aopiduroo ou A128) jou [JHA OM OUTTUL BSN OA JE ING “POIEDIO SI ADV.LS OM UOU 49A0 St uornooxa uonouny amp HH" pur YOVLS Ay} UO poroys st |[eD woROUNY a4) LOY} pojyed SI UoNOUNY JeLULIOW yTTOHIUM TEGHION u :suV (102) “worouny [eUtON 6) “ureaBoad oy} JO [019UOD dU 49) rere pun you ose yor peusar? fq paSuryp 0g ues onjea s yoofgo onejoa y “algo aynejoa v > (OE ‘Sz ‘gy “oI)uMs >> rn09 “PU >> (Sz ‘St “OL)uMMs 5 rn09 “P49 >> (C1 “OI wns > ros } Qureur qu { 042 4464x) umar 3 “Aur x quy)ums yur (=a qr ‘g=z au ‘Stuoumase y 40 swiownfize ¢ 10 swuounie zy Sa Heo ‘stwsumnsize yneJOp ya uonOUNy yyy | | {pis oaedsoweu Suysn Oo} post swrowmdse Du U9dAVIOq sUOISIOAUOS luvo Joqidutod oxp “saddvoyord Jo sn aup Jo asnweaog es pt FAD UY SOUMOTORT WOTUNY Jo SeETTEAPY 0 “+49 wr sodAjojoad wonouny yo soteyuwapy 11 102) : a Suscoye “Yu suo) 98 uo nny OTH ONCE SUuSorg-pamUusry TIO Scanned with CamScanner (1 0Y'9 woUFH TWoUPaxe ye, “hl e=td yoy, ¥8uo9 Scanned with CamScanner apnjou4 (gf run pape fase} (quay Pie payout OI a ‘pis soudsoweu sus ule 9pm ‘2 st wd isyuaUUNS.av yuyap YI aie “Sida Wy WOME WNKOp JO Ise wy AyMBGuT oqe 9aEHHM #) oo WiLU LATOR POT ‘ ‘Quon Furpoy Jo varyU,>>IN0D {(q{)eore=ajnsox ‘q<>1N0D ‘Ipua>>ynsai>>,, :9joa1g Jo vasyuy,>>Imoo {(a)eoreynsox ‘ecu S.A :9]OuI- Jo smipey xp sou, >>3n0o ‘pua>>ynsor>>,, :o/3uey] Jo varyuy,>>1n09 ‘(y'q‘¢'9)eare=ynsox H<>In09" {Quosi9 Qureut proa { sre wmyaa Sqsise “ae qo, } (q yoy" 1woy)vose Loy. 4 “ze uimjoy Saytgtdare ue oy } (qwoy)eare woy { ue wangor SU gQytiare ue yoy. y. aa eoee nt) wlan ae SETH ON SR ——— Scanned with CamScanner “€107) “61 (oroz'e| ssv[9 Jampoue Jo uonouny z9quiow oy aprsuy Ssup) 9UIus JO UONIUNY sz9quiaW ay) apIsuy wea3oad ureurayy apisuy (o10z*¢10Z) ‘81 uOHIUNY JIQUIDUI PUL sAdquIoUI "WEP Burssazov jo wistuvyoour ay) aquasag+y1 (6102) ‘wea8oad ajquyns & YM aomsue anok Aynsnl UOHIUNJ. pudiay Zuysn jo asea ur papaau st UOHeIEPeP PavAioy, OL (110Z) gsuoyouny AIQUIIUT ¥ Jo soSL19}IvIBYD 9y} ae JEU ‘sy (1102) wonsuny puaty Jo yoequerg +} (0207) uonouny puaray Buisn Jo sodejueape SIP puv sodejuvape ay} UMOp OM “gy (€10z)pauyop aq ues uoHUNy Pua Moy JUaUIsas apoo afquyins YA MoYg {uORDUNY pudtyy st Ey AA “ZT (o0z‘e10z‘st0z*L10z) guonauny PUSLY E Se MoHDUNY v aa¥Pap NOX op UaYyAA ZUOHIUTY Puaray st yey AA “TT (O10Z) ‘ardurexa yy ureldxg Z914W0)s sep & yo. daquiow ¥ a8 ap Nod way Ad “OT (o1oz‘t10z) ‘ojdurexa yas ureydxg ESSBID [BIO] SIIVYAL *6 (o10z) “Pafqo pur ssuja usaayaq uoNLpY °g (Ztoz‘broz‘st0z) “uonssod anog paynsnt ., Ayrxajduro aonpoa uonynsdesug,, *L (o10z*P10z‘z10z) “Palgo 20y uoHLaoTe Lows °9 / (9107) . “SS¥p ¥ Jo aquiaw p2}99}0.1d pus ayearid 0} ssao0" Avy WED Jey) UOHSUNy SNOLIBA dy} aau WeYAA “S (9102) “SSUPD ¥ JO UONIUNY zaquiau oyu, 14d ssaaa¥.0} MOH. “b (r10z‘s10z) . “ePaWw—ID Kom Moy SE 2alqo srqeyAy “f (LL0z‘st0z) “SuIpLY ve poysyduosse SS¥[D v Soop MOH 7 (T10zS10z) éssup v staUyAA ‘T TORSTAD sy9fqO pue ssej5 Scanned with CamScanner Page Nod AMO. oo ccc coece eeeennnnnenesee eee ene neeene een Object Oriented. Programming 17. Write a program classes using friend function, (2018,2015) 18. Write a class to represent time that includes the member function to perform the following: - Take input for time in hours and minutes - Multiply time by scalar value - Add two times - Display the time in form. hours : minutes (2010) 20. Write a C++ program that introduces the use of static data member and member function. (2013,2010) 21. Define Static data member.(2020) ~~ 22, Mention the properties of Static data member (2029) Scanned with CamScanner object Oriented Programming, Class and Objects [What is a class? (2015,2011) “Ans: . . ‘ Class: A class is a way to bind that data and it's associated functions together. It allows‘the data fand functions) to be hidden,if necessary from external use. It is a user defined data type, which holds its own data members and member functions, which can be accessed and used by creating, aninstance of that class. A class is like a blueprint for an object. For Example: Consider the Class of Cars. There may be many cars with different names and brand but all of them will share some common properties like all of them will have 4 wheels, Speed Limit, Mileage range etc. So here, Car is the class and wheels, speed limits, mileage aré their properties keyword user-defined name lads Classtiam { Access specifier: Jean be private public or protected Data members; 1/ Variables to be used Memberfunctions() (} //Methods to access data members J{ Class name ends with a semicolon 3. How does a class accomplished data hiding. (2015,2011) Ans: " Itis a process of combining data and functions into a single unit..This is the central idea of OOP. Usually, the data within a class is private & the functions-are public The data is hidden (in OOP data is given more importance than function as data is the reason for program's existence) so that it will be safe from accidental manipulation Example: We go’a bank & access the staff rather than the computers and files over there. The bank staff knows hiow to access those Computers and files. Data Data hiding::- 'tmeans that data is concealed (masked) within a class so that it canni Outside the class even by mistake. ‘The mechanism used to hide data is it private . ot be accessed by functions to put it ina class & make Scanned with CamScanner NT Page.Ni Example of Data hiding in C++ #include using namespace std; class MyRank{. , int a; //dofault accessibility is private public void read(); void print(); }: void MyRank :: read(){ cout<<"Enter any Integer value"<>a; } void MyRank :: print(){ cout<<"The value is "< class student private: intrn; float fees; void readQ. TN=12; Sees=145.10; void show() readQ; cout<<"\n Rollno = "<) ‘Ans: Once a class is defined, it cai relation between an object and a class is the same as that of The syntax for declaring an object is class_name = object_list; To understand the concept of instantiation, consider this example. n be used to create variables of its type known as objects, Thy ‘a variable and its data type. Example : Declaring objects of a class class book ’ { I body of the class , hy » . int main () i { ‘book bookl, book2, book3; //objects of class book return 0; } . In this example, three objects namely, book1, book2 and book3 of the class book have been created in main (). . . book bookl, book2, book3; // declaration of objects } 4 Memory Allocati in for Objects Before using a member of a class, it is necessary to allocate the required memory space to that member, The way the memory space for data members and member functions is allocated is aa regardless of the fact that both data members and member functions belong to the same i memory space is allocated to the data members of a class only when an object of the classis declare, andi not when the data members are declared inside the class. Since a single da the chee ron have different values for different objects at the same time, every object declared fo" class has an individual copy of all the data members, | On the other hand, the me — class is defined Tie Emory space for the member functions is allocated ‘only once when the shared among all the object the class book have individ one copy of the member fu ] ‘ords, there is only a single copy of each member function, which s. For instance, the three objects, namely, book1, book2 and book3 ©! lual copies of the data members title and price, However, there is oY inctions getdata () and putdata () that is shared by all the three objec!S 8.”Encapsulation reduce com, Ans: . cela reat um He * Encapsulation is binding the code and data together? (orate, public and comp! a ly ki @ class. Encapsulation has less to do with access spool OF profane itd Protected) In encapsulation members inside a class can be private, P!! ‘ted. The private members of a class are only accessible to the objects ofthat class &” plexity” justified your position, (2018,2014,2012) Scanned with CamScanner i and the public members are accessible to the objects of the class as well as they are accessible from outside the class. Encapsulation helps the end user of a system to learn what to do with the gystem instead of how it must do, Let us understand encapsulation with the help of an example of a car. Ifa driver of a car wants to change the gear of car, what he needs is to just change the position of the liver operating gears of the car and it thus changes the gear of a car. A driver docs not need to understand the complexity of, what is the mechanism behind changing the gear. This is how cncapsulation reduces the complexity ofa system. Encapsulation makes the system easier to operate by the end user. d:Relation between class and object. (2010) ‘Ans: *, Class is mere a blueprint or a template. No storage is assigned when we define a class. Objects are instances of class, which holds the data variables declared in class and the member functions work on these-class objects Each object has different data variables. Objects are initialised using ‘special class functions called Constructors. Class is a container which collection of variables and methods.object is a instance of class.One class definition should cxist only once in the program. For one class multiple objects can be created. #include BL class Employee t public: int salary //-data member cout<<"Enter salary: "; i cin>>salary; cout<<"Salary: "<opnypuyy ‘ dy puv 10 suoneseppap ‘wresSoxd areas ur peyeaus yng ‘(ung ur prea ome 999 Surmoyjoy oup ut ‘opdurexo a es Sujsojouo oy} Ut posn 9q Sjuo ue oureu Od} ssvjo [U0], “(jung ur sseyo B09) v sf 9804, ‘uresosd Huyoyfoy a4p wt “oydueNd JO “++ 094 OHSU W apISU PasL Np SLID V porje2 st pue uonauny ye1p OF fed9I SoUOd9 HOHUTY v 9p! epee suy “opdurexo yin uid gSsep> [e90] SHIEUAN OT OPT HE ON Re UL ssvjZ [LOOT C (o1oz‘t107) SureraBory porwsniey 9911" Scanned with CamScanner C ss 4(s oyduies) ueowt yoy puouy Cop=a ‘sz="} () anzeatas pion conqnd ‘au “equ } ajduws ssejg : puaiy :MoYaUNY PUdLy Jo woHEAE|I0q “uoroury ayy Jo adXjojord amp Jo uo Ur Promax puony dtp asn ATduns ‘uonouny PUDLY v orv[0p OJ “SsuD JoMPOUR Jo oquioW v aq JOU AeuI JO AUT MONOUNY pudLy y “oHoUTy yeuuoU v oy] Isnf st UONOUNY pudty ou} ‘spreBor JMO |[e UT "ssEID JY Jo JOQuIoUE B ODM JT YON Se ssvjo ¥ Jo sioquiowt areatsd amp ssaooe ues ey MONOUTY & st UONOUTY pusLy y :uOHIUNy pudLay ssuy (102) Epeuyap 3q Wed LOR IUNY PUdLy Moy JuaUIas apod eIqQuIINS YIM MOYS UONDUNY pUdLy st IyAA'ET “pasinbax sr wonsuny puony & sown yons uy ‘awn eye paresado 9q 01 poou Seu yorym stoquioUL PorejauiotU UTEIUOD AEH S9SSE[D O10 16 OAN} SOUINDUOS sp ‘z91Se9 SuoHOUTY Q/I JO Sad} oWOS Jo UOHTRaID oY sayeUE uonoury pus Ingosn oq wes suonoUny puoty pasnbar si Supeopidao soyesado ureys99 UDA, ‘WOHOUNY PUdLIJ & Se UONDUNY B azeJOOp OA OP UOILA\ 5G Inqey) Aejdsrp pron puory ayduexa, ‘@goureu ssejo)puoty tuonsuny puaiy yo uorEsEp>C woRoUny amp Jo odAvoyosd dtp Jo OIy UI proALsoy puto, B-Oleppop OY, “SSeI9 JoMJOUR Jo JoquIOW ¥ oq JOU ALLL 10 Ke B ogy] asnf st wonouny puotsy oun ‘sprees JOMIO [Te Uy “su Sssbjo v Jo Suoquious oWeaLud ou) s8999e ED Ye LONOUTY v Ly OY} On Ayduns ‘uonoury pur WW UONSUTY Pusu y ‘uonouny peUHoU 19 WMP Jo soquiow v axon 4 ysnowp S, St wonouny puowy YrTaRTUM PA suv (0107'€107'S107'L102) ee [____dwonauny puis vse uonbuny e aamDOp Nas Op way uonouny puaray st wud ‘Zh 010 Tet FONE an ~~ sunuUMRATOTy pI Scanned with CamScanner Ssoquioul s}t ur WisTqdrouIA[Od oun unu Aue op youueg “ssaquiout pusty JO 9ziS 0} Sulpsoooe syoafqo Aq patdnoso aq J}1m Arowowi Jo ozIs winwixeyy “p ‘Sasse[o yooaviog Arepunog ayy Appnuw spuoiy snosownu jr uonenyis 2poo-inayseds oF sa € Asso Ayjenjdasuog °% AquBaqur vyep Jo yoeaig *] . “SUIPIY yep Jo Mey ayy saqejora yoryas SSe[O SY BPISIN WOY sse[o v Jo siaquIaW oIBALId OF ss90de @ARY UOHOUNY puaLy woRaUNY puatay Jo syvqMBAp ay “10}e10d0: papeoj1oAo Jo AjI[IBSIOA aSBAIOU! OF pasn aq UeD “ssejo B Jo ped ayeauid ay} 10 o1gnd ay} Ul JoysIe pasejoap aq ueD *S s(umnu)aaenbs wey) sno1ago ss9] st {(Jaaenbs-umnu ajdurexa 104 TOHOUTY TOGUIOW uey} soyyes uOHOUTY B Buje 10y xEWUAS SMOJAGE aJOW B SMO|LY “h . “SSEIT SUT SUNY Jo poou inoyywm ssaquiaw! ssadde 01 21GV “€ pUdLY GIU! UOLIOUTY B axBUE 0} SsEIO BY} 40y POD BOINOS 0} ssod0E BABY IST “Z seyep 10 Sunjerodo Aq sassejd OMI usemseq aSpiq se yoB uoKOUTY puoHy “TL, 1 uoHouny pudtay Jo syst ay :xOMSHY Ss ayeand sayy Ue [ (0z0z) uonsuny pudzy Bussn Jo sadeuKApE SIP pur SaU}UBAPE OY} UMOP ILIA pT { :Q wimax Sun, >>(X) UOBUD>>,=ONTBA UEDA, >>I UeD HONOUTY JoqUIOW y < “wOHOUNY PudHY B St-o[nU StU 0} UONdaoxd Ue “IOADNOH ‘OS op you ueo tonoury Joquiow-uoU Y “ssvj9 oY) Jo ByEp ayeALAd o1p Ssoooe WED YOHDUNY JOqUIIW < adoas s10qf \ Joqe] diyssoquiow oy] “oureu woNoUNy dures oY} OSM UD SoSsEIO UOIOYIP [BOATS < rare sonsuajoereyo osoyy, “wourdojaaap wesdoid & UL osn UdYO ae Jey) SoNsUOoBIEYD [eIOOds oWIOs savy UOKOUNY JoqUIOU! OL ssuy ajosor (102) gsuonouny soquour e yo sopsLiaavaEYD ay) OIE EUAN sroquiou s}t rydiow. class b; class a { int x; public: void assign(int t) £ Scanned with CamScanner } void display() { cout<<“value of x is: “<>a ; cout<<“Enter y ="; cin>>b; nassign(a); m.assign(b); ~ Scanned with CamScanner 13.sum(T1,T2); is cout<<"T] = >: TL puttime( ); cout<<"T] = >; Ti puttime(); cout<<"T2 = T2.puttime( ); cout<<"T3 = ». T3.sumtime( ); return 0; } foi. Write a CH Program that introduces the use of static . data member and member. function. (2013,2010) Finclude class stat { int code; static int count; | . y public: stat) { code = ++count; void showcode() { cout << "\n\tObject number is :" << code; } static void showcount() { cout << "\n\tCount Objects :" << count; } hy int Stat::count; Scanned with CamScanner “Qdstp pion {(s0urysiq)ppe ooueisiq { Sut=sayout {y—3995 } (Ur qeoy “y 11)sipras proa ‘onjgnd ‘soyout yoy ‘Syoy aU coeaud } doueisiq] seo apnyouty C'7Z Z st saquiny, 199{4Q, Z:s199[4Q wnoD ] ssi soquiny, 390199, A Z:s120[qQ wnoD ynding ajdureg { ‘Quod {Qepoomoys'zfqo :Qqunosmoys'ziqo :Qopoomoys"[ {qo sQqunoamoys"T {qo >1109 SOdsip'zp:,, = z souristp 1,>>109 ‘Odstp ‘1p’, = 1 20ueIsIp u,>>1n09 “(cP)ppe [p=ep “(¢'s‘€z)istpias'zp AULODIsIpias Tp SEP ‘ZP' IP soursiq, } Qureur am w>PSOYIUT>> ,,,\,>>}OY>>INOD Sumi ard + pyH+ WY ‘ 1 Set99yt S0'71=soyoury a } (O71= OM) BARK OAL “TT spatgo ad4y ywoy om Ajdyjnut puw aprarp* «os Sots PROLOAO 09 Jey? wIVIZOAd ++ F AIAN “OT (oz0z) am pue A Jo 9alqo (1107 ‘p107‘L102) youayqnst ppe 03 ssozesado .4, PU ¢ (s10z) ‘uonouny () + 40yvaado uv Suisn soywsado + 949 spuojioao yyy wEsBosd BAM “6 (p10) +449 ul << pur 5> soyesodo ay} jo Suruvaw ajdnnu ayy urejdxg °S (1102) ‘Burpeojs9a0 s0ye.1ado 105 sajna ayy aquiaseqd. “L (610) ‘vonsuny soyesado puarsy 7p UOIUNY A0WvIVdo JoquiayA UddMJaq BdUBIaIG “D (9102) Ay uredxg “s0pesado ,=;, pvoj1940 0} pasn aq youues uoy>uNy pully Vy“ (0102) 21dwwx9 aa1y {Asosindutos uorouny puowy v st UOYAA ‘ s ’ (L102) ‘vonauny 10yv10do uv jo xuquds ayy aquased “*f (L102) ZuoHIUNy aoyesado sizeyAA “Z (0102 ‘2107 ‘8102)¢3uypeoj1aA0 soyesado si eYAL “| wonsNnd Scanned with CamScanner . Object. Qriented Programming Page No #158... a Chapter: 5 Operator overloading | —) bles of user defined types with the same that C++ has the ability to provide the ‘anism of giving such special meaning vides a flexible option 1)_ What is operator ‘overloading? (2018, 2017, 2010) Ans: Operator overloading: C++ perm syntax that is applied to the basic F ie a data type. The mech: operators with a special meaning fo y to an operator is known as operator overloading. Operator overloading pro’ for the creation of new definition for most of the C++ operators. nits to add two varial ic type. This means 2) What is operator function? (2017) | ‘Ans: Operator function: An overloaded operator is called an operator function. You declare an ‘operator function with the keyword operator preceding the operator. Overloaded operators are distinct from overloaded functions, but like. overloaded functions, they arc distinguished by the number and types of operands used with the operator. 2017) | 3) Describe the syntax of an operator function. ‘Ans: To define an additional task to an operator, we must specify what it means in relation to the class. to which the operator is applied. This. is done with the help of special function, called operator function, which describes the task. ; : The general form of an operator function is: return-type ‘class name:: operator op(argument_list) { } Where retum- type is the type of value returned be the specified operation and op is the operator being overloaded. Operator functions must be cither member functions or friend functions. Function body; 4 When is a friend function compulsory? Give example. oi ns: Friend functions may be used in the place of member functions for overloading a binary opera The only difference being that a friend function requires two arguments to be explicitly passed" it, while a member function requires only one. : In most cases, wwe will get the same results by the use of either a friend function or a meme finetion. But there are certain situations where we should like to use a friend function rather i member function, For instance conéider a situation where we need to use two different typ? Q ; . toe for a binary operator,say one an object and another a build-in- type data as show® A=B+ 2; (or A= B*2) Scanned with CamScanner obiest Orier yore A and ent TB; (or A= 24B) wil not work. This is because the left hand operand, which is responsible for invoking the snomber function, should be an object of the same class. However friend function allows both approaches. An object need not be used to invoke a friend function but can be passed as uments. This , we can use a friend function with a built-in type data as the left operand and an amet as the right hand operand, sample program to introduce when friend function is compulsory: jinclude class coord : int x,y; public: coord() { X= 0; y=0; } coord(int i, int j) { Xe yj friend coord operator +(int i, coord ob); display () { } hi coord operator+(int i, coord ob) { cout<> oywI9do BIYs YoT om ‘og “pou podde USIIAN ‘PaSn axe Ao yoruaN ut yxoquoo 3qf Uo pus sq youtea 798 JOyeIOdo sy ysnoipjy, ‘Q1QIPUDIXO St II JEM SI ge 9pn]>Ul JOU Soop oBenSuyy +49, SUL "popraoad st em Opor 99 ueo-Suruvaur 9M) s}oafgo A190} dap sioreiedo Jo sSunmeaut axp “paseazout 1 S\dadu09 a109 SHJO auo Inq ‘waysks O/T qeBopo o10u! v os OSOQIOA SI DAOgE OY ‘<< PUE >> SuipeopsaAG, ssuy [ire OUI << pue s> soywsedo ayy Jo Suuvanr adyinu ogy uridxy (8 ] anyea Y winto1 apnjauiy :suy (102) suo ouny () + 201Wiado ue Suisn 10jeIAd0 4 94) SPEO]IOAO Jey) WeAdOAd & LMA © pure Ze st p>>T oS -okky pousis sit jt (ui ou oAsosoud 01) 11g doy amp spuorxo so ‘od pougisun we st onpea Jt ‘sq ONO SppE pure YSU sys << + uo YL o4p Te SOsOz Sppe pure Yo] SYIYS >> * ~AyStx arayp Uo Sug Jo soquinu aMp Aq Yo] s1oYp Uo onywA om YTYS osuaAyLG ssOVEIOdO YIYS LL ssoyesedQ Y!S wechecx> B Jo ozIS puey Yo} OWN se UTEHe posn oq ueO onyeA sryp’ uTeaNS 1ndINO uv st yey} onze v soonposd uorssoidxo amp pu o}quuvA Pury IYSH oMp Ind;no o1 sueons indur west juownSse pucy yor sw woys uoNaUTY yd oy} oq 01 papeoparc us9q ‘ class FLOAT { float data; PP public: FLOATOQ; FLOAT (float d) f { data=d;} FLOAT operator+(FLOAT fl); FLOAT operator-(FLOAT £2); FLOAT operator*(FLOAT £3); FLOAT operator/(FLOAT f4); void display(); b FLOAT FLOAT::operator+(FLOAT f1) { FLOAT temp; temp.data=data+l data; return (temp); } FLOAT FLOAT: operator-(FLOAT £2) { FLOAT temp; temp.data=data-f2. data; Scanned with CamScanner Object Oriented Programmii return temp; } FLOAT FLOAT::operator*(FLOAT £3) { FLOAT temp; temp.data=data*f3.data; return temp; } FLOAT FLOAT::operator/(FLOAT f4) FLOAT temp; -temp.data=data/f4.data; return (temp); } yoid FLOAT: display() cout<) weMsuy (0707)<4eM pue ++5 ut papeopiado aq youuts aojesodo Woy “ZI Sok Sains algo ursaing wojawey iy (ssep uogeonssq) | ax apy woe jenaniy sopuy opens ssrooe mea ed aD xe (sxpz203) aq uojinasor, ons sonata 8enst ASD sop met On he “SSe|9 DD4NOs dy} UI aq PINOYS UONSUTY LOIS9AUOD aU pu SSE UONEUNSAP oy UL Posn aq P[NoYs JOJONIYSUOD ‘aJOH{ “UONDUTY UOISIOAUOD v JO JOIONSUOD v JOyWO 4g INO POLLS 2q ued sasse[o quoIEBIP JO so9lqo wooAXI9q UOISIOAUCD YONG “sse{o UORLUNSD oy] SC UNOUY SIX pue ssvjo aounos ay} Se UMOUY st A “X SSEID 01 A SSEID WoY adz[d oxe) YOISIOAUOD OY], B OY) 0} paudisse st onjea payaauoo om pur wep odAs x SSEj9 DUP} 0} POUDAUOD st Hep adi A sepa OULL “A SSID Jo 199/qO UE SI q pu X Jo JDO{qO UL SI v OJZYAA * SOSSEID OMNI OUL A PUL X 19H} isuy. (9102) Zaid PUL pasn oq pjnoys auNNOs UOISIBAUOD Jo 2dA} JEYAA !qQ=e Aus OF [wea om pure A Jo Algo uv st q puc x Jo 39aLqo WES} m JL” A PUL X SPSSEID OM} DALY DAA “TT TSP908'0 =CA/ Id See = Tdeld 90° = tal oS = : Td+ld Ve = td st ’ a ld Soomesorg para Etq9 iar ort Scanned with CamScanner a $q 01 paxsayar yo0fgo ue 10 * Sutpeoporo jus} uoneiodo ue sayIAyN Moge stioHsonb oF ped] Uwe Os RuLOP “roxdMopy abuinjaa? ous otf) HuIsN opeoyioso aq ajdiound wi pynos (op) ~roresode apolqo up 40} pouyap-sasn JO} ysOM ssoe19dO oxBUI UES OM +4 UL 449 ur Surpeo]s949 s0;es9dQ) YOUN AST] “UOISIOAUOD PILPURIS IP YSronp yoreu v puyy OFSIN ++9<+ :punof youu ou ff aiqnop 01 paroword st 10] 4<- “yur ue 0} pojourosd ose woYs pur “eyo pousisup eYD<- —punof st yorou jooxa tou eff + (aoqoweseg pur oweu uoNoUN,y) -:yo;Du JoDXY* 910K Bupeopinag uoNIUNg AOL sod Jo 9dwexo uv se posspisuos 9q eo Suypeoyor© wonsun TUOLQIP SupeoyoAg wonsung UL oumyeoy wsiyduout +H % pinoys suonunsie oyy pue owes a4 9q PIMO|S oUuLM_,orIOUNY., Loqyip pes papeoy10x0 Suspeoysoag worst, paypes st 4 sqor wt. 1 outeuworoUty B HOA suorourvred yuoxoyytp 1g ouUU oUrES ay OxvY LED Svoupuny azou 40 ov axo4sn Suumuesosd ponsows0 120/go Jo cumeay e st Huyprojoro worsung : . 449 uy Sugpzop294 woyouny LOMsUY Ao wOHoUNy UIEdXY “CT l (0z0z) -ajdurexo yp Suppwop10.40 Joywsodo pur ‘Supe Tap go “OST ONAL Swtocaasorg pamuBTey 189140) Scanned with CamScanner (1102) “pefqo jeaor pare peqors w30q Suen aydurexa ue yyy unoydxg.“199fqo 940 UH 270uH aywas9 puv soyonysuos ayp aouanbos 7eqm WT “ST ws80rd 49 BUM “FT up aa¥ SUOTIIUTY 10797959P nod way PAU auias WoouUogly ayesauas 09 Ur eaojonajsuoa doa Busts (1102) (o10z ‘z102) szoyanaysuon Adoo Suysn uresdoad adUys HM ET (L102) jrojonaysuos wound yynejap Aq WEI nok op yum “ZT szojonaysuo 31NB90 “TT (L102) suoa doo Jo asn ¢, soyonsysuoa Adoo st7eHAN “OT (e102) -adurexa yy 40 { <()atdwres 91qn0p soyqnd so'q'e a1qnop Jordures ssei) (0100 gquamvay Suysoytoy auf UY UMoys 2O}IN2}SUOD OH TE Buom sie 6 (otoz't10z‘L102) jAonaysep pus soronsuo> w39M424 aur “8 (ptoz) gssujp ¥ yo sojanaysuod v asn 0} AxoyepuEUT HST “L (pt0z‘s102) -uonouny soyonaqsuos Jo sonstsa}aBsEyD Wye 243 UMOP HAL D (stoz‘L102) gpapeopisa0 zojanaysuos si MOH 'S (9102) gamooxa a2e s0yINIySap puL soJNAysuOD UY nea +s0)N143Sap PUB 40yINI}SUOD Jo sans9dord 94} UALOP SIAL € (e107 ‘S107 ‘9107'8102'0Z02) : : (o10z ‘eL0z'F107'S10z ‘ 9107 “gtov‘0z0z) i remand G40}9N.138U09 St IBY AL tT toRsend voruny 1079n.1s9q puy. toyon.aysu0 guaydey) — ~~ marmaRTOTy parE BIO Scanned with CamScanner

You might also like