Program To Overlead Operator, Using Two Data Members, And Member Functions.




class distance
{
float point;
public:
distance()
{
point=0.0;
}
distance(float p)
{
point =p;
}

distance operator+(distance x)
{
distance temp;
temp.point=point+x.point;
return temp;
}

distance operator-(distance x)
{
distance temp;
temp.point=point-x.point;
if(temp.point<0)
return distance(0);
else
return temp;
}
void show(){
cout<}
};

void main()
{
clrscr();
distance d1(5),d2(2),d3;
d3= d2.operator +(d1);
d3.show();

d3= d2.operator -(d1);
d3.show();
getch();
}

No comments:

Post a Comment