AS 6: Copy-on-write Strings

This assignment will give you experience with the "big 3" for a new string class. If a program does a lot of text manipulation, it can be helpful if it uses a string class that does basic, automated memory management. For example, if two string variables are assigned to each other, it would be useful to have them point to the same underlying buffer (to avoid duplication), but to reassign the variable if the string is modified. You are going to create a string library that implements this.

You will implement a class cow_string (where "cow" means "copy on write", most definitely not an implied reference to livestock frequently found in Wisconsin). The class will store arrays of characters and be implemented using the C-style string operations like strcpy. To avoid duplication, cow_string objects point to shareable_string objects which contain both a string and a count of the number of cow_string objects that share that string.

More specifically, download the following code and get it to run with no errors:

When you are finished, submit just cow_string.cpp to esubmit as 6cow. Your solution will only be graded for correctness, not style issues. You may discuss your solution with others, but each student is to submit their own.