0% found this document useful (0 votes)
3 views4 pages

5 PGM

Uploaded by

naacc3.klnce
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views4 pages

5 PGM

Uploaded by

naacc3.klnce
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

#include<iostream.h> #include<iostream.

h>
#include<conio.h> #include<conio.h>
#include<string.h> class distance
Class {
Complex int feet,inch;
{ public:
Float real; distance()
Float img; {
Public: cout<<"\n default constructor";
Complex(float tempreal=0,float }
tempimg=0) distance(int f,int i)
{ {
Real=tempreal; cout<<"\n parametersized
Img=tempimg; constructor \n";
} feet=f;
Complex add(complex comp2) inch=i;
{ }
Float tempreal; distance(const distance &dd)
Float tempimg; {
Tempreal=real+comp2.real; cout<<"copy constructor \n";
Tempimg=img+comp2.img; feet=dd.feet;
Return complex(temp inch=dd.inch;
real,tempimg); }
} void operator=(const distance
Complex operator +(complex &d)
comp2) {
{ cout<<"overload assign operator
Float tempreal; \n";
Float tempimg; feet=d.feet;
Tempreal=real+comp2.real; inch=d.inch;
Tempimg=img+comp2.img; }
Return complex(temp display()
real,tempimg); {
} cout<<feet<<"feet"<<inch<<"inch
Void display() "<<"\n";
{ }
Cout<<real<<”i”<<img<<”\n”; };
} void main()
}; {
Void main() clrscr();
{ distance d1,d4;
Complex comp1(10,20); distance d2(10,10);
Complex comp2(20,30); distance d3(d2);
Complex d1=d2;
compresult1,compresult2; d1.display();
Compresult1=comp1.add(comp2); d2.display();
Compresult1.display(); d3.display();
Compresult2=comp1+comp2; d4.display();
Compresult2.display(); getch();
Getch(); }
}
#include<iostream.h> #include<iostream.h>
#include<conio.h> #include<malloc.h>
#include<string.h> #include<conio.h>
class student
{ class test
private: {
int rollno; int i;
char name[10]; public:
char address[10]; test():i(0)
public: {
friend ostream cout<<"contructor is called\n";
&operator<<(ostream };
&,student&); ~test()
friend istream {
&operator>>(istream cout<<"destructor is called\n";
&,student&); };
}; void *operator new(size_t
ostream &operator<<(ostream size);
&tempout,student&tempstudent) void operator delete(void *p);
{ };
tempout<<"rollno void *test::operator new(size_t
is"<<tempstudent.rollno<<"\n"; size)
tempout<<"address {
is"<<tempstudent.address<<"\n"; void *p=malloc(size);
return tempout; if(!p)
} {
istream &operator>>(istream cout<<"memory allocate
&tempin,student&tempstudent) failure";
{ exit(0);
cout<<"enter rollno:"; }
tempin>>tempstudent.rollno; return p;
cout<<"\n"; }
cout<<"enter name:"; void test::operator delete(void
tempin>>tempstudent.name; *p)
cout<<"\n"; {
cout<<"enter address:"; free(p);
tempin>>tempstudent.address; }
cout<<"\n"; int main()
return tempin; {
} test *testptr=new test;
void main() delete(testptr);
{ getch();
clrscr(); }
student captainstudent;
cin>>captainstudent;
cout<<"following is
captainstudent data\
n"<<captainstudent<<"\n bye\n";
getch();
}

#include<stdlib.h> #include<iostream.h>
#include<conio.h> #include<conio.h>
class complex class complex
{ {
float x,y; int a,b;
public: public:
complex() complex()
{ void gete()
x=0; {
y=0; cout<<"enter two no:";
} cin>>a>>b;
complex(float real,float img) }
{ void operator++()
x=real; {
y=img; a=++a;
} b=++b;
void show() }
{ void operator--()
cout<<x<<"+j"<<y<<endl; {
} a=--a;
friend complex operator+ a=--b;
(complex,complex); }
}; void display()
complex operator +(complex {
obj1,complex obj2) cout<<a<<"+i"<<b<<""<<endl;
{ }
complex temp; };
temp.x=obj1.x+obj2.x; void main()
temp.y=obj1.y+obj2.y; {
return temp; complex obj;
} obj.gete();
int main() obj++;
{ cout<<"increasment complex no\
clrscr(); n";
complex c1(1.6,3.6); obj.display();
complex c2(2.6,4.9); obj--;
complex c3; cout<<"decrement complex no\n";
c3=c1+c2; obj.display();
c1.show(); getch();
c2.show(); }
c3.show();
return 0;
getch();
}

#include<iostream.h> #include<iostream.h>
class matrix {
{
int Element[3][3]; int arrayofint1[]
public: [3]={1,2,3,4,5,6,7,8,9};
matrix(){}; int arrayofint2[]
matrix(int Tempmatrix[3][3]) [3]={4,5,6,7,8,9,1,2,3};
{ matrix m1(arrayofint1);
for(int i=0;i<3;i++) matrix m2(arrayofint2);
for(int j=0;j<3;j++) matrix m3,m4;
Element[i][j]=Tempmatrix[i][j]; m1.display();
} m3=m1*5;
void read() m3.display();
{ m2.display();
for(int i=0;i<3;i++) m4=5*m2;
for(int j=0;j<3;j++) m4.display();
cin>>Element[i][j]; }
}
void display()
{
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
cout<<Element[i][j]<<"";
}
cout<<"\n";
}
}
friend matrix operator
*(matrix,int);
friend matrix operator
*(int,matrix);
};
matrix operator *(matrix
Tempmatrix,int multiplier)
{
for(int i=0;i<3;i++)
for(int j=0;j<3;j++)
Tempmatrix.Element[i]
[j]=multiplier *
Tempmatrix.Element[i][j];
return
matrix(Tempmatrix.Element);
}
matrix operator *(int
multiplier,matrix Tempmatrix)
{
for(int i=0;i<3;i++)
for(int j=0;j<3;j++)
Tempmatrix.Element[i]
[j]=multiplier *
Tempmatrix.Element[i][j];
return
matrix(Tempmatrix.Element);
}
void main()

You might also like