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

Computer Programing Lab PDF

all c++ lab works input code with outputs flowchart and algorithm

Uploaded by

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

Computer Programing Lab PDF

all c++ lab works input code with outputs flowchart and algorithm

Uploaded by

gahajjsj
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 105
howe. B2iptka, fa fro. So, The Poceno. | pate ‘Remark pa Te peg tae 3 re ‘Ore aa fee Rumbas | 03 ag| cates. |e 7. Fi he an 3 ond relat i oar Saleses 0 a | oF a [i a Te theste (Cenk 2 ane ee as lo ig (rink @ Piamid | 10 petteun IE Te chest (| Pati? ramber| 42 in, [Tepes svkme | ay clay Cobjed ae To cal foe mimes | aa) IS | cag cos € aoe 3 40 whe too | ay 10. hg Clann ate [ 7 [ERE Ihe fasten E Seep wr 15 le [towne a Laing clay ardegpap| £6 4+ [Roy 90 ns td a, Ain" fh nativey por DW 13. | Te Find Pactersor| + Q_number ib B-| & thane me | 79 Crhered pune nr Be: | print « patem | 9, jusing clags objet er [Ana pauline | >, ramier aa [To sere on dipoy |, foo nme 23. | Tocauare mattipe| & Objents dhenectoy | 23 Biceictinre ons swe? | PAT cath Pry | 24 GAs | £5. | Te dehine the anation inside Phe Ctays ese BE [0 eee re sin | 3p oarite the tas peas P| sig: natin zt bas. [ Te cxene a frend] ag archi on To coware bredy| 29 eee Te imprrtent En | 3, 3) f 32 “Te implement 33 chin dwere Te Sheva the use To Creare an acter Page No. -Roll No... 35 Date | Teacher's Sign | Remark axis usiryanjal °° Pt [Roe acne | 34 / pe some 3 [ » Sawa Bate |e Ar ee al » | eee Cc iene ence | 4 As ae pee BD) Bxsgrum 20 anbinity | 46 reb'07) sana 6) ee Fonotion- Paoguam on ‘ Lees wigs Lyretion: Div. Roll No. Subject Title Page No. Teacher's Sign | Remark Rarqeam on Clay, | dempinve Be andy» [Resarn 0 fine | 53 i Reganiin Hie | &% Program 1: Program to print a message. #includeciostream> using namespace std; main() { cout<<"My Friend”; } Stale eg CAfeneel by wer Program 2: Program to display the two numbers. Sincludeciostream using namespace std; Ant main() { Ant asbs coutc<"Enter the two nunbers: | cin>>a>>b; coutc<"The entered numbers are: “< Stop \aseuss [9 | Program 4: Program to swap two numbers. Hincludectostream> using nanespace std; int main) int us coute<"Enter the first number cin>u; coute<"Enter the second number"; einov; out<<"\nBefore sap numbers are: coutc<"\nAfter swap numbers are Program 5 Program to find the quotient and remainder. includeciostream> using namespace std; Ant main() { int div, q, r, d cout<"Enter the dividend cin>>d; cout<<"Enter the divisor cin>>div; qed/div; redXdiv; cout<<"The quotient turn @; Output: Enter the dividend : Tae The remainder :2 PS C:\Users\Asus\Desktop\Priyanka> Program 6: Program to reverse a store number. sinclusectostream ng nanespace 5 cin» Prog) Program | E 5 a l ™ Ro by eee 8% (rev 10) + Teve rs taf i v tp. ) w’ natural numbers, Program te calculate sum of Enter the number of tern e Yhe sum ides: 1830 S.C: \Wsers \ASUS\Desktop\Pri oo SExse wR are print fox Ion levenewnems oh a py? + To pot Revo germ 04 Algsstnum lone Fyrom, i Pear) Pre Cede ferminutt rye nu : Depp 2! ! Gb Jnpur : Sep3 i feets yids ay ser Step4 s sont yt 5 cee grt Shp St The number fyremtd i's Sep 6s eee umber Pyrarnif Shep Fe Sp Floocronep Eeomple W Ses 4 Cor) QD pesst- one seviy eile ee amber fr Pyramid 4 as, / . i fy pyrenid Sages { j i CO the number yon of 1 Pyra i oes . Qa j 333 4uy srete 666666 1739.4 Ys shes Program to swap the two numbers by using class and object #includeciostream> coutcc"Enter the two numbers cin>su>sv5 coutc<"Before swap: “ using namespace std; class fact_num { public int num; void input() { cout<<"Enter the nunber :"; } void display() { for(int ix1; icenum;ire) if (nunXi==0) coutccic<","5 } main() fact_num ob; ob. input (); ob.display()3 return 0; for(int a1; jonum; ) void logic() « origenum; while(nue t= @) { temp = nunXi0; rev = (rev*1@) + temp; rum /= 10; ? Lf (orig == rev) { coutcc"Entered number is a palindrome nunber"; ? else t » } coutcc"Entered number is not # palindrome number"; main() palin_um ob; ob. input (); ob. 1ogic() return @; Cc: : \Users\ASUS\Desktop\Priyanka> cd" ter the number: 334543233 ntered number is not 2 pa. Wid (nv igbt temp fam sien 10 | ee Ja 7 Ou a ‘Mota Lindman 9/ No iincludeciostream> wincludecstring> using namespace std; class Car public: string brand; string model; int year; int main() Car carobj1; carobji.brand ="TATA*; carobji.model ="TATA TIAGO"; carobji.year = 2016; Car carobj2; carobj2.brand ="TOYOTA" ; carobj2.model ="TOYOTA CAMRY"; carobj2.year=2012; Car carobj3; carobj3.brand = “MARUTI"; carobj3-model = "MARUTI SUZUKI BREZZA"; carobj3-year =2022 5 andcc” ** “ ing namespace std; ass outside_class public: void myMethod(); //methode/function declaration /Methode/Function declaration outside the class oid outside_class: :myMethod() { cout<<"HELLO FRIENDS”; } main() outside class obj; obj .myMethod(); HELLO FRIENDS a PS C:\Users\ASUS\Desktop\Priyanka> i Peogrem26 5 Reog Algorithm : é > snd menor Hert} SPT: Street yp enter ET Stp2i Dectowe cen °' Step 33 Cauare obfeeh Ch) ine ole i Sep et: Dectane -farstion ord Bep 5: Cau fanien Tneur grarernend Shep 6: (att Jarvion 40 pon? Step ay Sop ii) Decto butside_yide Hen ‘WE 1) Obdae Objet = obf Ce) Decteime ‘Vold oubiidencteus @ Tope" HELo FeIENDS” UW) abjemyrerred J oom Fanon | Voted oudsrcbee leery ea (vi) Osha HELLO PReren gy (wrip Soop #includeciostream using namespace std; class create private: int a,b; public: void setData(int u, int v) { a=u; bev; void showata() { Cout<<"a = “< MME Cade’ » Step Cob) urshan +o pulpur odoli Sepa: seeenirp le Ploschart W Saat G3) CY) Clay Guetre oe CD (auuate ct [scons “od \ @) pavares prrt'e member fundivo __} (Y) az20, beso ce mek ah) oa Bea =a wb Friend vold Fin( Csceate ¢ aie a eeernca saa yey (ID Sum= C44 eb = 2ot8o ee ie ees “Topar number if LY") Rincon coll peas C4. Serdata (22/58) — : GI end Fonction Fun Ces) ) Qubpar : Sum = ae (WO. Shp + “Yogram 29 Program to create base class and derived class #include using namespace std; class A { public: void fun() { } cout<<"Base"; 3 class B: public A {}3 int main() { Bb; b.fun(); return @; Output: denveel clays d . ye bye 9" Rerogewm 29: Ae cone Algorianm : st pectow) mbox Pincha | Br stam on Oe , Steppes Oetlore DARE aunon » 19PUr Srep3; (au & clan 1g (Derived © tax) oh Baye chars Spur peitane StepS? wren objet Shp 6: cate function to owpyr S'epys Srp. ghaternent « Pec yyple + Finathos ’ WU) Shane GD CtorsA at Cid GU furvim Tn por oa ££ : = Bae” J ; ( Class g; pubdic A = sinseenent// Ww B b; =i Rp Retforchon tolaphes: Dertare elas; B Storermens Cenved c1993) with. , ” Les. oe bfint); Baye 4 q WD Base (Wii Sop / Qurpur cteverey Bin a” public: void display()¢ COut<<"HIT Guys! >; } void show(){ Cout<<"\nShow™ ; } a class B:public A { public: void display() { cout<<"DISPLAY"; } 3 int main() - { B obj; obj.display(); obj-show()5 return @3 } a Ue Output: Te implemen? fanoio0 aver HIN * Pocequarn 30.) © vm Algorithm t en Furhion —_— no’ ' 3 nso ane PO Stepat Sank go at clers Se Dec lewre sented Rec RKne oe hope gtader rae be Clots . ; antag Cowie eas) game on Oy - pay Detane ag IS P noo Step StOertey Member furnm in a eps? Coreaure Objet B Step 4s Can Fannin ‘to input Se Sicp Bs cous fircnien to Gueper fede Sk po! Sip Exar’: Fowchaut bg. e Stout Staak ® Clasp = UO) Wold eb pay cy Dectane cers A . Liem Wasa member CY) Tnpat = "imhuYs © [and rmomber faction WY veld sravsey wee ipegcy ©) Trpap =" shoo” Wid show c) (VD class 9 tpanste a Wid Boye ee fae bj "Showa? Co Weld ahpey6) peaar CO Enpub = OiSpLay; Ceelae olor B ob ose Clary Eamecesiaiel Oip lent ° (x) a0) Pyklrion dy Oude Starermene Gbjotisplay ¢)," chal (xi) Gurpub ie DiS pLay Show (Xty Stop ; friend class 8; class 8 { public: void shoWata(As t) { } COUT Moet J rey) [De tate as 1 [wee jest rail viid ¢ | haters painting * pubic anirg = bi) atone piing [iets sen] () Tapors "6 pachern”« Ki) Cal function te @utpur [pues (xii), TF onigineued iho j TS au universe te ee pathern p. vy) tt 89 Mondale * public pains Wi) Mendota po; (VW Trpur:" 34% oll += Universe (xi Roaguam ge; Te leplemen for Alsentom Sepa Sra Cee SPI? Dectane voutuble wi iaiy ‘HR Or, ¢ SP RE Tape nby SHP AS et k ‘ io seeps: st Weosinbie 1c4Ml y with Dwble oP ae Spes Trp x» fy a S*P Bs me Step 63 Quer Tareger Decimal Spd Srp Flouschatt Exomple = ee D Stop Dethie Yarietble sith int Datatype Ww fod pluseane( intn, int) CY %=90 sy 2000 a) aty = 9otlve= 150 W Dowble plustunc’ povse 2) Double y WD ne ag, Ys 55.5 ip ney g iy a Z-245Te B38 Pt ENTE Hep: 190 DEUIM pL t Boar ete L bectar vantable tity Read! (yy Stop Program 34: Program to show the use of copy constructor using namespace Std5 class cons private int 8,b5 public cons (int s, int t) ass; bets coute<"constr arameter"<<"\na a"ccacc"\nb = " a uy hoo vameble s@t s ins f hie * au 5% t h Lonh Clon ne e f umber F ( Dectar 13 lth’ Duss, manner og PN _therbey funchion Rt beg fonsrrucky Sf ponsamalery ar 3y Coryrrectvy 2 POsamuenbe y Or hy hz33 Conytree Wy 0 parecumbery copy darren: pow sre ure oF g Ragen Po” foeqvem 35? ct Heo ps2 Algo sith L membex Furstlen ard Shepa: out vk date member pr: Dectaur cto Srepss t elt dbjast S*PA? Coens tonctruster AO SPS: Cast Laction 40 Popuk stabernent T DP OD Core Wesnuckey AY Sepa; CU Lanetin to jnpsr sraterneot D Sep s: Cost Fimesup te OU4pue Staternent - Srp ae hee Bla rnple,* Flowschotoup W Sout QD) Cas A 1) A obss, obj ed Dectame eters cain c Dosa member ang Ww Ay 2. (WH Toper : Tam \p Contry [ Creat oper | (vi) way Obi, dbj2 | (vil) Tapor tT om in Dermuour pcccecesaa (vy Gutpur; ee AD om in (onshusty 4 TD amin Canstruckey Topur Storenent 7 Satan in. Oevtteney Lam in Oesrrucdex Stop accey 24 Obes ‘ine an pssyoam fo curente eee SS a bew farktion + Sep 20 4 sph pate, member and run Stepay Dectasce Cory Cit SHE? Coeate abjer : ter ble Ro }n parte Be a nig ok ate (peter “PSY Topor » vy SPS? Qubpus : Exeor SPF: Stop ae areens Sf Example *- D Gras Flowehaset (D Gast See (iy cer Gib Pabue? Inte ee usa), Prrivol; Pate memoer ane indy GY Inper ** ; Y=90 = eg o ee Oeslane vata a pataaaee ota (Ore “rote gram 37 Program to show the use of nested classes #include using namespace std; class A public: class 8 { private: int num; public: void getdata(int n) num = n; ¥ void putdata() cout<< number is "< and mumber Sune ey dota mum orrbey 2 them, p win datam ePHL Cseaouke Objee SPS: Catt fonaion to inpub Number = Shep 6; Cote Farsion fe culpa number Step ai stop num Bape: Ge) W Steer Destoure clasp vith acess airetcieratey: 2 clon ¢ vine ThE Cla Member Fumes ci (iy ANS obs (WY) Ippar Rumbor at W) Gatpord Naret clone in Ott ae Bree The runber 1S lo AL58 obj Ny S439 ¢ Shrusk . m ui ; sh; Toe 4 poe Es Algeninm + Sep Lk Sth Sep ot Declare ord membe. Cie yh gabe. member nd Ore crue UH = Sip 52 Gorente ebjere : cae onal Flee dada sn Sep hy loreake truce vor th 1G Pe o* ShpS; Call faretion tp input dhe names Hep b: tatt fincion + Cutpsh he rebel Sep3 2 Sop Proochostt Eyvemple : eS Vy Stans Gied) ws ae GD Grract poste [Dectosse srret ain fi) 5 Sa Ci pack Py Liembuur Aimchin' \ GO tnt model enum ! Fine postin ; Cheote 0 bjet Fiosk (08k: __Pouck pa See pa, model mum = 29u8 4 pis Post-nsim = C988, pis tosk = 2980000 wy) Output : Medel} 29g Pur! 6999 (ost 1 28Se $006 i) Gop Furtion to oudput CI acebdota @, wy} Coos ch ‘La Showdatacy Bid a=9 , boa Ge=azo , b=) Qutpat numer / fs os = a © buspus Overtovcding Oy Stop: “a void setdata(int x){ 3 2X5 void showdata(){ coutcc"e = “ ae a Bota Seria Eo. GY closs mgclais trembex function __\ (i) mydars: M4yme (MH) vaid sehdota Cat) Gre (v) Inpur 4= IF Bais shay Imgctass _emi_) me (vi) mgclass dperaty erCint) wy mytlay hemp; temp = att C9) outpar Naeig" "cS aa Ovestloaoti Fie mmpese FeCerion. Algeninm: Sheps: Stawet Sept; Dedare ota Olt p dase member 8 joole jaw SPT? Corenre objerh vous " ingle Sep ay sey member fons enna 2 oe Sep S 3 cam forsion be inpy > Sep Pi dem Po Giapur tne frcsuernantest volicg ae Four farcion Sep 9: Sop Place poset wo S+ast WD Clas integer iD) iMeger Ob (IY) void Sekctaba ¢ tnt ») ion Ww 3 ) Input 42/4 (nT oH ee Ope.etar trl) (UI) Integer fe mp, ‘ fempra = +tq 7) Oupor ariq OV ev och ie ba = 6 7 , pase To Implement Po Poxquamy2: Te : en fanchun Maine + ._ ee | Shp as peur : san dove mer My Deitanr evs Creare odfock SNP SE ct Grim te inpur 4 Bie otk decsement M9945 gpenatey = - int) Sep 3+ Diese. 52: Shp3i @auy fanction to 0 bpab the eps; Sp Flevserasit ep J phestasre ctor; cin @ b rember ofl Lm iB a Corense Objep SMteder mmf a r drevtment of jrgle Vv $e premesy Fervimn win sin perarer Over a putabie ink © jen Pouarneber deerernentea Vee ee eee Tee wb Integer cpany —— GH [ vera Setar Cntx) | ; | (GO eae ee all (8) tapas OE OVer (ask ing pa Program 43: Program to implement predecrement (operator overloading) #includeciostream> using namespace std; class integer t private: public: void setdata(int x) t a=x; void showdata() t | coutcc"a = " 5544 | Poon 9637016 | (bop - program on embiguly function, 1S emuyuny.epp ¢ , COONAN BUN #includectostneany using namespace std; class Main { Public: void Display()( cout<<"class Main\n"; } % Class Multiverse { Public: void Display(){ cout<<“class Multiverse “; + & Class cos : public Main, public Multiverse { public: void fiction() { cout<<"class cos\n } hb int main() cos Portrait; Portrait. fiction(); Portrait.Main: :Display(); Portrait multiverse: :Display(); return @; Gunition on Aenoiquilyy with Dectome clas Nein ¢ Clon muslin ee rember Fumnon + SHES? Gate Fynaian yo input Stobenea THY? De ctaree ¢teuy tos deed chars Off chess s pumice Mein » Pale ANE SEP S™ Guu tunuion fo tapab) Stabe Mp’ Curere on ober: = Povtreit SS GU Fretien, peipeint Omth coy Main L Chts Mottiyen, aap rigfanercen SPE Sops Fewcroet Buy Ren 3— = Stone @ Claw pain Delana class Mein WD Cat Fantien Papa [iret =f Clay Pain te WY Class PAutiverde (WD ba Function po inpuk st Chey Meutivenye (YD Cron Cor public Mons pust'e Powhi LY) bes Porrtie , PANE, Het): portasc «Drains pyre t a TNA hirer vebrn 0; CH» Outpa — Elany (os Clay Sain Clery Mudtivone (11) Sop nlergr nal hel : wm on Baeephie Rusyewm 49: Parogu Algerians SHY ae scatch fy Dwet Enver ane sy tial won Hy ond, «C Mabe, PPS Creare hoy beete ¢ \ dns print SOPH: Condition (age > 18) va ae © obj Atte quent you aww Sen meee S05) 9n sine catrn ode SIF Sees Ges 0) fr Cath font dns wy 18 seo POR Oi) You eres) be ableny y Cod. iy...0 Sateen uty) Srpir Shp. Pact Run ;- 2) Sra 3 arte tee mae: 3) Cond tm ee, TF Aer ay Geniey Flow) chawt : ~ pa muse Be Ohta =) 15 yous ode YD Apui0y Enrmy yous Ayo 23 BQ O43 19 oo ‘| PEE granted - Goy eur oly ce tao : 6) mp - program 48 } a} sadintin hyn program on object pointer. © obj_pointer.cpp > ... 1 #includeciostream> 2 using namespace std; 3. class pointer ns a s private: 6 int paw, ? public: 8 void show(int 1,int b, int h){ ° p=1; ae web; a dah; 12 } 13 void display(){ é 14 cout<<"length = "< .. 2 , 1 #includeciostream> ~ oe 2 using namespace std; 3 class Laser t Ss s public: 6 virtual void display(){ 7 cout<<"Light Amplification By Stimulated Emission Of Radiation\n"; 8 9 } 10 i}; 12 class Intensity: public Laser a3 { 14 public: 15 void display(){ 16 cout<<"Energy concentrated in a small region\n"; 17 2 8 Oe 19 int main() 20 5U 21 Laser light,"p; 22 Intensity light1; 23 plight; 24 light .display(); 25 Light1.display(); 26 p->display(); Diet 27 return @3 Porgaom 50; fusgaem on vive! Foput Saromeor 2 ee ite aye) Fobensity tights; Pe hugnyy, AR te Cig Oo @ Seputs Lyn Amphbicaion by Mmatoed Fenisys °F PactiaHon ‘ Frgugy (Nr en rated jROrmatll region Enorgy lntabrabed [A asm region anchor + Algor nem Skpt Sahm ber aed mombet Funchoy Dep2) Dedtame Clas loser with data mem M8: Gay Virtuo Fanci Set Taper stotement Ne cotn ea Hep St Derase derived clay sorensty Be and membe funchon: Sep 6 Inpad Starerment. Sept? Goete On bye with epoolntese SEPT tau Yusmin fo outpat ciroment Shep 9: Steptar sop - plows cha Dow Run. Cu wetane Ulery Lek © seu Mimi ena Ca Lager “ha oe i Toph stuberneat L tt Ureraad funckon Clon Savers ity ¢ pablo Laer _ {arpa Satermene Z J decor dedverf Clary frven ty bPebue Laver L A ‘> Program 51 en © pure_virtuatepp > .. 1 #includeciostream> 2 using namespace std; 3 class Tree Cet 2 public: 6 virtual void t1()a Pr os 8 class plants : public Tree Baad ae public: a void t1(){ 22 cout<<"Lavender plant\n"; 13 } 1 15 class flowers : public Tree 16 \ 7 public: 18 void t1(){ 19 cout<<"Sunflower\ 2 } ‘: ma oh : 22 int main() 234 24 plants p1; 25 flowers £1; 26 #1.11()3 7 p1.t1()5 28 return @; 29. Output: Program on pure Virtual function, S99 52 Ged Pave virhuat famaion vithie BAF Beep Dectare Aeuived clay peak nd membuy furshin : 5: J BPS Ca Lonation wich rave rue 04 'sorme tae i pare clos ard shpub Stupemment wih lets home BEREORMMUAeHdias, puny of On TH 7 ond Memb fan ch pH hj Same a4 Sep 8 Coreare et Pian ps a Powe &; Stes) Call Farchiins fo Qurpur the storernert - Sep tos Sop. Day Pun © Soot (QQ) don tree (@) Virtwat weld tO20, Clary plank + public Tree void fit) ® dass Hover t pubhe Tree void 42() plant pty Flow pl; Fino), Pao), ) berpur s Santioort Loved plank © a Rene Res yam a9: Racogram on class tempdole - Aloriine Seet™ Sten ond Sede Pretae clay eympe usin deta memer QI Dibine tempt, — Thpe ae 1p no meIgor” Spe apse vabeins om See even, Det Cocean an obpet Ste? aN fntin display the Output - SP Outpar Ste! Sop bay Re O Stuer Clos Sample Type ob (A) ener He veleUNs = 16 5 Enter treveley 200 FT By2 4 Sampe. ... 1 #include 2 #include 3 using namespace std; 4 int main() et 6 fstream foutin; ae foutin.open("myfile.txt",ios::app); 8 foutin<<"HELLO EARTH! !"5 9 foutin.close(); 18 cout<<"done"; ia return @; 12.0 Output: ao. See myfle © myfile X | m File Edit View HELLO EARTH!!|

You might also like