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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started