OOPS Practical
AI-enhanced title
#include (Creating class Complex class Complex { public: int real,img; Madd function to add two matrices void add(Complex c1,Complex c2) { int x,y; x=cl real+-c2.real; cl.img+c2.img; cout<<"n("<>a.real>>a.img; ny ee a and imaginary part of second complex number: cin>>b.real>>b.imgs c.add(a,b); damultiply(a.b); getch(); ) Sierload new/delete operators ina class. Giatb) Write a Crh program to, #include #include #include class CustomMemory { public: void* operator new(size_t objectSize);//Overloaded new void operator delete(void* ptr); //Overloaded delete hb void* CustomMemory::operator new(size_t objectSize) { cout<<"Custom memory allocation"< e public: int roll_num; void print) { cout << "\nRoll Number is "<*! ptr=205 sp->print()s getch();(@ Write a CH Progra the Data Members. ‘finclude include class fibonacci { ong int a,b; //data members “ public: fibonacci() //spe { a bl; } void fibseries(int n) //member function { i tor cial member function construc Resultant fibonacci series"; An"; next=a+b; //Expression cout<>n; Efibseries(n); getch(); kOe Pro} include ‘ #include class base isin, gram that illustrate single inheritanc Ble base class. ren atic int a7 ter the value of x & _gerive : public base ys Usingle derived class private: inty publie: void readdata() cout << "Enter the value of y = cin >> y; } void product() Ih { cout << "Product =" #include // create base class1 class student_detail { M access specifier protected: : int mo, sum, i, marks[5]; access specifier 19IE.Y.B Se. (L77.) ~ Object Oriented Programming with CH (Semtl)sri pracnnent s eee pois wont etait) © Sor se Dinter the Roll Noe t= eM eee aye oe enn seam ® Bnter the marks of ive sulest use for loop for (Oi) cin >> matkstils sumeO; for(i F< Si) store the sum of five subject sum © sum + markst create base class? class sports_mark public: void get_mark() t cout << "Wn Enter the sports marl mark; /* create a result as the child class to inherit functions of the parent class: student_detail and sports_mark.*/ class result: public student_detail, public sports_mark ‘ int tot; float avg; public: !/ create member function of child class Void disp () {ere gum +s marks tot /6;// total marks of six subject /6 1s At Roll Not " << mmo <<" \n Total" << tot << endl wv \p\t Average Marks: " << avg: an object of the derived class 1e base class ' rr obj; ereate imber function of th rest jy call the Mme obj details obj get_markOs obj.dispO+ getoh(s a C+t Program that illustrate jnulti-level inheritance. writ a .cjostream.h> include ginclude #include class A //single base class { public: int x, ¥3 void getdata() { cout << "\nEnter value of x and y:\n"; cin >> x >> Y3 } h class B : public A //B is derived from class base { public: void product() { cout << "\nProduct="<< x * y: } h class C : public A /IC js - { C is also derived from class base Public; Void sum() { CUS MSU ce xi Coa 1 govt co Hlobject of derived class B \ it Hobject of derived class C jl ye etdata( onl oducts pjz.cetdatas —ydeiotream! sh meecconiod he cass alpha { int X3 public: alpha(int i) { xi cout<<"alpha initialized\n"s void show_x(void) { cout<<" b class beta betafloat i) { cout<<"beta initialized\n’ } void show_y(void) { cout<<"y= "< #include class student { protected: int roll_number; public: Void get_number(int a) { roll_number = } im PULnumber(void)oi oo oll No:*< cla: { char name[20}; float age; public: Person(char *s, float a) ( strepy(name, s); age = } Person & person { if(X.age >= return x; else Tetum *this; } void display(voidy { S person, + Breater(person & x) ge) coutser "Name:"<< #include class Base { public: void display() c cout<<"\n Display Base"; y virtual void show() t cout<<"\n Show Base"; 3 ‘8 class Derived : public Base { public: void display() { cout<<"\n Display Derived"; 4 void show) { cout<<"\n Show Derived"; h void main() t msWOO ENLIST, mare wit om 4 aso ree Whew Rase Ny Derived Dy Nase *hptrs cout <"\n pte points to Daseln"s pyr 8H byte dlispla 08 byte show Qs cout="\nln bpte points to derived\n"; bpir= &D; bptr “display 0); bptr show 0; getehs information regargiyy 7 (b) Write ‘a C++ program to design a class representing cine: classes having here’) digital library (books, tape: book & tape should be sepa adding new Kem, lsat] class as media), The class should have the functionality for fy - ism. deposit ete, the program should use the runtime polymorphis! Hinclude: lostream.h> #include jude jass media protected: char title[S0}; float pric public: media(char *s, float a) strepy(title, s); price =a; virtual void display(){} h class book : public media t int pages; public: book(char *s, float a, int p) : media(s.a) t Pages = p; ) : void display();e post ties ible? MT etc * 5 Hoat a, float t-mediats.a) ime 4 ya displays couts<"\n_ cout<<"\n Pages:"<>title; cout<<"\n Price:"; cin>>price; cout<<"\n Pages:"; cin>>pages; :>title; cout<<"\n Price:"; cin>>price; cout<<"\n Play Times(mins): cin>>time; tape tape (title, price, time); rrr 287prcticls te 105 } yeturn (8895 ) void displaydata( ) cout << 8th; } ye ‘void main( ) { string st = 123; cout << endl << s1.displaydata( ); si = 150; cout << endl << "sI="; sl.displaydata( )s string 82 ("123"); jnt i= int( s2 Ji cout << endl <<" i=s3 cout << endl << "is" << i geteh()s 289 Hinclude #include void main() { int i= 525 float a = 425.0; float b = 123.500328; char str[ ] = "Dream, Then make it happen!"; clrscr(); cout.setf{ ios::unitbuf ); cout.setf{ ios::stdio ); cout setf{ ios::showpos }; cout << i << endl; cout.setf{ io: cout.setf{ ios: cout.setf{ ios::hex, ios::basefield );< = ait Sain tw Implement Mtn, Calculating length of the string, 8 Lerten cena ate eae Stein ae wat ar tring SOF rmter @ SUPE {trea file.opent"t for(int file.pur(strinel EX’ [ios::0ut): file.seek (0): chy fite.get(oh couts yinclude void main() char source[ 67 ], target{ 67 ]: char ch; cout << endl << "Enter source filename"; cin >> source, cout << endl << "Enter target filename"; cin >> target; ifstream infile (source ); ofstream outfile (target ); while( infile )* We 202 vas infile.get( ch ); outfile.put( ch ); } getchQ; 4 (© Writes GH program (eer file): the object of a structure! #include #include iinclude void main() t struct employee t char name{ 20 J; int age; float basic; float gro B employee e; char ch = ofstream outfile; outfile.open( "EMPLOYEE.DAT", iost:out | while(ch = "'y") { cout << endl <<"Enter a record"; 8 cin>> ename >> e.age >> e.basic >> e.gross; outfile.write(( char *)&e, sizeof{e)); ‘cout << endl << "Add Another YIN"; cin >> ch; ) outfile.close(); ifstream infile; infile.open("EMPLOYEE txt", while(infile, { Cout << endl << e.name << "ys ) } jos::in | ios::binary ); read((char *)&e,sizeof{e))) << ne SABE << Nt" << e basic void test(int x) throw 1.0; cout<<"End of try-black\n"; } catch(char ¢) { cout<<"Caught a Character\n"; } catch(int c) { cout<<"Caught an Integer\n"; } catch(double c) { cout<<"Caught a Double\n"; } cout<<"End of try-catch system\n"; } void main() { cout<<"Testing Multiple Catches\n"; cout<<"x: test(1); cout<<"x° test(0); cout<<" test(2); getch();, } 20/F.Y B.Sc. (I.T.) - Object Oriented Programming with C++ (Sem.-Il) 1\n";geteh(s } ‘o create Simple calculator using Class template; ite a CH Program t (a) Wri #include #include template class Calculator { private: ,als ee 295 num, num2; Pre iblic! we Ncalculator(T nl, T m2) num! = nl; num2 = n2; } yoid displayResult() { cout << "Numbers are: " << numl <<" and " << num2 <<"" << endl cout << "Addition is: " << add() << endl; ° cout << "Subtraction is: " << subtract() << endl; cout << "Product is: " << multiply() << endl; << divide() << endl; cout << "Division i } Tadd( { return num1 + num2; }+ T subtract() { return num! - num2; } T multiply( { return num1 * num2; } T divideQ) { return num1 / num2; } B void main() { Calculator intCale(2, 1); Calculator floatCale(2.4, 1.2); cout << "Int results:" << endl; intCale.displayResult(); cout << endl << "Float results:" << endl; floatCalc.displayResult(); getch();includ ey) return x3 else return ys, void main() { ‘TClassMax iMax; // (100, 75); int a, b, is TClassMax fMax; // (90.78, 750.98); float ¢, d, j; cout << "Class Template Programs : Generic Programming : Get Maxii ‘Number \n! : imum Number \n"s cout << "Enter A,B values(integer):"; cin >> a>>b; / iMax = TClassMax(a, b); i= iMax.getMaximun(;— SP°St°s2° practicals cout << "Result Max Int : "<< i; cout << "\n\nEnter C,D values(float):"; cin >> e>>d; {Max = TClassMax(c, d); it fMax.getMaximun(); cout << "Result Max Float : '" <You might also likeC++ Lab ManualPDFNo ratings yetC++ Lab Manual26 pagesAssignment FinalPDF100% (3)Assignment Final94 pagesGeneral C++ Cheat SheetPDFNo ratings yetGeneral C++ Cheat Sheet6 pagesOOPs Complete FilepdfPDF100% (1)OOPs Complete Filepdf52 pagesOop Exp 7-17PDFNo ratings yetOop Exp 7-17140 pagesOop Practical ManualPDF100% (1)Oop Practical Manual34 pagesCPP NotesPDFNo ratings yetCPP Notes95 pagesMayank CPDFNo ratings yetMayank C83 pagesC++ File.mPDFNo ratings yetC++ File.m45 pagesDocumentPDFNo ratings yetDocument68 pagesAnna University (Syllabus) V Semester (EEE) Cs-1261 Object Oriented Programming Lab Programs C++PDFNo ratings yetAnna University (Syllabus) V Semester (EEE) Cs-1261 Object Oriented Programming Lab Programs C++32 pagesShafaq Assingment of C++PDFNo ratings yetShafaq Assingment of C++23 pagesRelational, Logical and Bitwise OperatorsPDFNo ratings yetRelational, Logical and Bitwise Operators40 pagesOOPS Practical FYBSc - ITPDFNo ratings yetOOPS Practical FYBSc - IT46 pagesOop Practical Program ?PDFNo ratings yetOop Practical Program ?41 pagesClass and Objects 1.: Student DetailsPDFNo ratings yetClass and Objects 1.: Student Details35 pagesBCA C++ Lab SolutionsPDFNo ratings yetBCA C++ Lab Solutions28 pagesPranav Pankaj 18107024 Oops - Lab.recordPDFNo ratings yetPranav Pankaj 18107024 Oops - Lab.record33 pagesAssignmentcpp 1PDFNo ratings yetAssignmentcpp 176 pagesPsoop Lab Internal CodesPDFNo ratings yetPsoop Lab Internal Codes32 pagesJava Slips Solutions PDFPDFNo ratings yetJava Slips Solutions PDF18 pagesOOPS Notes-Module 1&2PDFNo ratings yetOOPS Notes-Module 1&242 pagesC++ FilePDFNo ratings yetC++ File29 pagesLAXMI C++ JournalPDFNo ratings yetLAXMI C++ Journal34 pagesPractical FilePDFNo ratings yetPractical File19 pagesPL FinallPDFNo ratings yetPL Finall21 pagesObject Oriented Programming Lab MannualPDFNo ratings yetObject Oriented Programming Lab Mannual27 pagesComp218: European University of Lefke Faculty of Engineering Department of Computer EngineeringPDFNo ratings yetComp218: European University of Lefke Faculty of Engineering Department of Computer Engineering13 pagesC++ Revision Questions - 2PDFNo ratings yetC++ Revision Questions - 268 pagesPiggyPDFNo ratings yetPiggy12 pagesPracticals CPP FPDFNo ratings yetPracticals CPP F15 pagesOodp MegalistPDFNo ratings yetOodp Megalist46 pagesOops Lab ManualPDFNo ratings yetOops Lab Manual25 pages01 Sample Programs C++PDFNo ratings yet01 Sample Programs C++78 pagesC++Lab NotesPDFNo ratings yetC++Lab Notes20 pagesC - ProgramsPDFNo ratings yetC - Programs28 pagesPratham Pareek BSC Cs Oops Prac 3PDFNo ratings yetPratham Pareek BSC Cs Oops Prac 318 pagesOops FilePDFNo ratings yetOops File18 pagesC ProgramsPDFNo ratings yetC Programs12 pagesC++ Record For II-IV Sem 123PDFNo ratings yetC++ Record For II-IV Sem 12358 pagesCodePDFNo ratings yetCode15 pagesOops Level 1 Oops ElabPDF0% (1)Oops Level 1 Oops Elab59 pagesSimple Cplus Cplus ProgramsPDFNo ratings yetSimple Cplus Cplus Programs10 pagesC++ ProgramsPDFNo ratings yetC++ Programs8 pagesPL PLPDFNo ratings yetPL PL17 pagesChatgpt Made CoursePDFNo ratings yetChatgpt Made Course16 pagesC++ ExperimentsPDFNo ratings yetC++ Experiments18 pagesGeneral C Cheat SheetPDFNo ratings yetGeneral C Cheat Sheet6 pagesC - 1PDFNo ratings yetC - 17 pagesC++ Function AssignmentPDFNo ratings yetC++ Function Assignment6 pagesOOP Lab ProgramsPDFNo ratings yetOOP Lab Programs5 pagesOOP CPP Lab Test Complete SolutionsPDFNo ratings yetOOP CPP Lab Test Complete Solutions4 pagesLab ProgramsPDFNo ratings yetLab Programs16 pagesC ExamplePDFNo ratings yetC Example11 pagesIMRANOOPSPROGRAMPDFNo ratings yetIMRANOOPSPROGRAM23 pagesExample in C ++PDFNo ratings yetExample in C ++17 pagesC++ ExamplePDFNo ratings yetC++ Example8 pages