PROGRAM TO IMPLEMENT RELATIONAL OPERATOR OVERLOADING

/*PROGRAM TO IMPLEMENT THE CONCEPT OF RELATIONAL OPERATOR OVERLOADING*/

#include<conio.h>

#include<iostream.h>

class rel_ovrld

{

int value;

public:

void input()

{

cout<<“enter the value: “;

cin>>value;

}

void display()

{

cout<<value<<endl;

}

int operator<(rel_ovrld r)

{

return(value<r.value);

}

};

void main()

{

int t;

rel_ovrld r1,r2;

clrscr();

cout<<“For first object “;

r1.input();

cout<<“For second object “;

r2.input();

cout<<“Value for first object is: “;

r1.display();

cout<<“Value for second object is: “;

r2.display();

t=r1<r2;

if(t==0)

cout<<“Value of second object is smaller than first object”<<endl;

else

cout<<“Value of first object is smaller than second object”<<endl;

getch();

}

Leave a Reply

Your email address will not be published. Required fields are marked *