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

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();
}

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