11. Consider the following class mystring Class mystring { char str [100]; Public: // methods }; Overload operator + to concatenate two strings such as string1+string2=string3.


#include<iostream.h>
#include<string.h>
#include<conio.h>
class mystring
{
public:
char str[20];
public:
void get()
{
cout<<“Enter the string:”;
cin>>str;
}
void disp()
{
cout<<str;
}
mystring operator+(mystring x)
{
mystring s;
strcat(str,x.str);
strcpy(s.str,str);
return s;
}
};
void main()
{
mystring string1,string2,string3;
clrscr();
string1.get();
string2.get();
cout<<“\nString 1st: “;
string1.disp();
cout<<“\nString 2nd: “;
string2.disp();
string3=string1+string2;
cout<<“\nConcatenated String: “;
string3.disp();
getch();
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s