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

Output of the file should be: Hello Hello there Length = 11 Hello Hello again Le

ID: 3804829 • Letter: O

Question

Output of the file should be:

Hello
Hello there
Length = 11

Hello
Hello again
Length = 11
0
1

Using the starter source file below and implement the functions where the descriptive comments are found. The class contains a pointer that the classes constructor will initialize by dynamically allocating 101 characters using the new keyword. A destructor will be responsible for deallocating the memory using the delete[] keyword. You're not allowed to use the c-string library functions like strlen, strcpy, etc . . .. Use the arrays and pointers.

/////////Contents of starter file below:

#define _CRT_SECURE_NO_WARNINGS

#include

using namespace std;

class String

{

private:

   char* pstr;

public:

   String()

   {

       // allocate 101 characters and initialize pstr

      

       // Set the first character in the array to the null terminating character

      

   }

   String(const char* s)

   {

       // allocate 101 characters and initialize pstr

      

       // copy the characters from s into pstr

      

   }

   ~String()

   {

       // deallocate the memory for the character array

         

   }

   int length() const

   {

       // loop through array and keep count

         

   }

   bool operator == (const String& s)

   {

       // loop and compare characters in each array by passing a String as the arg

         

   }

   bool operator == (const char* ps)

   {

       // loop and compare characters in each array by passing a char* as the arg

   }

   void operator += (const char* ps) // concatenate

   {

       // add the characters to the end of the existing characters by passing a char* as the arg

   }

   void operator += (const String& s) // concatenate

   {

       // add the characters to the end of the existing characters by passing a String as the arg

   }

   operator char* () // conversion operator

   {

       // return a pointer to the characters

      

   }

};

int main()

{

   String s1;

   s1 += "Hello";

   cout << s1 << endl;

   s1 += " there";

   cout << s1 << endl;

   cout << "Length = " << s1.length() << endl;

   cout << endl;

   String s2 = "Hello";

   cout << s2 << endl;

   s2 += String(" again");

   cout << s2 << endl;

   cout << "Length = " << s2.length() << endl;

   cout << (s1 == s2) << endl;

   cout << (s1 == "Hello there") << endl;

   system("pause");

   return 0;

}

Explanation / Answer

#define _CRT_SECURE_NO_WARNINGS

#include

using namespace std;

class String

{

private:

   char* pstr;

public:

   String()

   {

       // allocate 101 characters and initialize pstr

      

       // Set the first character in the array to the null terminating character

      

   }

   String(const char* s)

   {

       // allocate 101 characters and initialize pstr

      

       // copy the characters from s into pstr

      

   }

   ~String()

   {

       // deallocate the memory for the character array

         

   }

   int length() const

   {

       // loop through array and keep count

         

   }

   bool operator == (const String& s)

   {

       // loop and compare characters in each array by passing a String as the arg

         

   }

   bool operator == (const char* ps)

   {

       // loop and compare characters in each array by passing a char* as the arg

   }

   void operator += (const char* ps) // concatenate

   {

       // add the characters to the end of the existing characters by passing a char* as the arg

   }

   void operator += (const String& s) // concatenate

   {

       // add the characters to the end of the existing characters by passing a String as the arg

   }

   operator char* () // conversion operator

   {

       // return a pointer to the characters

      

   }

};

int main()

{

   String s1;

   s1 += "Hello";

   cout << s1 << endl;

   s1 += " there";

   cout << s1 << endl;

   cout << "Length = " << s1.length() << endl;

   cout << endl;

   String s2 = "Hello";

   cout << s2 << endl;

   s2 += String(" again");

   cout << s2 << endl;

   cout << "Length = " << s2.length() << endl;

   cout << (s1 == s2) << endl;

   cout << (s1 == "Hello there") << endl;

   system("pause");

   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