0% found this document useful (0 votes)
55 views105 pages

Computer Programing Lab PDF

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

Uploaded by

gahajjsj
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)
55 views105 pages

Computer Programing Lab PDF

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

Uploaded by

gahajjsj
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/ 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 porDW 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 useTo 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>a>>b; coutcStop\aseuss [9 |Program 4: Program to swap two numbers. Hincludectostream> using nanespace std; int main) int us couteu; coute using namespace std; Ant main() { int div, q, r, d cout>d; cout>div; qed/div; redXdiv; coutProgram 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 ooSExse wR are print foxIon levenewnemsoh 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 shesProgram to swap the two numbers by using class and object #includeciostream> coutcc"Enter the two numbers cin>su>sv5 coutc using namespace std; class fact_num { public int num; void input() { coutonum; ) 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/ Noiincludeciostream> 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 iPeogrem26 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 Dectane etary loin Dasa member or eee Sep 2 Crete Objer SEP RE dectane Aes Mpedpier — SrepS: Cal guretiony topr Mn a ep 6: ‘ : 3 ae cep teo e rend Lait Rn Sunein Lok oO "i means ben & Srepti Sum: > 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; } void show(){ 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 (xiRoaguam 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 StopProgram 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 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 parecumberycopy 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 Stopaccey 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 “rotegram 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 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) GopFurtion 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: “avoid 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 Fiemmpese 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 paProgram 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 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 coutdisplay(); return @3.— Preogevirn 44; Paegtam Algorithm + =m: bee Farckien Stop £: Stone an ae . Siep2= Dedasye Cars frinten with ante ™ Shp Bi tee Areers Epes pice, « SRE: Prarivate —¢ cimin prrivste Wp ond; Within poli peda w= Jato doth fore PSE Biden sr volux yp tergin 5 barasitns 24 _ Skep 6 ie O Arse ; Caeahe okies pont ; Set lounte pointer *P ; p= Spat; Shep $- Coad furdion be pict autpur Stabemenh pursnose Pos ditplanc); Flaschat Sp %- Stop q gx Class Poinkes, A 4“ a pias d deb; @ Pointer port, S Joiner *p ; b= pa; © ptr sroa € 4160) 31) " Lanapi on pro ditplog Y @ mtr te = Butpt = gensCC Bargam:s9 = Pangan rn om antpine Aesevinn a qrembre Finction eps dade ember aq Fed: Deebar Clay peinber wit Ship 3: Sob Rees epeigier eet Pestveabe: Jab pov ores Bot sp PR Wy = sok teed ~ iny PS Mintare obyee caitn prinder - Lp Gintay PAplayc SEPT COL Beatin op dsptoy Oudpur Skpt+ sup wn) Sane @ Cay psorer © neivay a} Pardic : this a P =P, Ws &: i thigo Fed j (0) poder pry pidrer 2; Pp Saplayes ® Spur are value df p = d= de eh fay de k= 009 + Langth = b,program 5 ; aie OND Wed program on virtual function. virtul functionpp > .. 2 , 1 #includeciostream> ~ oe 2 using namespace std; 3 class Laser t Ss s public: 6 virtual void display(){ 7 coutdisplay(); Diet 27 return @3Porgaom 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 ... 1 #include 2 #include 3 using namespace std; 4 int main() et 6 fstream foutin; ae foutin.open("myfile.txt",ios::app); 8 foutin

You might also like