0% found this document useful (0 votes)
38 views19 pages

3rd Unit PPL Notes

The document discusses the concept of subprograms and their implementations in programming, emphasizing the importance of modular programming for better code organization and maintenance. It covers various aspects such as parameter passing methods, the use of functions and procedures, and the significance of abstraction in programming. Additionally, it highlights design issues and the flexibility of subprograms in handling different data types and structures.
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)
38 views19 pages

3rd Unit PPL Notes

The document discusses the concept of subprograms and their implementations in programming, emphasizing the importance of modular programming for better code organization and maintenance. It covers various aspects such as parameter passing methods, the use of functions and procedures, and the significance of abstraction in programming. Additionally, it highlights design issues and the flexibility of subprograms in handling different data types and structures.
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/ 19
ws SOBPROGRAMS AND TmpLEMENTATIONS i can be = —Retued 45 tg) Known as 2 @luckon of Statements) whith gaveremoay Spa Ce and cecbing “ume siberagro ' | he " j a Pre”g rams, multiple statements can be'terre UE YY LOU, Nae H becomes ed she ervoy and tt drerteult 4) Read prog becorre oF understand the progres Sor that's we nour Som ealled. modular pre ran 1 . dul divide oF -progyams arterms (oF meses. Y Suppoat, “our pregyand , we awe Yo catcubsre Fractorvot exrewarg foctoy vat 10 mes ) aFReelt tO Recover evroy or traci ram or Grey we lostime's. S07 Instead | of, code ‘of -facloriat totus, we Pare # * e factorvah wonetin, rool. Hot single moolule,, ec! catouhte : ond we ‘worl! alt -hot ‘noctule mulerpule, Himes ov lovine aM rom ah per oth Reguaty The 16 called sulpeeg Om Fanerion ond. procedure can be Co sub pragrorn« 3 4unch on tos Rutuor ype: ) proedoe ches rok hoc Reon typ e- s fa ing add (int ¥, tnt y) “9 otf bn fz Ir vod add Cc fom 2 a t j lor $um5 int Sum } d Sum 2¥4y / Sum 2%4+Y! Run bon," » { Sppude vor moun Ot rs of sok : ote 7 odd C30) 41; ~ we NVM ey ok SP : ene psiyeivaengJqegh Ug, Ge abi RIAN or \ Reade bility ¢ «boi error “he! ducing "TEs boyy Hi ods Abstrathon : Pom TOM ON wonites se ; | Hae de. he deny ero v0 wk Subp regror. ; | ‘ | a he worn Ct fueron or subporgrorn. he w/e" yt olf. Meer | | logteed~ Subprogrorn elder trom the Bs ta uw ro ned fo bop about © ae “YS a Ble ene aerate F, me C2 Wwiy loka we dm'p hae to voarhet bieman 5 rot 7 | wwe Ode ond ue win b (o-Hws of factor-a» frrdomustals of § ot Spr + ' Clancreraucs of Sp! wy Who 14 ee “s Oot cach 6 es & ime one pein D the @ulterg Pam unre 5 aipinded doving ple cx od tne. te means trot Hhure I only ove Subpregom i'n execu oe ou giver sme. | 9 hae always Prors fo the Coll] then he SF ( exetut'on termenake sg... | Terming bres! - mini ee b subpage cob: we Spas ce, pert Rye seal a : r wy 3 _ spewhe sp “be vexecubad -, : he aden ‘ ha. ackve SPP of 0 tone eee sr wil be ‘actewe a yo “B. Sp Headun. . i sp Heat ois - ade Cint tyinsy)-> 5p hraduy 1 Vine sum; 5 get ayy {yr body | a fla 2879+ mS : 4 Te def cd poromuteds 19 Pytery Uae A Ruby hagas win fncren’ én Joe Senp 7 : of 6p Neral” yn ae dn e i we wilt * cbte a * conse. ot bones, nlp ot f_sp.- + Pecomuke ¥ ‘pootile:- WW contarn's \ pororlutey pootilis, vm gyre, orden of tts tbrres povemabe Ys ‘ - prvtocok :- prromaer pokie +\Ruun we, "04 add (int ¥ jeg ) eee + PP R- oe Meteen an Cy hago, ‘abter rain frretiom, TE we React Hare Harem, alud PR? / » oe AVE womtH SP, 99, when Comprber ok a time ecagpthet unwore etbout(aal a: freon ) > Jo cl eke we wor Cole prryr es. \ ebonut ; Posi erak Por7errute! ~ hy cors eapowral blo actol Pp é ond repeat. povonuters . (er) Mey of achat’ peomes os an b uci teyrres peoomuters 14 che, wv poarkon ago poromere et! qr wn python, : aches ro ; eee Sameer (length 2194 Dinghy vets ry. anes, ange 4 4 \s Y a 19-84). feriron parorntevs “4 ordey we Com write. g's not depend on oy thro ordut. = ( design issus tn Suloprogroras!~ \ coll a tl. 4 nomi | ") are locat_Vartabhas eesti cn spor at wig v Compr he tine Bind tg tm | fan Yo ofow Ayeal Meow + Yow bindings happ' YO ’ or memory adeness od binding to ariay i G diobvnry, yor, . 1a Gm 6p det's appear '? piu Subp' ; | ye ae © dy, ore teed ¢ [ 3. who parometey — passing method... or, mete jw. me the pes of He chet paromasers CME tea 1 ys yres of. the -forrrat poorutero ) ah dL p's s) dE Sp com be pared a perpruters en 2 se teuled ot a be ngted, whdt ry the Rebvoucting Pod sp 2 : \ SO 2 ton Spr Con be “ Curbaded 9. ; . i | 2 40 Cte Gow be ouenbasdid , ; . , a (9. Gn sp's be genent9 ‘ - gn Java, we axe @. tf the buguegye attovos nested pls, are cloups Supported 9 2 A Closure 1% a neted SP md A's sretemnacihi enurrormuut, Which fogietur ao He subp2vg7on) do be tolled frevnr Ma in a fy. \y \ L lecat Risereneirg | Gusteenerat = ie wands: of 7 Fro Q- nesting 6ubps0gron- ey 7 \ G? Savasonpl 5 sy ins 0b 8, 27 TRIE we: Voth nested SP, 4a altourel 9 Sere Paws! UKe_ foeyeu'p - gute tb, word Factorvout O vod proceed O b. @xeterrot Japecs vouab le + 4 Prt can acess au the Jeo vovably ¢. locate vowably. — © stack pyran vaowab le uy siasre. weet vo LA Wabrde. the sucbp7g Yor? * D geo . Yo ek int ade (int % int Yy iat 2) [Porrnat, pero tm Sum; // sack drome, tocar verve bht > toropile Hine only erry Stowe ind b; Newowc spear vara ble Sum =X+y win accers yer Sin} edu) — 1. Flext btlty g. Supports Pecinyy'on |- Colterg dm dracon HN 3. shoved mowrory 2 4M, Some vouably, tf oe how meebrepole eps. +0 allocate he thewiverg wp cat wovable of 2Hmne a sp 4) ine 3 Sp 50) Lim 9; yr Sf 40) in 2) on oe, =. { —:° ame twallotae tt deallo@uoy. 4 Ih Ny : ; [| hou Hime 1s wasting | 2. dadoua Nae Se war wit ocede x Ober Hire Fy te van Hu'r ot etme. Memo deat voouohl 1@ Static locat vauabte,- (atati oy). tdv O No tine wastege da altocetion oval clea biota @ pied aan DM Gropthe time omy slate (een ORY | -Dis)- © 00 not Support DUO a aa @® storege Cm fot be Shared, *- Pocomefey passing mettods » - > ways yed ve ara in whith parameters We rons 0 fiom ulled Subpragrams: t pass —by -als featt -by “Vat” pars - by Result + POA- bs volun — Raul, fas - by! Rherente S. pata by - nore ° Lo Fic cll coll Cpavecdne sub (% ) 2)) Gab 0, bo) — — ——| x s] a In mode oe Ee Te] wnt how: rode. tg Load erodes of pororuter pay, the valu of the aduct posoeneter rs uxd. do inmalrae coyresporrdl fymat Paiamerey, - Novenaily implumentecl copy" - tan be implemestes! » Ayonsn HF an a but nol &Commendect . = when copies ave wcal, adduivovat stovegs 15 Requibuc ceeds path ~ Soroge and op opevatPors (or be coy, Pays ~ by = Rywlt moole) ¢ ge hy Sens steal s when a parameter is pared | by Ruuls, no Value | | '> tronsnw Heel to the Subprogram , +e, , correspon 9) | dora Pr i eK act eh Woon bea | waren ey Vole US svonsmitied gtr, caller's Medtood | poomuters when contrat (5 Retimed “p she caller, , . COME bar — Requist extra Storage location and py lh ilat | . 7 potentat problem: sub(R, p,)» whichever fora parorruser th opis tack eu Represent! thé Ure vale of P, pawn by Malus “Ryle t- > * Combination of pos ~by -vae wat peers by - sot > Semetimn,” ciled pees by or y ~ terrras parorrusers have foes storey. . ‘ =. Dibod Yona. aa 3 those of pars — bu ~ Resuts 0 —> The of fay ~ by - Value rue Eby ~ eronce(Snous, mode): » 7 Por, an otter. porn 2 Phyo Cullid poor by - Aoi, pea (> pawing poocers is ebnbucvort > bidscaluonsayy ”. | > Alouuere acters |] potemsrals or ~ un-twonted albiasey- un -cwomed Séle ohbuect ( 1.€ Poe By yertay Substttutton- > tomaly a bound to an accert method at +he v 4tme of the call, |: Subprogram exorne be i y rw eC econ. int odd Cit tary) 7? jets Paneer “yr t Sag we) Functor tye int Sums Sum > 444 5 Yéeturn Sugn 5 j > wou add Cink xy tty) 1 int Sum} Sum 2 4x} ; dtat!s > were , We drlt howe reurn +yre colltrg proced wu + ho vocal maint) f int Os {a wet 083 C298) any bog. staan i6 tHe fnetion Cabs c tied ag a POE N oh asetinauixc Ong’ > fincrin ‘ond procedsre can form ary Subprog rons, wer Loacled. meted :- ‘ Ww. came fm overloaded Subpreqram wy one thot boy . e game Rebrerencirg name a anctrwt Subprogram in aad) en tyonment. = Wevy verAve of an pyeyfoaded Subprogram hon @ unique pov to cod- ‘ > C++, java, CH Ord Ada include Predefened overtead Aubpvegt ams , ; In Ach, the return “ype of an overloaded - Funetron’ can le ued to Avsambiguete calle. 4a ada, (tre Return type OF an overloaded finbiro} jova, cH, and CH allow Ueu to vrtte muteple —Nerbtovy Of Subpyegrarny tolyyn re “Sant! Vong Sunerit pregronn, ), A genente Gy peltroorphie Subprogram takes powmelers oF olifterent types 07 afFerent ack Veter y > overloaded. Subprograms proud. adhoc. _ Polymorphuann . > A Sprogem Hrat? Fak) a GONE patameder Het A wd in a “fe Alprenis i" aster, describes, the type. of whe farameterg of 4ta ‘Subprogram poses “ pavamét vid” Pelymorphien epgeee ree UNE daw! Ge OF, parametric pelyraorphis a on | template Ne ; 4 ier \ gre max ( Type First, “yee ‘scatnel) ‘ inlacg teu tyal 7 gewond ? fist $82 Cord 5 be dnstannaed tor og B the above templare Can +yPe for which opevatoy tA defined . im mare Cin first, jaa, Second) , ‘ ct velan fry > Second > first 1Secord 5 os I j | Design iwues by freien. Mie Side “effects giinued 1. ~ Parameters Should always be In rood Srde ebbwct > what tyres of Yeluryy valuy are allowed } Tmebe imperative lang iqistestyteh the return pes, : TE Allows any type excep arrays and Fonekiny — tH ip Uke c@ but aldo allowA ager det rudd Py eda attoews oy ype k — Jka amd Ce do net haw oy fonc-himy bee met Gn hare any Hp e ; f a Semanxes oF cal ont Peturnie a aware —, OttOW, ane athe Subprogram | Call ond Rut . oper told) : qhe — tmpha | ubprogrony Linkage - ay. sont cud § y b 1 on sermonkts of thy oF subprograms muyt be . oe being impdmuted. \ Subprograrn linha. of ane ng 7 ‘ A subprogom CO in a typr'cad Jorguays Fay rua = ———~S 1 euasred wrth rt, 4 achor, Ws + the GH proces must in b unkoxevey — pooom4er - paving method ik yd. clude The fenplamanciaateinn oF VF locos Vannblus ave not Statto, He Cul’ proces russ buco cde Storegt for no locals dellaned fn the called Subprogvan and bind thes (varia bla to Har storage peihie ay 4t ‘must’ Adve the execut on grarus of the eating Program anit - 7 , ca he exetustion | Stars, wa eveything needed 0 Ruume executor of she cabling Program , wnt. Then cabling dnetudes” vegiatey,,, Wales, cp stasus bis, and the envirmment pointer .CEP), or ures ) the EP. e wed | am _ acceN, parameters and tocak Vortably aornig “he exetutin of a subprogtam « sthe calling procey ade rouse, AONE. to svorgher Com rol Code of the Subprogram, an ensure at Combo ,Piace tohen the’ = subprege to the dan vetum +e the)... Proper ere tuto ita Gereplsed : , Syoheoyt wt, - , ) ratty , ig the larg “supper | reseed “Subpregvomy, the cau, proces musk create.’ ‘some — MEChorv'» "mM. sto provide acces | b Wonhoait! varvabLesy that) Ae, wigthle ue, +he vated su bprora « boeru Heo hemanes the Required aware oar a: Subpregram yeturn ae ets Conpiared “Hon hore of Gib Wr Be “Mel, » de tre. Subprogan how parameters Copy , the, sl or in out mode ana. “are impliménied by acim oF the rw? proces * 1S rto-amove, the local Valury fF he asouacd Formal -paramuters' to! he Otte parornderé. S Mext, A must dollocate the ‘toreg2 tyed Foy load Uayvinblu and Rustore the execution Stetuy, of he cally | Nested Subprogram \- fies f aby LceEs = Nisty pth tyne “gence pe of detiniy, Nested Subprogya ma Rubney to “the ; pragyorn « one Subprogram inate anotlun Sub the creator | oF More > the nesting aows for, * Prbduba ond encaph ubred od 8. \ thvengon e only ace of he outer SO Stoker taney + Subprogram's, ,.4% table, within the Slope pat 2 ao Mere .—) “ths approach can improve code. ‘orger encaphulsin, and facrltare darfrmae'on BeheFya ts teed byan = Scope @ encarsubkioni 6 bid aetanuies oy eee nro i] = the winner sulpregram ts only " a.ccehifete’ corthiyy. | i the SwMPe OF ~+he outer” ‘Subpiogrow! = Je anot be alled or upd’ “oiaside of tne tbe te ) | cong | Outersub progrom . i , > thes nesting proutdes aq form oF encapsubsen, ®& she inner subprograms timpleminvtaston! °y, sila hrdten from +he ma” Progra my’ and of: Subprog . ‘ outarde the Nestrg, Pata sharing :- a en } Viaey aver Subproqgram'’s have “qed , 7, “wart bby ond | Paramelers of the ourer rey fi celle pthis attous tov lhe ae: w9 Hho ut ex porcrg the dato. as ae ‘broad progronn,. 4 moducarty and orgond pax It ZOK'ON !, 4 Ong Mexting Subprogrens alews dor a bai day bee = modubsurty and Cod° orgomrzanior « i h de helps group rebred fim cttovaly -togetuor ond Keeps the debe more marntainable duced Complex Hy By breaking dow Compl. teas tnd smollea, noted Subprogroma, the mow program can become more readable and master +o Avelerkeon dh. Rewe of lot varmblea! —_—— ———_ dey varvobtes’ of the ay’ shored Jnnev subprogvam en outer Avlepragton- O theye ae an Ac sxore bin ane ourer nd. inner aubpregroms . aaege Scoping |- pete datced 4n Some progrorarating lorguog As, inven warvolbLey OF the SUN) dubpragrams hove oeheNs xo the sore mested . Ws vnding Subprogrant wy which tne ja KNOWN > dyna geop rg : Rerurston *- evonuek = Nested Subprogram? can, bee Raguratvedy vant Bb waar, c Bubp rasracr: OU "We ranyrous Fenexton Celpanow © 5 oun! defined, where an, inne! dn Some borquoys , neste al Subp og ors coe be upd to” detine anemy ous fantom, abo an as Closure S. . even ead ‘ 5 ; these dency Gn Captune and farnernbey ne) Coment tin which Hy were treater, one Gomoriitg wd? in rbyguoges tow Nested _ Subprogicrs cedun5 | 04 Fv Sarr’ Rack Support dnchovs ww pr | dee owercx); | i : 5 4 rast pa Ht. stlene der inner Cy) Lyqrwe wink pa : | 3 Tern xvy amerporgd >i | Tern Ihr) Closures ouserC wo) result = closuve(S ge they wilt be is , 4 4 * , nye ~ rag a> Rested Subpegrams . prourde, . a power Fut reechon'y, | tor ode PpeBan on, encapsubsron and creaxtvg inpdubs ana Rewoble cade vvardou pagent, re Orenpal Combet. “Blocks rypeiened Specified... IC spe for brit cated blocks. AS any example of a, biwck, Conaik| athe Pouswwing Code Begerist. Lint temp, NAPS shee uu teme,> Wat Drrrevd; leat Cupper] = lat ee . Yelos baie bet [ooerZetemPs-ordels orton) qsominall pw block & specttred ty she. Cs ice, bravon aa Gompoon a. EtodemenfS -+tos brogins wth me or nile ahta, dahunrh ov. ses ae \ . . . : ‘ 4 49 ~the lhe Hime of Beer Varna le 4emP in whe "pending 2 -blook begs wher tonto! eners fhe Nock crcl ot 1 on \ them contyel. eu,’ He beck, 3 i 2 alvartoge. of using Such A locas ts i rok Nno + interfere —eDH any Ore variable vot Hae Some rom, Hot tA declared Sywhine in thre Program |, orenore SpectPecaly, In the inaroonind environment ot We block Blocks dan be implemented b eines ‘stadie - Chatn process for implementing nested _Stuopregrans, | Blocks are tveaked tay’ ferameters Subpregroms rot Be alueyy called from -he Orme "plate in the progrom . q ~Hune Fore , every btock hoy San ceckyorien Record a AN inatonce oF HA actuation Record’ Created eucy t rdA4} pe ; : . tp +me the bleck ' exetuted ~~ © mnt £2". Sk eletat Rae ir eH, BS while C..d tnd a, by cy obrle C++ D4 1 Int de; pons 5 J owe G+) { . ink FI te 4 > Note Hot fF ant QJ ACuPy ithe: Some memory locateny Oe ® ond b, — beaauye a dred bi are — popped omp vhe, Sake when thor blotk ~ eu'led ’ ye oo? { as! ‘ “ » yooh \ Aref iss 1 pike wolpot > ACV ALLOY) record. IngtOmMle Foro” s 4 matyy Up ovate bate Stophanentng’ ‘oatore aro 7 there are ot beast _too “ digtenct. cy in oh ir locat Uanabley and non-—toar Reecronces to tiv’ | 5 cay be imphmented tn a dyrarnia 2scopad © beep Actens— WO. B\ile | + > \ a fe seltal ; ; — fs as ocd vod. Sub30$ to ine UES ab ect “er UNS void Subd OF ine Yr) A eee ky pet 8 . uotd subfl Y PANY Ee Vy BGs es 4 bikes ot, asa i : i Nod maine) 4 tnd vy vy j the Prog ron th wren nm a ayntar Har glug et the apPpeayance pf a Progrem tn a A bayed Voge, uk HS ps nel meant to ke m a par ticubs bag iaye. Suppore the fusocomg Sey ute of Ameten calls OCW S Ea] > Tawi] Tole) tabT] * [sb] [eB] RhowWA the Stack during re executor of &netr'on subs abter hed catttra weg once. ; yp singpon tes pat the activarion Record i Notte a Serve bp puipoae mn A ‘ ue ob rot low gate links, eh \ a agi Acvasten ad talon Os poodles, 4 Consider ste Rbrevences to the w “1D function Sub >. : actvasten p In| Inslonce oF Subs. card “the. Rukereneong 0 wis "une ‘ Sarehing akg stack, by ‘ | | ii wes . tS “the Yeferenta 4p x tA found in the 1. the. aekvasion Reord “atances "on the | | the only exiareng variable ‘Lenn yar name is th\ny thes search tnuol}Ss “Foliowing Your dynamo ra ‘bok [° exam ining 10 Varialste, ami NOR SP the Rukerence to v 15 found._,in Hak 7034 - Receu eens ACHVAR'ON Yecord instance fo. the Subpregrem Susy imp 7 > there aye -poo* ditferencer bln. he eh 204 for nom loa acer in 7 room scphed rate and +he state -Chain method “Yor Siatee Sraped brquag is. Sener ae ee iy wit AU adie Ro bg d edi Fes | ey. a yoamve. scoped “bg, Laon ir \ way se Jdetermmne | Ot Compile , ame. fhe hagth — SS Safifer Chan trot must be Searched. D> every acuivanion Record trakanes, © wh thes ‘chain mar] ° 2 ba Searched. utt the Pirat instorbe,. ve He uot ; ts found. at eA Eh, ae r ‘ > theA th one ee | \ Reason pie Sitped tigen |, ty peealey have Slowey tae pes ton Btantt = , it Paar , \ b raja 4 , | a'are activaxion jecords "musk Sire" thes Pain bf yan Seay fh’ TOL O a aN 4 doy he ae , tinciax, 0) Stata, gcted Lj ove Regueved i vege implementascovy ev re wales, Shawtord acces: FD Shallow ales ra an altemarve implementation anette not an atternakve Semankrs . Aas sated Piewtoryly , The Semanrce> of deep acer, and shew acceys ave dentrent. Jn he Shallow - acces method, Marably are decboud Yn sulprogams are not Stored! in the activasir7 Recor OF those Subprogroma , uw v Fy 7 > The name tn the etadc cetls indicate te progm unttA of the Wartabl. deckoou ov). > BECOUYE, cottth dinamig Scopirg dune fs at MSL me Apeekee hame at @ pen be token)» wisible parisle ef a time, a very dittevered approach Can . ve a , one varatton of Shaltove acces tr to VO Cornpled Aeparare Stack 4oy each variable name mn 4 mp. py YO) .

You might also like