Wednesday, October 1, 2014

Compare the two object that contains integer values that demonstrate the overloading of equality (==), less than (<), greater than (>), not equal(!=) greater than or equal to (>=) & less than or equal to (<=) operators.

Code:


#include
 #include
 class compare
 {
 int x;
 public:
 void get()
 {
 cout<<"\n Enter a number";
 cin>>x;        
 }
 void display()
 {
 cout<
 }

 int operator==(compare &c1)
 {
 int y=0;
 if(x==c1.x)
 y=1;
 return y;
 }

 int operator <(compare &c1)
 {
 int y=0;
 if(x
 y=1;
 return y;
 }
 int operator >(compare &c1)
 {
 int y=0;
 if(x>c1.x)
 y=1;
 return y;
 }
 int operator !=(compare &c1)
 {
 int y=0;
 if(x!=c1.x)
 y=1;
 return y;
 }
 int operator <=(compare &c1)
 {
 int y=0;
 if(x<=c1.x)
 y=1;
 return y;
 }
 int operator >=(compare &c1)
 {
 int y=0;
 if(x>=c1.x)
 y=1;
 return y;
 }
 };
 void main()
 {
 clrscr();
 compare c1,c2;
 c1.get();
 c2.get();
 if(c1==c2)
 cout<<"object 1 is equal object 2"<
 if(c1
 cout<<"object 1 is smaller than object 2"<
 if(c1>c2)
 cout<<"object 1 is greater than object 2"<
if(c1!=c2)
 cout<<"object 1 is not equal to object 2"<
 if(c1<=c2)
 cout<<"object 1 is smaller or equal to object 2"<
 if(c1>=c2)
 cout<<"object 1 is greater than or equal to object2"<
 getch();


 }

No comments:

Post a Comment