Question: C++ programming You are to implement a MyString class which is our own limited implementation of the std:: string Header file and test (main) file

C++ programming

You 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, code for mystring.cpp.

Here is header file

mystring.h

/* MyString class */

#ifndef MyString_H

#define MyString_H

#include

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

#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;

}

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!