0% found this document useful (0 votes)
10 views42 pages

Unit Pps First Year Jntu H

pps jntu h
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)
10 views42 pages

Unit Pps First Year Jntu H

pps jntu h
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/ 42
TTT ; . CPPL) + Introductions — Subprogram are the boullding block of progracy Sethe most important concept In Programening anguyge concept . Bub progease— ~ A collection of statement which can be sensed “to Sore, Memory space 5 coding time fs Called secbpregty 2X General Supprog ram charactristica? — ~ Each subprogram has 4 single entry point — There ud only ene subpregrac fn exrecutlon at any gives tine ~ Conti always veturn to the coller When the - Subprogram exocHon terrminok-oy. + Terminologier I ® sub prograc eo — A Subprogram Cat! ts the explicit wequast that a SpeciHe Sub prog 7a be executed, @O Active Subpregract— — A subprogra > Ps said tobe actlve of it hos begun execution but has) not get completed that ete cedfon hoadee3— Se oo reader, ani fs Ffast past of the Aetinitod ; Serves Several pus poses. j eq. def adder parameter; ~ Tis fs header of a Pythen cubpregrae Named adder. Scanned with CamScanner Ruby Subprogeacs header als degih with def. The header of Tavasor{ pt subprograc begin with) Functton, { ' PU ele AWG, ; void adder( pasacmeter) @ Body of Sv» program; — horned (ye ‘~ Body ot subprigran deHnes PS acHon | “In d bored languages ' body ot SUbpro gra oy 9s delimited _boaces. : | ~In Ruloy ion ‘ond Statement tesm{nates body, of a Sup pregiram " { © Parameter, profite : ~The parameter Profle oF the number, order Stype of Sh Subpre * sag. mn \ paneer © Proto cols — a p : — the protoce| ota SubptOgmaay fs ib pacamdte Footlle plus of it Loa seekich funcHon, cit redyen type: © Subpreyras declaw ttons | — subprog tac idleclavation provide the submonas Povtocol bur do not include thelr bodf 3. pyon B formol Parag ees: — The Parameter in SUB PROS o> header are coed forma) Parameter: @ Actus) foramen — 1 ob SUbPrograc call statement aust include SOPPMFeA PAMe 4 \ist of patameber ound to a Sormal Para meber are called actual Parameter: Scanned with CamScanner 9) fositiona) Parra eter: | othe roinding of detiad Parva metew tr forma) pawg- Meter Is done " poston ave cabled Positvonoh Parameter. 1) Kejesosd Parameter — When Vist are long, Ot mokes mistakes $n order of achtal parameter in list. One soltHon 4p Tis Program is feyword Paranebes tn whteh the Name of formal Parameter bs which achral para ead Yo tobe bound specited adtth achuol paraneter| MH colt. ea. Python - Sumer Clengen= My-lengte Vist = oy.are4 | sure oa). # Peslgn Tssues tor subprog meng © dre lol vasiables stotically oF dyjnamicall allocated @ can Sub acd depinitto ; preg k ND appear 19 other gub— Pregrac definition? Owhat parameter passin. ® Are the Ahe Metheds are uyed 2 3 of achtal pavameber chookeal ogaintt types of the formal parameter, ©ITF supprogram can be passed a parameter g subprogra® co be nested wWhalin the refegerr| environment of a passed subprogiraco 9 a ® can subprogram be overloaded ? ® can Subprogra be generic? QTM «ne language) allows nested subprogra 0, ave closure supported ? “Scanned with CamScanner POD nia we tanh qi obtdablbb cs er t Py AF Local Referencing Envioments—_. —Local Referencing environment of SUPPT IMG Gy mens stape of any companentr whetnen \ X iy jocal ov gore or ony other subprog rac OHO*L thod Lompenen+ can be accessed. © Local_varrobler’ — Variables that ame defined inside SMebpregra cy dre called local variables ;becanse thelr Scope fs Wually Pedy of subprogram ip hich they ore desired @ stack dynamic loca) warriadble ! — ~ ak wun rie MEMoPy fs allocated fo thot . Natiabl 2. ® steh’e local varfable — j — oF compile Hime Hemyry fs allocated, fo eyptry 4 ink add Gintvaglint 9, 65 vo Rete wath Ink “suo, static Int bj} SUM = atb) MekUT Sue, Rdvontames:— | — Reaipiiry — Bxppost Tecurston. —~ Shored memory Disadvantages: __ —eVOMY time allocaHdr 4 deallocoHon — Indirect accers B+ The enethods Scanned with CamScanner @® static local werslabloe ENE solange | @ Ndvanreg 2) — , ; _ Nodtime wostage tor \alocaton 4 deallocatHon - Direct access é Alsadvant ages — — Po not Suppost peQusstory. =_Stpare © Extesna) | Gobel yvar'jableas) — — A global mpaviable ave variable define oulside the SUb progam ov method. -— GF hos gleeal SCOPE. eons GE Holds volo Avot. owt the Program . So Lat can be accessed throug ouk the ore wy) an functon. Pregracd % DrNoted subpregrac!— Vord Ffacroricd ©)» noid product 0) {4 y Somme Languages Mee! Cet dogs nob sepposh Nested subprogra® but Tavascript p+ support noted support - for product ©) subpregraay can pe when we Coll Lactrjal Subprog-rq @ , So, Product() sub prog ran No occa} rotderening ‘emNiaynment ef dachorial Oy Sudpragsca cy Called only Scanned with CamScanner Ae Parra meres Passing Methods 3— . = Paramekee passing methods are the woy 11 which Parameter are transaitted 04 oy torn Called Subproyra Mm. ( — farancmoter Parsing depends on mode oF subprodry ~There are two model for. garra meer Posting. ® semont'c model of Parameter Yarstre @QTmptementation cece) ot Param eter Passing ® Semantfe model of Partameker Passings — : @ seoelve data Pree achiel paramebey-trroode . ® Can transmit daty ty actus) Para er eterr- out rode © they Cands bots called inout mode, Colter Cotkee . Cab Cab, 03) Croid sub Cint x. frry intz) Cat nT Ji ) q j >? Xx Tr mede Reba7n i eT 88") ey mode Call é Zz Inout mode Rey. © Vrnplementotor Model of, Parameter passing s ® Poss by votre} CANN’ bY Value! — , hen a parameter 5 paised hy Malte, the Note of aehiol parameter iy wed to Injttolice corresponding foxmo) parameter Which act a4 4 locs) variable tn sub preacs . thus lo plenentiry Jn -mode semantics. Scanned with CamScanner EE SSS-—~——C s by peulhs — . : a Os by vravtt is an } a plamenraHto 5 - mode Foy Cub mode parameter. Bh. cH code Void Fixer (our int a, oot fot yD, 7 ale tie 8S} 4 }. Myer Coutce out 4 V; - © Pass by Vole -Reyutts ~ Fs ad {mplementaHon model for facut mode Parameter (0 which acho) valtes are copred, @ ass by creberence> —— Pass by wseference fs second implementation mode} dor Inout mode where parameter is Parsed 4 addresses ov veberencel @ Pass wy names — — fars name fs an (nowt made. Param eter Awansmission mode wher parameter are passed by name the achtal fparrameter fs gubstitided for covrespondin formal parameber fn subpregamn = Algo | 2 suported by poss pf name. A Parameters that awe Subprogara en § g— Sn programming 14 Number of sltuctions occury when subprogra thames Cad be Sent ay pacumet, to other Subprogram Scanned with CamScanner r OV. Maun ereetar ON ComMmMaN LxaAMPIe OF those laccury when g Subpregracs MWA SaMHPle same Mathematfe Function, Beir h. 3 —Althousrs the idea fs naturel 4 Seeoning ly. simple bub how vl works con be confusing | It only the transmission ot the subprgee ay Code wal necessary at would be done passing Qa single Pointer. Howedver hoo complicattory Av\ses _ i Ars} there » matber of ype choking of q Sebprogracs that ed Posed od 4 Parameter, -En CAc++ Functon con nst be parsed et as Parameter, bub pointer to fueneton cai, — Porprongs+ had a mechanism of providing Lype of pavametey tyr svbprogram’e thot are yossed as parameter $ Chey must be checked, _The Second complication WIth Pascarseter thot Are subprogsacs oppeass only with languages thot allo neited subpragrac, ; ~The issue $s what meferending appears enyironned for enecatiing the passed, Subpresrac shoud be Wed There are three ohoites. © The environment oF the call sjatement thak enact the passed subpragea ( shailfor> boindiing) © the ovine moment, of the defini onio fs thet | Passed Subpmogra a Cdeep bainal ing ) Othe Environment of tine definiHon of the Passed Subpreg racy Cad hoe fai'noli'ng ) Scanned with CamScanner ek. Fava cost pr stunctior sub) OL Mae x 5 Function sub20 § alert Cx); d Functon sub Of Nov * 5 AaB) Sub (Sub2)" . ) ys SuncHon suby (suby) f Var Xj Kel! Sr x Oy) 4; AoNS Sub 3.0, 8 : wf — Considev the executon of sub2 When ib ls called jn sub4. do%-s ; __ dor shallow binding, the referencing environeers of thot execrHton js of sub4y, sothe vreherence fo * in Sub fs bound to loool % in suby | 4 ol1P gf G - For deep binding the referencing envirnaren} of sub 2'5 executor Is thot of sab}, so the weference tx [N sub2 1's bound ‘te loced X10 sobl 4 ol Ty 1. ce ~~ Scanned with CamScanner a ACO. r efertnt Lag eny aesng a4 oO , ¢ e “Alnos sbindl'ng \ tre binding Ts to the \wool A in subs 4 olp is & - shallow binding fs not approapl are for stedfe Scoped languoges vith nested Pee X Calling Subproyracs Tn diirect| — Usually when there are Several possible sub — Prvgrams to be catled S$ the Comrect ona past cal; sur oF the program fs not knowon untal execution (eg. event handling 4 Guts ) ~In © § C++ Such cally gre ase thy! cH Pointerss. “a? gine -An ct, method pointers are imple Mented ces abjeot cabled delegates A aera declaration Public delegate tnt change Cint x); ~ This aleeg oe type named Change | bon bd insten 4 fab bel: fergie any methed that takes an int paca ned en S veurn an tnt voluo. 7 A method static sink Fun) (int 2) Y.- --F £ opburiiai e's y ‘change chgfun! = new ch Can be catted aolth + chgfunt Cia) . ’ nn pte “ON store More than one address, \Fa P called a mutt tatk delegate, ange (Fun!) . Scanned with CamScanner ¥ Over loaded Subprogeam & — An overloaded sw>progracs Ps one that hal the Same. ame amie Sub poosra cy tn the same vretementing ANNI ToNnMeNt - Every Newsion of a overloaded Subp TAD hoy A Unique Protoce) je. tt must be differcent drew Other in the Number, order or type of GD ‘para meter 2 return Aype if St uo dune. — C++, Tavg co 4 Ada include predefined OYerloaded Stbprogeacn. Type of an OVerload ed ( Con be Aued to isa mbiguocte Coll Cus won oe Ver duncion can have the Sarme Pama cr Oterrs ) — Ada \Tava yt, SCH allow Mmuttiple versions @f Name . Wer 4o write SUbPI-wGer.5 uaith the sq Ma, Constructor. <4. tit code, Notd show Cinta) t Co rs a; Scanned with CamScanner void shod (int a Vint b), 1 cout < vnporbant conhabub x Ap slo producti . ; =To increase the reusability of sofhoare Need tw oreate different subprogmm thot implement ‘the game arithm on iditterent ape of data. “A. Progranonves should not need’ to write four Aitfecent sort subprograms tp sort four array that differs only 19 element Type! _Polyon oxphise 3— sub pregrand dokes parameter of different “types of Aitferent ackivedon, sonerloaded’ Subprogram provide a pattelae kind of poyyrosphisms called ad bee 0° moaphisn, — Languas eo thot Appos object-orient preget- oing wuolly Suppo er sub type polymnpapls2); -Subdype polyremprk se ees that avaiable of aypeT can accet> any object of type T ov amy ye derived hoor TT. : J aah ote Ete. Ee oer tat lace j thot i oribe the are wed ih XYP™ exrpressiens + 3 ype ot the pegrae parameters of sebpreyTan, _ Parametri cally polyerospnic Subpsogsacy are often coed generic Sub program. —Xda port) Tavatot+, CH 20054, 4 Fat promide 4 | kind of compile AML Pasgmekri co! popyedse piso Scanned with CamScanner Generic function in CTH Bm ents Perey) @ aM onpstios ‘ot generic SUbPTOYTAM are crested ; eo} Ubprogra mo is named Tn d col] Jmplreiry phen SUPproy 5 . ov een as address, us, baker eohieh with the ‘5 oper okor { — Genesic (sab preg rao ore preceded a ternplate Claye thot List the (Qwente Nawiales, which Can be type NAMKS oF Class NgQ o-24, Seley | | Geneste mnethod in ' Java s.g 2 -Difterence bet? wie ind pir sri sal Goer tc IN Yoava S.0 4 those, \) Generic Paracheten Classes BR Sara s.o generic methods are Instentlated Aust once as trply, geneste method. 19 Tang ¢.0 Must be 3: Resdrickton con be speciffes| on the wange of Classea Wel cain be passed ty the generic methes oS Goene Parameter. 4s Wild card type of generic Bata mek oy. Public static <7 >T dort CT CJ st) aan | The parameker fs ory array of generic Clement. (Tis the Name oF} type), a b Scanned with CamScanner CUBA coll une ay } dott boo ahi hee a generic Ape IF it (Con not determine the supe of A Ppavamebey oF welurn type of PuncHon - aubometl¢ generaliaation, | -such type are denoted with an aposhrophe 4 single letter eg . 'q Scanned with CamScanner —funcHon Can be defined ap have gemersc, Parameters. ? lek printpaly (Xs a GUT tape Printtn YD 7k | Ky —%A & Frmad code for ang type. “These parameters ave not type cont}ralnel — jb the parameters of 4 tuncHon are ude with avithmebic operaidys, they are type. Controined even sf The pavrameter are specitred Ae be generic ; - Become of type Inferenciag & the lack off Aype coercion: dk generic 4unctons are tar lees wweful than those of ttt Sava 50d | CH 20054. Design Assaes For Function %&— — The oll design) suet are Specific + fre Mare side otfect allowed 2 ~ Adq functons con have only ipmode formal Parqnurers. THs prevent atunctorn from. cuuing side edfeck through als | parameter or aolg> otlasing ; = Most imperadtye lan ag.cs teincHons oan have’ uthey poss by VolNe OF Pods te] wreterence thus’ allows FunctoM thot cause side offect 4 Pee ~ Pure funcHonal langutegien,\fre Hoakell do net have variables , 30 duncton, canner have side e tech Scanned with CamScanner PV Fae multiple vale, can be returned ey <4 Placesing ther In tuple. * User defined over loaded Op vedo st — cs operators Can be overloaded es the weer in Ada, cr, fython & Pubs. | 723- Python Saco fre det _add_ ‘(self second )¢ ; | cretion compler (self eveal a second rect! golf. imag + Secand:ima4) ~ Neatly oll! Program cing language have. oveTloaded Operators, -¥ closur es¢— LNirN Ment where Gb OU def ned, setesenci a9 environment 1s needed of the Subpro rac Can Pe called dorm ouny arbi traay —cClesuves is, a Subprogram & mehertncing e Place in the pregram. —Shotic scope progsancs dows not Have nested Subprogram (o closeres axe not Useful. —Neally all Fun cHonal Progyvamening longusges Mos soripting \eungeeaged ' Jonparahve Vanguag ed Cty support closures. ; — Ther languages ave stale suope , allow heated Subp gra to be Parsesl a3 parameter, Scanned with CamScanner @ Whet type of Values can be returned? —<¢ allows any type fo be wetarned by a funcHons except avvory | yf — cat allows Ad be wektitned fron HH Fenette, ~ Ada Pythe 9 Ruby glua can return Vabite oti 3 tyre 3 —In seme, PSogrAmenlng | YY 3 aubprogina a5 Ine ety cat he posed Coy Parameter, serum ed. Prova functions. & caisigned te Variables. ; - ee Sava nov cH an have Sunctton rothougty thelr methods awe similar t functons AN bos ONY *Ype oF clas can be wetusned yy methods.’ Hirst class objects’ cveans Gh, @ row MOM VAM Con be ekuwn ed 0 Me — In| mest lenguages only single Value can he ceektusned fro a function. = Ruby allowds the seturn oF more than one ‘valite Bren metned - of aetusn statement ft followed oy VAPredsion, mi! a ekturned | -9f fellewed by one expression the votue of ekpressioN in mokuwred, rot more “thon one expression _c array of voles ey express) om vo Artyoned , , ba Rex: ollovss fuuncHon, > veturn ub ple. ex. etu™ 9) SUM J adex Scanned with CamScanner 24. Tava sesipr . Auncto oO moke Adder (xy § ra ftencton (y) AUTO ALN SY 3 vay add\o = okeAddt|o}; vay adds = makeadder (4 - documest write (% Add 1oto%o% "poad 09 4 veo 1d") 5 document. write (YA NL bt Ip" )5 ad to Qe "yadd 50) + o|P=> r Add |0 to 2° 3 30 Add = to 20 125° * Coyoutines%>— -A copoutine fs as entrie g cone) dh -GA us also cabled symm -FA tbo has Ane mean eo Naintan betM activation: ; ~ This means Ahot coroutines Must be Wistory srectic \ocal variables. etten begin ubpreyram aghek Ned cdi ple eon akseth. edric conn: their stotu's Sensitive = Secondary exoculion of covoutined ok points others ‘than its beginning. —A (orovtine catt ao named a resime — The Hirer reume of a coxoukine nto aly beginning Scanned with CamScanner eu e. x - woe but subsequent coll entey ot the point swap after Ane bast executed statement tn the Comoukl N24- @ Two possible axecuHon conor] sequences At mse Cos vl ne anithowt loops: I me oa A > creduome B pesane B resune ® (6) Scanned with CamScanner ; Leogle menting, _ Sub pre gracpe— ap 2 f General symantics of call £ Return s— —The subprog vam coll £ rerutn operations are together called sub program \inkoge. The 9m plea. tation of the subprogra Must be based On the Semantics of Ahe sub Prog rac Unhog € ofthe — Semantics of a sub wutine call, - Save the execubfon stots of the current Program unit — fois the pawameters ~ Poss the mekurn address to the callee. ~ Transfer control bo the cotlee. Semantics et a Submutine return =F Yheme are pads by Noluercmesult ov out mode. Paramebens tne current vlolue of those. pavameterr ove moved to the corresponding actual parameton =Move the retusn value to a place accessible to Ahe cater ~The execntion star of the ahlliens is ‘restored, ~ Contw\ fs rransterred back ‘to coller. Stwrege of anformakion 3— - Call & eur achons require Storage fox tpl}? — status intormation about caller. — Paramekers —RekuTn addrers - Rekurn value tor Function - local Navriablel. Scanned with CamScanner Y . ’ 2 ' HLnple menting sreple Subprog rao — _sienple subtbutihe? ore those! the con hot be Nested 3 av jocal variable are state A -fA simple submutine consist of Moo paris: code S'daka - fil - Cole | Constant Cinstsuction space) ~ Dota. can change when the subroutine fg Recuted (dota Space) - Both parts ihave Fixed sires. Activation Record 3— ~The toxmet oF Joyout of toe data past ts called an actlyakton vecerd becouse the data is wleant to aN achivatior oy execution, of the subroutine -The form of tne activation ‘record ts stadic. -AD acKyatoo “record instance is q concrete Lxarmple of on octvarion wecord (cormrerpondt ag to one erecnton. A» activation wecord for simple sub mune Local srorrledoles Pavaccekers Return address Ldince the ackvetlon erecord tnstancé oF a sicnple oo nos fixed Size ab con be stabi col ly suppor alloca ~ Actually ob Could be abtalched +o the code part) of Ane Subprogram Scanned with CamScanner Twifltne | codes: acHvedton, mnecomd | ot -Hhie Progmres oO with RMMple subqoutina che | = four Program units ~-MAN,ALBRo —MAIN cols A 18 3c r originally 1 OW Pour Programs may be compiled ot difherent Hoes individually. - When each progracs fs compiled kh bb machine Codk, along aoith alist of references to external Sub progea cm Are noritten to le. How w the code linked 2 EE te linked 2 mot £1 Local variable | f Local Nawtable A Porameters. {lees canis Local Nala es B Al Patameter Return address Local variables CAA Para neser ReAWEN address | BA ey | “4 Scanned with CamScanner “ET plencnting Subprog wad saith ssbank -qnievie Loeal_ Variable 3 — — one tmportant advantage of Stack dynaoic local Variable ts Support Sow Reewrsfon, _ The implementotHon vrequires core complex activation secord. ~The compiles cnust generate code td cause the Amplicl t atlocalton & deatlocadion of local variables. —Ackvohon recond s — Local variables: Parametems dAnamic tink Reburn address _— = since the return address ydynacvie link S parameter are placed in the activation record ingrance by the Caller these entries mut appear Myst ; = Local variables dee adhocated & intiablaed in collec So they oppear \ost - — Dynamic Wok Coon) link) oF subi L]_Retwrn Cosabay Ki =Btc; ~ —_ © Lei bad got sub) pas) [ Pecet, T Procedure sub Ck. integer) is fs oe BiE idnteger: , Rehirn (t'ntb2) Procedure SUE3 iS Lec C,E i Intege~; Local begin .g— of subg er Parameter Sub] ; Vp) | Paani Vink, Eis ; 3 ; end : Sts <——@ L] Retwrn Co Bigsub) 7 (| Local, beaj @ Loca) ye still “Oia 4 j 7 Loca . @ Tee) 17 Loddy COTE ¥ beg y op Bynamic \ink Sub2CF D5 Stale Unt. ee _ URebern (to maf) | “Bigsu; Me {L voce) | mon ond 5a ~~ Scanned with CamScanner Blocks; — — Blocks ave wer-spectHed loco) scopes por yarsidoley oy. an e { int temps tomp = Ws tcupperd; list Capper) = list Clowerd + Us} Caer’ =temp-! —\ibetime of temp begins when contrl enies the block . — An advantages of asin A 12Col Normbaly| ey Whe fs thet Gt cannot InteFbre avith Any other variab withe same name, le ~ Lonple menting blocks?— wo Methedd.2 — OTrest block as Parramekevess sub are abwoys cotted- Program hab — Every block has "from the SAML locaton, an activation Tecord ! an } r - ns Ps created every Lime'the block tence @ Since the { ~ e4ecuked. CO MUA * Shp: 2 vequhred fo { b C2N be Stati call deteror'n ed xq block CHO be allocak often the Ag ithis amoung of space cou) ‘ 5 ackvation record Variable tn the “# To plementiing Su namie Scoping 5 Deep Access — NN loca) weteren cg ave found b Searching he achvaHon second inttences on The dynacntc chat, , — length of chain cannot be Stat Coal ly olebewmined Scanned with CamScanner _ Every actvattors record Imlrancee mut have © Nariable names, — shallow Aecess.— put locals in central place one Statk for each variable mame, — central qeble with an enhy by : Farce hy for each variable, — Using _shalnd access Void subac) hat m2! rechh get da KaAA } 4 Void sub2 0) f TMF 00, + BSS rior Th sub, 4 sub) Sue Ah id | Sub] void subtC) { mein| malo | b2. | supa} sub] int V0 “UM x Z w / y ? (rane fa the Stace cells tndicate . Void mained § Praran units oF Vamehl dealaradton) tat vius 5 AAbstract data typess — * The concept of Ab StracHong — —An abstraction Ts a view oF representation of an entity that Includes only most ségnificant atts} bute, The two fundamental tind of abstraction are.— Oo Paroceas ab srraclen §— Att SUBPrograry are process obstracH on becouse they provide a way of dor 1 APRgrAS fo Specify a Process pwirhoud Providing — Scanned with CamScanner _ hee dvekol |s af pow ne perdorors jK foak. Hy Ga Process. SB, yIhen prgvam needs to sovh an arerroy oF numeric data of soree type. ( somfor (list, listlen ), - This coll ts an abstrachon of actual sovtiag process whose algersitho is nob specitfed., , absrraction $— an Py Ts also Known a information vidi ng. Taleo allows werto create data object (Naviablaos Abstract gata type 4 ase allows user to perforos some operation on qhose ‘data ‘obsects but am plememetion of these tapes are hidden from were @ Poating point as ar Abstracties dota rypeg— —atloatog point types in nig \erel tangaades vio q koy concep tr dota abstracton.:\ntprmaton hid (09. the user connst direeHy manipulate the fast of the Aha svepregentation of values because -thed wepre. Sentation So ‘hidden. The wer is not allowed to create DW operahors an data type eXCePH “those +hak can be constructed using built in operations J @ vser defined abghaet data type 3 — —d#t uses deAned sbstract data aype should prowide the game chara civistics as those of longuage. det ned ‘yper Such o floating point type. SO we Can detined an abstract data ype to the Cantext of user defined TAPS An abstract date typC} Scanned with CamScanner 7 re fy. is a data type that gatishres fol!” conditfan,, O the wepresentaten of objects of the type ix hidden froro the Progra unit thot we type So Akrect Sperodion s of possible on these peat Ove those re iced in the types cletinitjon 7 © the Aectaracton of the type & the protacels oF the opeyatian on objects of the Type , which Prvide the type intertace are contained Ina Single mtacto units The types interface dees not depend ov the crepwesentalor of the 6byect or the implementation of operations, ¥ Benefits of abstract data types — OTruease seliability- @Tt geduce the Tonge of code & numberof rammer aust be yariabied oh robich a prog Onde wher wribing or reading a port of peogern @Makes name confivehs Jess likely ;becarse the Scope oF variable if Smaller. #-Des ign Fsevex for Abstract lech pax The Fores of the Contoines for the int face do the e. @Wherher abstract data type coh be Parra metennr.eck « @ Whot ace ers controls qve provided & how such controls ave speci fred. 5 Pet the kype is physically @ Whether the speciHeatoo of geperoke fro 1% implementake 9 Scanned with CamScanner “tLanguage Exam ples 3 “We describe the suppost for dota abstract on, povidel by Ada, c++, obsective-c Tava, Cab Be Put. @ Language example in Ada §— ¥The eneapsutotion construct an cashed packages, sped Neation Package Cthe interface) WY) Thenance—of the Body PackageCimplementadtor of entities named ww the Spectt'catf on 7 In tormalion hiding? — . = The specification Package two pasts. \ public s private —The name -of the abswatt data type appears fn the Pulte Past of speciticat’on package. This pass avo jwelude sreprenentation of unipidden ‘type ! -— The representah on ot abstract dota type appears in private past More Reatricted tose wit |foj}hed Private aypes?— ~ Privote agpe Kare ‘built-in opesstion for assignment \ 4 rk 3 & comparisom. |) 4 — Limited privete have no built-in - operator, Reason fox: Public | Private Spec package: — WM Thecompller able to see BPresentatton atter Seeing only specitcation Package Ceannetsee pvivite Hi) Clrent crust Bee the ’ype name youd not ene 4 wepresentoH on (cannct seo private past), + Prollea with thse © DUEHcudties with pointerr i) object Compasison Sesh “ = {iD Contrel of object allocation 1, Scanned with CamScanner | | \ eA. 1D ada. 7 Package Srackpack fs rype stacktype fs limited privates MarAsize' Constant 1= 100" function empty (shle sin Srerek ty pe) return Boolean, Procedure Push (stk 1 iin Out stack ty pe; le sin Integer), Procedure pop (stk tin out stack type) ; Funct on top (stk: in stackty pe) return Tot-eger , Private -- Widden Aros cWends = type Usttype te array (1. .mad_sfae) of 41 tegen type Stacktupe is record J Z end Statk pack» x Language PROMPLE | CE i closs fs eneopsudetion device, —M\ of the class instances of class shave a sf le co OF anemMber Funenon, ~ my -Each instance of Clas ha ah members. —Lnstences cous be Static —Inborman'on hids'a _ W Private For fraden antitd he . ‘ < iD Public for dntertace ontifies it) Patected for «nheriteure, — Constructo re—_ CD functon to dnilialize data member Cthey do nor create. object +> (OD Mey -otv0 allocate storage of past of object Ps peop dynamic. Bs CMP COPY Ob Clary day 1STRCk clay namie or heap Ayn elo of = Clays sample. Public 4 Noid swopiun (TS, , 18m), 4 T temp = 4 ; Lam, Makemp j Snr ‘Int onan (> (nk a= pos; , Mook C238 doo3' char entp paral ) Sample Say Here, T 2d genew'c dota type, @ Generic closses_in Taveg Class sample + =neaw samele d = nea sample combos Sample s = Nevo Sample Sta AGRI 4 / *Encapsutarion Constructs — — Eneapsutation is derived. binding Aogeth er the data & funchon thot TAN) pulobes then, ®Encaputetor consruct acheive msing header dleg— ‘ -collecHon of related dota S functon getinihon can be placed 19 Mle such “le ou asa \ibmny, The interface aw such Ale includéng dota (AMppe S&Fundion declaration co placed into seperate Nie cated Header (123. | - Type declarakien con be Widder by devlaring Tepe anyeston . thom in neader ile: — There are wo Problem with th} : ois eDach @ documentation of c\fieny PTOFACD oY tHovaey los}- D Author of the Woranry change header fle £ fonplemenet - Scanned with CamScanner @tneaps atton 1D bead cH + langeage fs anhiwed b @ neaddHives ® classes. @ Ada Pack ages: — Ada package apect ficaifon con anclude any number of data & sUbprog Fao declyraHorn. in their re ic privoste section. -So the pacleaege up multiple type encapsutotion construct - & Naming Encapsutattong— ——-w+8$+____ — When we are writing any program there we ave, dectaring amutH ple variable , AeHning funcHon + declaring clossen, SO there awe chances thal name. of varioble nay confit ~To avoid Naming conflict. ® Namespaces in -cy+ ®D Paclcoge in Java Ada packages Ramespeces {), CEE Bi i: 9. th incletole vsing nawmerpace std’ namespace rsd: { Imt vol = 200 t ¥ int volelvo; Scanned with CamScanner int mone) 4 Int val=209 | cout << $ivsth i vob <<\'y/ , ren 0 | 4 5 ~We con we Namespace For classe: also. @Qfackayes 9 Java y— — Jovo include Paming en capsulotery conshuet s-e. Pag berg es, — FPeebayes can contin more then one ype aley'ni- Adon 4 packages ave pastol tytend ot one another ChawHal means entities depined in package are either Public o¥ protected ov NO access Specifier ase visible tm other Hype oF pacberge) - Entities without access moditfes are alt eof Porkaye scope . ~The package aeclavahon cust |ppear at tye nse Une of file HYNTOH | —_ Packard Strpkgy -9F package stwpkg has clas name eysiack. So Class can be wmeterenced a2 import strpkg-mystack 5 —~Vo access all of the Names in package -tmpost Stkpkg . #5 Scanned with CamScanner Gada packages? — ~Ado packages wied encapsulatiors Vitbwery ies are delined jn hievarehres - visibility de a packetge fromm Progam unit ub gained aoith with clause °F) asith Ada Texto 3 H To aceess puLt Procedure . Ada »Text_To»+ put ; — Jo access names nvitbout qualifcahton use Aca “Text To; ~ Ada's ase so sfmilar +o Java's amor) Scanned with CamScanner

You might also like