#include<iostream.h>
#include<string.h>
class marge
{
private: char name[20];
public:
marge()
{
strcpy(name,"");
}
marge(char *x)
{
strcpy(name,x);
}
marge operator + (marge m2)
{
marge m1;
strcpy(m1.name,"");
strcat(m1.name,strcat(name,""));
strcat(m1.name,m2.name);
return m1;
}
marge operator=(marge &m)
{
strcpy(name,m.name);
return marge(name);
}
marge operator+=(marge &m)
{
strcpy(name,m.name);
return marge(name);
}
void show()
{
cout<<name;
}
};
void main()
{
marge m1("Good"),m2("Morning"),m3,m4("Boys");
m1.show();
m2.show();
m3=m1+m2;
cout<<"\nOverloading + operator=\n";
m3.show();
marge m=m3;
cout<<"\nOverloading = operator=\n";
m.show();
cout<<"\nOverloading += operator=";
m+=m4;
m.show();
}
#include<string.h>
class marge
{
private: char name[20];
public:
marge()
{
strcpy(name,"");
}
marge(char *x)
{
strcpy(name,x);
}
marge operator + (marge m2)
{
marge m1;
strcpy(m1.name,"");
strcat(m1.name,strcat(name,""));
strcat(m1.name,m2.name);
return m1;
}
marge operator=(marge &m)
{
strcpy(name,m.name);
return marge(name);
}
marge operator+=(marge &m)
{
strcpy(name,m.name);
return marge(name);
}
void show()
{
cout<<name;
}
};
void main()
{
marge m1("Good"),m2("Morning"),m3,m4("Boys");
m1.show();
m2.show();
m3=m1+m2;
cout<<"\nOverloading + operator=\n";
m3.show();
marge m=m3;
cout<<"\nOverloading = operator=\n";
m.show();
cout<<"\nOverloading += operator=";
m+=m4;
m.show();
}
No comments:
Post a Comment