0% found this document useful (0 votes)
23 views30 pages

OOP Practical

The document discusses key concepts of object-oriented programming (OOP) including abstraction, encapsulation, inheritance, and polymorphism. It contrasts OOP with procedural programming, highlighting the benefits of modularity, reusability, and ease of maintenance. Examples and definitions illustrate how these principles are implemented in programming languages like C++.

Uploaded by

badalraj304
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)
23 views30 pages

OOP Practical

The document discusses key concepts of object-oriented programming (OOP) including abstraction, encapsulation, inheritance, and polymorphism. It contrasts OOP with procedural programming, highlighting the benefits of modularity, reusability, and ease of maintenance. Examples and definitions illustrate how these principles are implemented in programming languages like C++.

Uploaded by

badalraj304
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/ 30
— ——————_ = NO. ssn 7 | = Introduction ‘tr 00? —_ 2) What is 00°? »—— Obyect _owiented p20, caning is pipiens pong | hort veh ager Ceo teScten! teal -untld onli. | Each obgect ‘onting: + fittibute (mote): Represent the obzecl’s _propendties. _| * Methods | Funchons): deine -the behavior ox operations of | le Wyma Haig ae oe muliple foams | —Leg- method overlosding)-— oe ns [ a Teacher's Signature Date sesescsssseeeeemsssssssee Expt. No. Page No. .. fa bean _of opp over procedural Programa ee What is procedural Prog caring yo Procedural programming oxganizes code_into “pia cecutes os | —-/ Functions, Z:focuses ona _step_by— step execution model _| ;—-and__does not __inheviten}y— _suppott concept like obyecks, | L inheritance oy —encapgu ation "1 eee ert: 3) Diffoulky 1 Systems. As system grou, — Ce camming } \ a »_ste__mainmtain_and_debieg. | Low Reusabil >) Modularity and_Reusability ee a | Ease of Maintenance _ Beal - world _Scalab) — a | {Expt No. Page No. .... 3! | Comparison with sunctional Srogramring ee _Functianal Frogeamming._ isa frogee ming — paradigm eat — , breats computation Functions. Te _avaids changin g. chet andmutthle dade Gp —irametalty-—ana— pate function —___ Key _ siBsetence between po and FP 00? FP > Objects Tepreserrt entitien with state jo>-function are ahe_geimary building | | Lattnbite) and _behavios (nethads) | blocks , and -facusison whet is one | Compute than how. | [1 ®/ gata and methods are encapsulated 8) e+ is immutable and function! | n._obgecs | tvonsfon lad, E S| tonne ings th ragh_|© Rvoids mutable stele and side | | tbserts. effects | D) Qrckieved via ‘wheritence and | 4) Achieved via highes-ovdesf _| — falginet phism $$ ___| functions and closures. . ct, Sava Hyer style), Date... Page No. - nate Composition omusch on iivzauing! Pees smallex, —__| “manageable pieces and applying operations idependently on | | each _.this paradigm. is common ia procedural programming | /-ond___parvattel computing. | key difference _lnetween _90P and Seta Sexom position. —__| —-}——— | oo? gala Composition Para digi | D> _dbyect represent entities anc | deta ig split Into Smalies units | | Yiag. c seve, Python | l | Teacher's Signature Expt. No. 2 Core _O0P concepts = D Abstraction. :- Abstraction is we process of — implemen-tarton _deails _ ae_shossing onl Wy _ the essential -feartures__of an__obyect It focuses an ~ _| What an _obyec dock _tathest__+than how it _doeg its __| — Limportance_o_abstracHon. * Simplifies__complen ss ystons by breaking them inka oe a _ Protec users. — SS unit Taleo westits direct attess to some_comspanents| ene sing access — apec:Siis tke, pstaas,—pinkcch_and_ a aa fs {| “bse cases of encapsulation a “| ata Protection'~ Sensitive data can be hidden and | accessed only through public. metho: tb Ensures a —_clears__separation of cong, = Teacher's Signature __ Abstract class Example: Class Shage & Public : | virtual void ‘drawl) = 0; II pure Virtua) function | io) Class Civcle + public shape & pubic : void draw) ovestide { cout A Marawing Ciscle® {¢ endl; 4 Bb Encapsulation Example Class Bank Account £ Private : double balances public + void deposit ( double amount) £ balance +> amount + 3 double. getBalance Of Yetwsn balan ey 4; Date .. Page No. re _is inheritance 2 a __ | Tnheritance allows a class. -to_inherrt properties and [ehaviors from another class Tt promotes code reuse | and enables hierarchical classification, ; — Tye a “anberictance. ale single “TWheritance One child inherit fmm_one_gatent | 2 | “Multi ple Tmbevitonce: A chi Id_ inherit from multiple parents, rid Inheritance’ Amik of _ tine _abbave_-bypes _ 4 isi 5 ism_means, * many Using namespace Std) ‘nt maind) & nt ¥ptr = new ine Lio) 5 cout K" Value: "Ae pte endl) delete prs y se+Usn, 0) Expt, No *% UNITI: Classes and objects. 2 Encopsulation and index motion_tniding * Encapsulation != “Tk 19 the process of oundli a and methods that operate onthe _clata_intn_a_single =| unit called a class. Encapsulation ensues hak: _| [+ ala ig hidden from diteck access | thfarmadion hiding] | * . = 4 Access is combialled -Ynraugh__public_methods (getters. ave Seti) _* Howw__Ence« 10h__ensutes infoxmation hidin Teacher's Signature Ex- 4tinclude Alostream) using namespace std, Class Bank Account { private: double balance; public: Rank Accourrt (double inttBal) + balance Unite Bal) 53 | Yoid deposi (double amount) © VF Lamount > 0) & balance += amount. vy ¥ ¥ void withdraw (double amount) & iflamount yp 44 amount 2= bal ance) £ balance -= amount: > 7 2 double. Jerbalance OL Betutn balance, a 7 ink mainly © Bank Account “account | S000) 5 accountdeposit 1900 aCoountwi. an a cout 44" Current Balance’ 4 account.get Balance); weduyn 0, es —J | | Expt. NO. cscs Page No. soot Ques 2) Abstract Sata_ Ty pes Ad Ts) | fin, abstract data -yps—is_a_mathemelical model ft | | dada ype where “only the behavior _is defined, | __| net _te _implemenrkation. Ass promotes _________| _t E Medalarity! Separation _of_interface and implementation. _ Ls Reusabilit} canbe used _—accass various —_conber’s [| without “wortying aboot implementation details —__ |_| Examples of. AgTs in crt I nt Stack { Li-fo) ‘ © perations ps | —| + “Linple men-}ation eam we fy Queue LF rF0) : * Operation: enqueue, deque, peek Teacher's Signature | -FFInclude Liost team +#include A vectors using name space std; class gtack ¢ Privates * Vectos dintS elements , public; Vold push Lint yalue) ¢ Clements. push back Walue); 3 Void porU & LY clements.empty lJ elanents. pop —back \) ; Void top) & ie element empty Oye setury elements-bacts LI; Betuin -J) 7 fooo| ty Empty © Bern elements. emply Dy «| What aie —_obyects 2 | An __¢ Object_—is_an._instance of a class. Tt re presents a | — fea) = wo#\d entity _1idin the following characteristics, | ~_ [+ pttibutes:— Represent the properties af the ebyecd | ls Methnds: wefine the behavios of the chyect | whe te a clase? A clots i. blue paint fort creating —_fhyecds. Tk wi -defines the atttibutes and methods -thad its | Obsecds __ Jill __have. | Dbyerts voncepts : skate, “Tdentidy and Behaving $+ || Stwte i= The __stete of an. object is _tepresented by athe | value’ cf ids _ecttfibuteS oct a specific pint | in_Aime. + Aden Each obyeeh had a unique idlendity hich distinguishes He from __ other Obyetes. * | Behavios :~- The behaves of an object is_clefined by ids methods , which pelo _aperadion8 on is atifibile Teacher's Signature: ; [constructors _f conseteuckot isa special ype of Date .... Page No. “Gansteuctne and mete clots a ae ect _| \izeS___a3_ob- ap __a\lncade memoty and eee purpose \ 1 | ise Features. » ame name a4 the class. No Seducn fy pe. L net even_void) fiucto mertical | Types of constructors. “Defaubk Coneivuclod !- No paramelers ,inidtalize’ dbyecd with | defaub yobues. | Class studemt - public o— pe ! +8 u 0 he BochefisSgnaie © _fatameterized constructor != Takes _aigamerts tn _inWialze$ | Date... Page No. dhyets with with custom values. —_| - class 7 _ student fo privet ————-_Sifhing nam Ant ___foll_ nos public: Shademt (setfing nym) 3 name = 0} ollno= 2; % cy lar Cea: enna anon rue arE, ak. SONA eyo ansthen —_dayeth ‘lass student © SHing name 5 Syuden} Leonsh student 45) name = shames =| y 3, Teacher's Signature: Expt 7 deleted “TL (eleages te sousces Vise dynamically No. De stouco(s'~ A destwcdow is a _spe.dall_finction_ina_| class that is aur matically invoked _| When an ob yer 2 od OF Scope or is_spplicthly | _o\\osdrted Mmemofy —_—— Features : _ = ANE a, Name 5. i cae No _tedurn _ and takes _no_ fucdorn oti. cally a ed dur vag ag dercn | | pate in management (1 na Mh my Prevents of i ions. Objects _“Insanbiacion | > obyeck __tfested _in stack merry Studie _Dhyec creodion 2 fiutn maticaim destroyed then they so tuck of scape. __| ‘Yy- Cox caos ("BAW 250)* I Static objec -ayhamia 0b; pe ely a ep tRord Must be explichly ape using Signature Example: Destnuctos Atinclude Alo streams using namespace std; Class | Car & public, carl) \ Coukk” Gar obzet cresded | "keend); 4 : -ar YL cou K Cae Objet destpoged'd endl; ¥ ¥ 4; Int main LL Cav cash) ryeduon 0) > . Tnheritonce:~_ Te ig a mechanism where a _new class _ —_——datkedeatives__propentia and _b chavias “from an| —existing lag. Tt _alNaws: ee cose ety _snbeng— ath ute and methods _| Easy _maintencese hy —“Lendfalizing chan get mn the ___ pater lags. + Implementation of hietan dical—velaonships. | * esived class t- The cla wt \nherids: Imposdance nf inheritance tn 00 P _______ "| Code Reusability! Prevents duplication by reusing ne parent class code. Extensibility + New ida n a. to_chil class ea, wildhoul modify athe parent. | ietaxechical Repeesendation + ntodefs veal ssid cealétiombig fike Sis <4" eg-mo4 bsg Mowmd) feacherts signaite see seem Byrtax Example of Thheritance class Parent | Public» | \ void dlis play os i | CoubLLITHIS is the paren class | 4 endl | J i | 2 | | 3; | child child: pablic Parent £ i | paste | vord chow) L | i coud A" This is dhe hile class. "endl | { 3 i | | | 3; | | i int maint) L | H Chile c; | C- display \) | | splog 0) | show); | Sedusn 0) | = 1 | es = _| Si ingle “Inheti tence * One “child_inherit 4 rit -from_onepatens | | _class A ghey 2 | | class public @ SM. | ~ [yee oe mhetience = oo rare * ¢ yr... -. * Fy -*1;j An 3 it [nee ere a gue a St 72, 3 \dan ce! i inher aren and anodhes child _inheri+s from she Fins child — clas. pes eee ey cluss B public @ Senn 41D) cess ¢: public _{_I* ation Of mayhple and miwFilevel tnnesiaan re Teacher's Signature Hybsid inheritance » A ‘combin' | Expt NO. ssssstssnee Page No...) Fees _Detivation —“T —\n__tnhetitance —______—H4 [Finheitance aN ous__dewived classes to Loherid_members | from base classes . The aicess specifiers (public, | protected) determine the visibility ok hese inherited! | ublic_ inher >The ot the base class remain public _ | Private ‘Imheritance 1 il_publia and protected membesr_ bt the base Gloss he come _psivale | in_dhe _desived dass. Protected inheritance 1 The _public__and_prstect ec! members pf dhe base lags _| pecome protected inthe —desived clas Boss Base S || proberleg » ind R= 105 = y | ats qenived + proteted Buse§ public y wid disployd Teacher's Signature : _ a cout " yalue oF Meda Acend); | Giblic_Tnhesitance j | Closs Base © | | public | i i ink n= 10; j | #; ! { clogs Desived | public ®ase ¢ ! | publics / I void displays, | {| coud "Value of 2 Aan Arend] | a | t Pivute Inheritance Class Bose £ public : int W= 10), | a; | Class pesived + paivate Base. i public: void dis ploy OL cCourrd NYalue OF X:* BX K end]; > | : Aggegetin—and composition. —___ age gation 2 ieee a ‘hog -a)? gelatonship __| here _the_tifetime of dhe ton Aained obyeat | is inde pendent of cre _condaining objet _ Fi" __class Emfloyee © Public + oyee (arin An) £ a | Cliss Deparetmend Vector 4 Employee a employees void “aad Employ ee Lemloyre e) |_| contained ohjcel 1s _creeded and destroyed engl oy eed. push hack \e) 5. ‘ 2 > . | osthion:= 3 has * condaing—a'! selationship where dhe ith the conta) od Obyec eel I B-Class Engine ¢ public vold Stat) £ cout dc” Engin ghetled ‘end; By | class cow © tngine engine) public void. stastcas 1 \ J Teacher's Signature : x Date . Page No. i= Th allows pbyeds do take on |e —fosms,_enarling methods -tp behave —__| _ -difterently “posed on the _ objet _thedk invoket Ynem. _| [TA enhances — Flexibility and _eus ability: | 0 compile = Time _telymor phism"? occurs ducting —pragram | [Teas purine a titmpiintion and _tncludes : Fr class caleularbo & | public + Lt Mm odd Cinta, int b) 2 geduen Oaths 4 double ada \double -c, double _b ) £nehepn a b 53) >: | ond vitduad functions. class Base & Publi Giwduad void at OL tou "Display from pase “class Lend I; J : Blass vevived : public Base § Mblics void gisplay\) ovesvide £ OHM D els farm Serived class" endl, Signature cS Date ....... ( (Rpts efter Page No. .... > S *\ low 6 \oadii - allows dove lopens to atedefine _| _+| overloading is achieved hy defining Special member _| | function (vpevatos +, operados 44, ek) [| Opetadots paused ve dain thei original cfungtional ide |__| fore _buile in daca by peg fatamettic Polymoxs phism :- Jt attsullow and classes tah cain) ppesabke pn any desta ype. “This _is_avhieved avon —_| Aempleh- dycam ically. | crass Templates :- Templates cin he used Jo create il generic classed. Teacher's Signature: j | i \ | | | | _) arinclude Ligghtam> Os vy Framespace sd) H ~vem plate CAypename TY N function template. T finaha Ta, TY L set Lard) 7 a; i > Aemplate L Aypename Cass Bor X T data, punlic. j Box (Td : datala LP i void displog UL cout um Sats” yaadtadiedl; > i we int main 0X i Bor Aimd InBox \100) 5 Bor Lsrvirg > Sto Bor well”) j ind Box. displ ag) 5 ges Bor. dishey\)) Loud Ld Mmtor oF and ar? LFind ret (3,4) Lendl COUN Mak oF FS ANd 24 Wd Manl3.g 2-4) 4 end), wetuon vy Boe ————EEEE |

You might also like