Wednesday, March 19, 2014

Overloading Logical equal Operator

//Overloading Logical Operator "==" & "!="

#include<iostream.h>
class Point
{
 private:
double M_dX, M_dY;
 public:
Point(double dX=0.0, double dY=0.0)
{
M_dX=dX;
M_dY=dY;
}
friend bool operator==(Point &P1, Point &P2);
friend bool operator!=(Point &P1, Point &P2);
};

bool operator==(Point &P1, Point &P2)
{
return(P1.M_dX==P2.M_dX && P1.M_dY==P2.M_dY);
}

bool operator!=(Point &P1, Point &P2)
{
return!(P1==P2);
}

int main()
{
Point P1(4.55,6.0), P2(4.55,6.0);
if(P1==P2)
cout<<"P1==P2=True";
else
cout<<"P1==P2=False";
return(0);
}

No comments:

Post a Comment