/* 12. Write a C++ program to create a class STRING and implement the following.Display the results by overloading the operator << after every operator.
(i) STRING s1="VTU"
(ii) STRING s2="BELGAUM"
(iii) STRING s3=s1+s2
Use copy constructor */
#include<iostream.h>
#include<conio.h>
#include<string.h>
class STRING
{
char str[15];
public:
STRING()
{
str[0] = '\0';
}
STRING(char *data)
{
strcpy(str,data);
}
STRING(STRING &text)
{
strcpy(str,text.str);
}
friend STRING operator +(STRING x,STRING y);
friend ostream& operator <<(ostream& Out,STRING z);
};
ostream& operator <<(ostream& Out, STRING z)
{
Out<<z.str;
return Out;
}
STRING operator +(STRING x,STRING y)
{
STRING s;
strcpy(s.str,x.str);
strcat(s.str," ");
strcat(s.str,y.str);
return s;
}
void main()
{
clrscr();
STRING s1="VTU";
cout<<"\nFirst string is : "<<s1;
STRING s2="BELGAUM";
cout<<"\nSecond string is : "<<s2;
STRING s3=s1+s2;
cout<<"\nConcatenated string is : "<<s3;
getch();
}