WAP
to using class distance-member attributes km,m ,use operator +=,>
#include<iostream.h>
#include<conio.h>
class distance
{
int kilomiter,miter;
public:
void getdata()
{
cout<<"\n\nEnter the
kilomiter:\t";
cin>>kilomiter;
cout<<"\nEnter the Miter:\t";
cin>>miter;
}
void display()
{
cout<<"\nAddition of two
distance:\t";
cout<<kilomiter<<"."<<miter;
}
void display2()
{
cout<<kilomiter<<"."<<miter;
}
distance operator+=(distance &d)
{
distance t;
t.kilomiter=d.kilomiter+kilomiter;
t.miter=d.miter+miter;
return t;
}
int operator >(distance &d)
{
if(kilomiter>d.kilomiter)
{
return 1;
}
else
{
return 0;
}
}
};
void main()
{
distance c1,c2,c3,c4,c5;
clrscr();
c1.getdata();
c2.getdata();
c3=c1+=c2;
c3.display();
c4.getdata();
c5.getdata();
if(c4>c5)
{
cout<<"\n";
c4.display2();
cout<<"\tgreater than\t";
c5.display2();
}
else
{
cout<<"\n";
c5.display2();
cout<<"\tgreater than\t";
c4.display2();
}
getch();
}