STC
STC
h> class string { char *name; int length; public: string() { length=0; name=new char[length+1]; } string(char *s) { length=strlen(s); name=new char[length+1]; strcpy(name,s); } void concat(string &a,string &b) { length=a.length+b.length; delete name; name=new char[length+1]; strcpy(name,a.name); strcat(name,b.name); } void display() { cout<<name<<"\n"; } }; void main() { clrscr(); cout<<"\n\t\t CONCATENATION OF TWO STRINGS"; char s1[30],s2[30]; cout<<"\n\tEnter the two strings to be concatenated: "; cin>>s1>>s2; string name1(s1); string name2(s2); string name3; name3.concat(name1,name2); cout<<"\tThe first string is "; name1.display(); cout<<"\tThe second name is "; name2.display(); cout<<"\tThe concatenated string is "; name3.display(); getch(); }