Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Output of the file should be: Hello Hello there Length = 11 Hello Hello again Length = 11 0 1 Using the starter source file

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;

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intelligent Information And Database Systems Asian Conference Aciids 2012 Kaohsiung Taiwan March 19 21 2012 Proceedings Part 3 Lnai 7198

Authors: Jeng-Shyang Pan ,Shyi-Ming Chen ,Ngoc-Thanh Nguyen

2012th Edition

3642284922, 978-3642284922

More Books

Students also viewed these Databases questions

Question

How effective is each pitch?

Answered: 1 week ago