a. Extend the definition of the class newString as follows: i. Overload the oper
ID: 3667588 • Letter: A
Question
a. Extend the definition of the class newString as follows:
i. Overload the operators + and += to perform the string concatenation operations.
ii. Add the function length to return the length of the string.
b. Write the definition of the function to implement the operations defined in part a
c. Write a test program to test various operations on the newString objects.
d. Explain each step of the process and how it codes executes
Please pay close attention to the requirements
Please do not copy solution from textbook solutions.
Found on page 936 of C++ Programming: From Problem Analysis to Program Design, 6e
Explanation / Answer
Output :
Enter String :hii
Enter String : Hello
Result String : hii Hello
#include<iostream.h>
#include<conio.h>
class string
{
private:
char a[100];
public:
void get();
void dis();
friend string operator +(string,string);
};
string operator +(string o,string q)
{
string t;
for(int i=0;o.a[i]!='';i++)
{
t.a[i]=o.a[i];
}
for(int j=0;q.a[i]!='';j++,i++)
{
t.a[i]=q.a[j];
}
t.a[i]='';
return t;
}
void string::get()
{
cout<<" Enter String:";
cin>>a;
}
void string::dis()
{
cout<<" Result String:"<<a;
}
void main()
{
string b,c,d;
clrscr();
b.get();
c.get();
d=b+c;
d.dis();
getch();
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.