Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ Problem> * Make overloading functions for combining string class objects. 1-

ID: 3936496 • Letter: C

Question

C++ Problem> * Make overloading functions for combining string class objects.
1-For string object combination, you need two target operators. Ex) string1+string2 2-Target operators are two strings. 3-implement "operator + " with following actions. • string1=string2+string3 ; Ex) string2='happy' ; String3='birth day' ; String1=string2+string3 ; string1= 'happy birth day' ;
4-Implement "operator +" that allows multiple operation
•String1=string2+string3+string4 ; Ex) string2='happy' ; String3='birth day' ; String4='to you' ; String1=string2+string3+string4 ; string1= 'happy birth day to you ' ;
C++ Problem> * Make overloading functions for combining string class objects.
1-For string object combination, you need two target operators. Ex) string1+string2 2-Target operators are two strings. 3-implement "operator + " with following actions. • string1=string2+string3 ; Ex) string2='happy' ; String3='birth day' ; String1=string2+string3 ; string1= 'happy birth day' ;
4-Implement "operator +" that allows multiple operation
•String1=string2+string3+string4 ; Ex) string2='happy' ; String3='birth day' ; String4='to you' ; String1=string2+string3+string4 ; string1= 'happy birth day to you ' ;
Problem> * Make overloading functions for combining string class objects.
1-For string object combination, you need two target operators. Ex) string1+string2 2-Target operators are two strings. 3-implement "operator + " with following actions. • string1=string2+string3 ; Ex) string2='happy' ; String3='birth day' ; String1=string2+string3 ; string1= 'happy birth day' ;
4-Implement "operator +" that allows multiple operation
•String1=string2+string3+string4 ; Ex) string2='happy' ; String3='birth day' ; String4='to you' ; String1=string2+string3+string4 ; string1= 'happy birth day to you ' ; Problem> * Make overloading functions for combining string class objects.
1-For string object combination, you need two target operators. Ex) string1+string2 2-Target operators are two strings. 3-implement "operator + " with following actions. • string1=string2+string3 ; Ex) string2='happy' ; String3='birth day' ; String1=string2+string3 ; string1= 'happy birth day' ;
4-Implement "operator +" that allows multiple operation
•String1=string2+string3+string4 ; Ex) string2='happy' ; String3='birth day' ; String4='to you' ; String1=string2+string3+string4 ; string1= 'happy birth day to you ' ;

Explanation / Answer

The code snippet for overloading functions for combining string class objects is given below:

#include<iostream>
#include<string>

using namespace std;
class String
{
char str[100];
public:
String(char *input="") // Constructor for initialising string
{
   strcpy(str,input);
}
void printstring();
String operator+(String s);
};

String String::operator+(String s)
{
String temp("");
strcpy(temp.str,str);
strcat(temp.str," ");
strcat(temp.str,s.str);
return(temp);
}
void String::printstring()
{
cout<<"Output String after concatination ";
cout<<str;
}
int main()
{
String s1("happy"),s2("birthday"),s3("to you"),s4;
s4=s1+s2+s3;
s4.printstring();
getchar();
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote