C++ programming language part- 73 Look here is a program with a class and overload the ==,>,< and += operators
Look here is a program with a
class and overload the ==,>,< and += operators.
Program 49_3
class fps_distance
{private:
char str[20];
public:
fps_distance(char
st[20]);
fps_distance();
int
operator==(fps_distance &);
int
operator>(fps_distance &);
int
operator<(fps_distance &);
void
operator+=(fps_distance &);
fps_distance
operator+(fps_distance &);
void
display(void);
};
fps_distance::fps_distance(char
st[20])
{ strcpy(str,st); }
fps_distance::fps_distance()
{ strcpy(str,"nova"); }
int
fps_distance::operator == (fps_distance & Fps2)
{ return
((strcmp(str,Fps2.str)==0)?1:0); }
int
fps_distance::operator >(fps_distance & Fps2)
{ return
((strcmp(str,Fps2.str)>0)?1:0); }
int
fps_distance::operator <(fps_distance &Fps2)
{ return
((strcmp(str,Fps2.str)<0 nbsp="" o:p="">0>
void fps_distance::operator+=(fps_distance
&Fps2)
{ (strcat
(str,Fps2.str)); }
fps_distance
fps_distance::operator+(fps_distance &Fps2)
{ char st[20];
strcpy(st,str);
strcat(st,Fps2.str);
return(fps_distance(st));
}
void
fps_distance::display(void)
{ cout<<"\nstring is "<
void
main()
{ fps_distance
W1("NOVA"),W2("nova"),W3("Dhaka");
clrscr();
if(W1==W2)
cout<<
"equal ";
else
if(W1>W2)
cout<<"
first is grater";
if(W1
cout<<"first
is less";
W1+=W2;
W1.display();
W1=W2+W3;
W1.display(); }