Our String class always deletes the old character buffer and allocates a new character buffer on assignment or in the copy constructor.

computer science

Description

Visual studio 2019 ++ do not use include bits/stdc++.h

Problem 1 Modify the String class in the following ways: 

a) Our String class always deletes the old character buffer and allocates a new character buffer on assignment or in the copy constructor. This need not be done if the new value is shorter than the current value and hence would fit the existing buffer. Rewrite the String class to only allocate a new buffer when necessary. Abstract the common tasks from the assignment operator and the copy constructor and place them in an internal (private) method. 

b) Overload the compound += operator to perform concatenation of two String objects.

 c) Overload the + operator using the += operator. 

d) Add a member function compare (String) that returns -1 or 0 or 1 depending on whether the string is lexicographically less than, equal to, or greater than the argument. 

Please provide appropriate documentation. Provide a test program to test your class. 

Instruction Files

Related Questions in computer science category