Question: Help solve this program #include MyString.h #include using namespace std; /* MyString(); MyString(const char *pString, int pSize); MyString(MyString *obj); //MyString(char *str); ~MyString(); int getSize(); char

Help solve this program

#include "MyString.h"

#include

using namespace std;

/*

MyString();

MyString(const char *pString, int pSize);

MyString(MyString *obj);

//MyString(char *str);

~MyString();

int getSize();

char *getString();

void setSize(int size);

void setString(char *obj);

void operator+=(MyString *pobj);

bool operator==(MyString *pobj);

void operator=(MyString *pObj);

*/

//TODO Implement the constructor with no parameters

//TODO Implement the constructor with two parameters, MyString(const char *pString, int pSize)

//TODO Implement the copy constructor

//TODO Implement the destructor

//TODO Implement the method getSize

//TODO Implement the method setSize

//TODO Implement the method setString

//TODO Implement the method getString

//TODO Implement the overloading assignment method

// Strings may be assigned to a MyString object with the = operator.

//Implement the overloading += method

//One string may be concatenated to another with the += operator.

void MyString::operator+=(MyString *pobj){// string a = "A"; a += "BC";

char * newdata = new char(size + pobj->getSize());

for (int i= 0;i < size; i++)

newdata[i] = data[i];

for (int i= 0;i < pobj->getSize(); i++)

data[size + i] = pobj->getString()[i];

delete [] data;

data = newdata;

}

//TODO Implement the overloading += method

//Strings may be tested with the relational operators

int main(){

MyString name1;

name1.setString("Lukas");

name1.setSize(5);

MyString lastname;

lastname.setString(" Borges");

lastname.setSize(7);

MyString name2(&name1);

cout << name2.getString() << endl;

//name2.operator+=(&lastname);

name2 += &lastname;

cout << name2.getString() << endl;

//cout << (name2.operator==(&name1) ) << endl;

cout << (name2 == &name1 ) << endl;

cin.ignore(1124, ' ');

cin.get();

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!