#include #include #include #include #include #include #include #include #include #include using namespace std ; class mystring { public: char* ptr ; //TO DO set the pointer to NULL // in the empty constructor mystring( ) { } /* TO DO Write the copy constructor */ //Copy constructor mystring( const mystring& obj1 ) { //remove current block //printf( "%p\n" , ptr ) ; printf( "Inside the copy constructor. %s \n" , obj1.ptr ) ; //if ( ptr != NULL ) // delete[] ptr ; } mystring( const char* str1 ) { cout << "Inside the constructor with a single argument." << endl ; if ( str1 == NULL ) ptr = NULL ; else { int len = strlen( str1 ) + 1; ptr = new char[ len ] ; strcpy ( ptr, str1 ) ; } } //assignment operator mystring& operator=( const mystring& param1 ) { printf( "Inside the equal operator.\n" ) ; if ( param1.ptr == NULL ) { ptr = NULL ; } else { int len = strlen( param1.ptr ) + 1; ptr = new char[ len ] ; strcpy ( ptr, param1.ptr ) ; } return *this ; } /* TO DO Complete the code for the + operator Be sure to consider the cases where the current object or param1 or both may contain empty strings. You can use strcpy and strcat functions. */ mystring operator+( const mystring& param1 ) { return *this ; } ~mystring() { cout << "Inside the destructor." << endl ; if ( ptr != NULL ) delete[] ptr ; } void print() { if ( ptr != NULL ) cout << ptr << endl ; } }; int main() { mystring str1 ; mystring str2 = str1 ; str1.print() ; str2.print() ; cout << "------" << endl ; mystring str3( "Lennox Lewis" ) ; mystring str4 = str1 ; str3.print() ; str4.print() ; cout << "------" << endl ; mystring str5 = " was pretty good." ; mystring str6 = str3 + str5 ; str6.print() ; cout << "------" << endl ; return 0 ; }