Thursday, March 20, 2014

Overloading Logical 'Greater' or '>' 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(5.0,6.0); //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