Answered You can hire a professional tutor to get the answer.

QUESTION

ou are to implement a MyString class which is our own limited implementation of the std:string Header file and test (main) file are given in below,...

Here is header file

mystring.h

/* MyString class */

#ifndef MyString_H

#define MyString_H

#include <iostream>

using namespace std;

class MyString {

private:

   char* str;

   int len;

public:

   MyString();

   MyString(const char* s);

   MyString(MyString& s);

   ~MyString();

   friend ostream& operator <<(ostream& os, MyString& s); // Prints string

   MyString& operator=(MyString& s); //Copy assignment

   MyString& operator+(MyString& s); // Creates a new string by concantenating input string

};

#endif

Here is main file, the test file

testMyString.cpp

/* Test for MyString class */

#include <iostream>

#include "mystring.h"

using namespace std;

int main()

{

char greeting[] = "Hello World!";

MyString str1(greeting); // Tests constructor

cout << str1 << endl; // Tests << operator. Should print Hello World!

char bye[] = "Goodbye World!";

MyString str2(bye);

cout << str2 << endl; // Should print Goodbye World!

MyString str3{str2}; // Tests copy constructor

cout << str3 << endl; // Should print Hello World!

str3 = str1; // Tests copy assignment operator

cout << str3 << endl; // Should print Goodbye World!

str3 = str1 + str2; // Tests + operator

cout << str3 << endl; // Should print Hello World!Goodbye World!

return 0;

}

Show more
LEARN MORE EFFECTIVELY AND GET BETTER GRADES!
Ask a Question