Master C++ with Real-time Projects and Kickstart Your Career Start Now!!
Program 1
//Program for Relational operator overloading
// How to compare to object
#include<iostream>
#define clrscr() system("cls")
using namespace std;
class Test
{
int n;
public:
Test(int n)
{
this->n=n;
}
Test(Test &k)
{
n=k.n;
}
Test(){}
int operator>(Test &k);
int operator<(Test &k);
int operator==(Test &k);
int operator!=(Test &k);
};
int Test::operator>(Test &k)
{
if(n>k.n)
return 1 ;
return 0;
}
int Test::operator<(Test &k)
{
if(n<k.n)
return 1 ;
return 0;
}
int Test::operator==(Test &k)
{
if(n==k.n)
return 1 ;
return 0;
}
int Test::operator!=(Test &k)
{
if(n!=k.n)
return 1 ;
return 0;
}
int main()
{
clrscr();
Test T1(40);
Test T2(50);
// if(T1>T2)
// cout<<"\nValues are not same ";
// else
// cout<<"\nValues are same";
return 0;
}