Make overloading functions for combining string class object
Solution
#include\"iostream\"
using namespace std;
#include<string.h>
class string1
{
public:
char setofchar[50]; // String with maximum size 50
string1() // Zero argument Constructor
{
strcpy(setofchar,\"\");
}
string1(char a[]) // One argument Constructor
{
strcpy(setofchar,a);
}
string1 operator+(string1 second) // overload function of operator +
{
string1 temp;
strcpy(temp.setofchar, setofchar); // for copy the value to temporary variable
strcat(temp.setofchar, \" \"); // for add space in between two string
strcat(temp.setofchar, second.setofchar); // for adding second string with first string
return temp;
}
};
int main()
{
string1 first(\"CHEGG\"), second(\"COMPUTER\"), sum;
sum = first + second;
cout<<sum.setofchar; // for printing the output.
return 0;
}
