Using the following code write the following instructions in
Using the following code write the following instructions in C++
Implementation:
1. Re-implement your String class to use a dynamically allocated array for storage. It will be a NULL terminating charater array.
2. This dynamic version of the String will only allocate exactly the amount of memory necessary to store the characters. That is, the length will be the same as the capacity. However, the size of the dynamic array needs to have an extra char for the NULL terminator.
3. To re-write the constructors to allocate the correct amount of memory.
4. The default constructor allocates an array of size 1 for the empty string. The other constructors will allocate memory as needed. For example for String str(\"abc\"); str.capacity() == 3, str.length() == 3, and str.string_size == 4.
5. Implement a destructor, copy constructor, constant time swap, and assignment operator for your ADT.
6. You will need to re-implement capacity(). length() remains the same.
7. You will also have to update concat and += to return the proper sized string result.
8. Implement the private constructors String(int) and String(int, const char *).
String(int) constructs the object as the emptry string with int capacity.
String(int, const char *) works the same as String(const char *) but allocates int capacity.
9. Implement a private method reset_capacity to change the capacity of your string while keeping the contents intact. That is, create a new array and copy contents over to the new array, making sure to clean up memory.
10. The private constructors and method may be useful for re-implementing + and +=.
Testing:
11. Write tests for the methods developed for this project.
12. Write test cases first. Testing must be thorough. You will be relying on the String to be correct.
13. You should make sure that the test cases you develop are very complete.
14. The otests test the constructors, assignment, copy, +, ==, and <.
15. If you add additional member variables the tests will not work properly.
--------------------------------------------------------------------------------
string.hpp
--------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------
string.cpp
---------------------------------------------------------------------------------------------------------------------------
Solution
---------------------------------------------------------------------------------------------------------------------------
string.cpp
---------------------------------------------------------------------------------------------------------------------------
