#include<iostream>
#include<conio.h>
using namespace std;
class Unary
{
private:
int x;
int y;
public:
Unary(int a,int b);
Unary operator -();
Unary operator +();
Unary operator ++();
Unary operator +(Unary & u);
Unary operator -(Unary & u);
Unary operator *(Unary & u);
Unary operator /(Unary & u);
void display();
};
Unary::Unary(int a,int b)
{
x=a;
y=b;
}
Unary Unary::operator+(Unary & u)
{
Unary Tmp=*this;
Tmp.x=x+u.x;
Tmp.y=y+u.y;
cout << "Bainary operator+(Unary & u) overloading is called:::..............."<< endl;
return Tmp;
}
Unary Unary::operator/(Unary & u)
{
Unary Tmp=*this;
Tmp.x=x/u.x;
Tmp.y=y/u.y;
cout << "Bainary operator/(Unary & u) overloading is called:::..............."<< endl;
return Tmp;
}
Unary Unary::operator-(Unary & u)
{
Unary Tmp=*this;
Tmp.x=x-u.x;
Tmp.y=y-u.y;
cout << "Bainary operator-(Unary & u) overloading is called:::..............."<< endl;
return Tmp;
}
Unary Unary::operator*(Unary & u)
{
Unary Tmp=*this;
Tmp.x=x*u.x;
Tmp.y=y*u.y;
cout << "Bainary operator-(Unary & u) overloading is called:::..............."<< endl;
return Tmp;
}
Unary Unary::operator-()
{
x=-x;
y=-y;
cout << "unary operator-() overloading is called:::..............."<< endl;
}
Unary Unary::operator ++()
{
x=++x;
y=++y;
cout << "unary operator overloading is called:::..............."<< endl;
}
Unary Unary::operator +()
{
x=+x;
y=+y;
cout << "unary operator overloading is called:::..............."<< endl;
}
void Unary::display()
{
cout << "x=: " << x << "y=: "<< y << endl;
}
int main()
{
Unary u(4,6);
cout << "befor calling operator -(): value is "<< endl;
u.display();
cout << "After calling operator -(): value is "<< endl;
-u;
u.display();
cout << "..............................................."<< endl<< endl<< endl;
Unary u1(4,6);
cout << "befor calling operator ++(): value is "<< endl;
u1.display();
cout << "After calling operator ++(): value is "<< endl;
++u1;
u1.display();
cout << "..............................................."<< endl<< endl<< endl;
Unary u3(4,6);
Unary u4(5,7);
Unary u5=u3+u4;
u5.display();
cout << "..............................................."<< endl<< endl<< endl;
Unary u6(4,10);
Unary u7(5,7);
Unary u8=u6-u7;
u8.display();
cout << "..............................................."<< endl<< endl<< endl;
cout << "..............................................."<< endl<< endl<< endl;
Unary u9(4,10);
Unary u10(5,7);
Unary u11=u9*u10;
u11.display();
cout << "..............................................."<< endl<< endl<< endl;
Unary u12(4,10);
Unary u13(5,7);
Unary u14=u12/u13;
u13.display();
cout << "..............................................."<< endl<< endl<< endl;
getch();
return 0;
}
#include<conio.h>
using namespace std;
class Unary
{
private:
int x;
int y;
public:
Unary(int a,int b);
Unary operator -();
Unary operator +();
Unary operator ++();
Unary operator +(Unary & u);
Unary operator -(Unary & u);
Unary operator *(Unary & u);
Unary operator /(Unary & u);
void display();
};
Unary::Unary(int a,int b)
{
x=a;
y=b;
}
Unary Unary::operator+(Unary & u)
{
Unary Tmp=*this;
Tmp.x=x+u.x;
Tmp.y=y+u.y;
cout << "Bainary operator+(Unary & u) overloading is called:::..............."<< endl;
return Tmp;
}
Unary Unary::operator/(Unary & u)
{
Unary Tmp=*this;
Tmp.x=x/u.x;
Tmp.y=y/u.y;
cout << "Bainary operator/(Unary & u) overloading is called:::..............."<< endl;
return Tmp;
}
Unary Unary::operator-(Unary & u)
{
Unary Tmp=*this;
Tmp.x=x-u.x;
Tmp.y=y-u.y;
cout << "Bainary operator-(Unary & u) overloading is called:::..............."<< endl;
return Tmp;
}
Unary Unary::operator*(Unary & u)
{
Unary Tmp=*this;
Tmp.x=x*u.x;
Tmp.y=y*u.y;
cout << "Bainary operator-(Unary & u) overloading is called:::..............."<< endl;
return Tmp;
}
Unary Unary::operator-()
{
x=-x;
y=-y;
cout << "unary operator-() overloading is called:::..............."<< endl;
}
Unary Unary::operator ++()
{
x=++x;
y=++y;
cout << "unary operator overloading is called:::..............."<< endl;
}
Unary Unary::operator +()
{
x=+x;
y=+y;
cout << "unary operator overloading is called:::..............."<< endl;
}
void Unary::display()
{
cout << "x=: " << x << "y=: "<< y << endl;
}
int main()
{
Unary u(4,6);
cout << "befor calling operator -(): value is "<< endl;
u.display();
cout << "After calling operator -(): value is "<< endl;
-u;
u.display();
cout << "..............................................."<< endl<< endl<< endl;
Unary u1(4,6);
cout << "befor calling operator ++(): value is "<< endl;
u1.display();
cout << "After calling operator ++(): value is "<< endl;
++u1;
u1.display();
cout << "..............................................."<< endl<< endl<< endl;
Unary u3(4,6);
Unary u4(5,7);
Unary u5=u3+u4;
u5.display();
cout << "..............................................."<< endl<< endl<< endl;
Unary u6(4,10);
Unary u7(5,7);
Unary u8=u6-u7;
u8.display();
cout << "..............................................."<< endl<< endl<< endl;
cout << "..............................................."<< endl<< endl<< endl;
Unary u9(4,10);
Unary u10(5,7);
Unary u11=u9*u10;
u11.display();
cout << "..............................................."<< endl<< endl<< endl;
Unary u12(4,10);
Unary u13(5,7);
Unary u14=u12/u13;
u13.display();
cout << "..............................................."<< endl<< endl<< endl;
getch();
return 0;
}