Saturday, 23 June 2012

write a c++ program to consider the following class mystring

/*write a c++ program to consider the following class mystring
class mystring
{
char str[100];
public:\\method
};
overload operator + to concatenate two string such as
string1+string=string3.
*/
#include<iostream.h>
#include<conio.h>
#include<string.h>
int i=0;
class mystring
{
char str[100];
public:void accept()
       {
       i=i+1;
       cout<<"\nenter string "<<i<<":-";
       cin>>str;
       }
       void operator +(mystring);
};
void mystring::operator +(mystring m2)
{
strcat(str,m2.str);
cout<<"concatenationof string is:-"<<str;
}
int main()
{
mystring m1,m2;
clrscr();
m1.accept();
m2.accept();
m1+m2;
getch();
return 0;
}

No comments: