Wednesday, March 19, 2014

Overloading Logical 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);
};

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

int main()
{
Point P1(6.0,7.1), P2(7.0,7.1); //Change the value of argument however you like
if(P1<=P2)
cout<<"P1<=P2=True";
else
cout<<"P1<=P2=False";
return(0);
}

No comments:

Post a Comment