Write a C++ program to overload>operator to find heavier of two stones according to their weights.

Write a C++ program to overload>operator to find heavier of two stones according to their weights.

Ans.

#include<iostream.h>

Enum boolen {FALSE, TRUE};

Class Overload GT

{

Private :

Int weight;

Public :

overloadGT (int value)

{

Weight = value;

}

Int Ge Weight( )

{

Return weight;

}

Boolean operator > (OverloadGT wt)

{

Return (weight > wt.weight ?TRUE :FALSE);

}

};

Void main( )

{

OverloadGT wt1 = 10;

OverloadGT wt2 = 20;

Cout <<”nWeight of stone1 =”<<wt1. GetWeight( );

Cout <<”nWeight of stone2 =”<<wt2. GetWeight( );

If (wt1>wt2)

Cout<<”Weight of stone 1 is heavy”;

Else

Cout<<”Weight of stone 2 is heavy”;

}

Share this post

Leave a Reply

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