I am working on a project and am having problems with the append function. I am not sure how to finish the implementation. Let's hope i get the code tags right.
//////////////////////////////////////
//
// Function : append
//
// Description : Concatenates str onto the tail end of *this
//
// Pre : *this and str are correctly formed MyString objects
//
// Post : The concatenation is complete and length is updated
//
/////////////////////////////////////
void MyString::append (const MyString& str)
{
assert ( 0 <= length && length <= CAPACITY
&&
0 <= str.length && str.length <= CAPACITY);
//finish the function implementation
//NOTE: The length of the concatenation cannot exceed CAPACITY
It's not possible to answer this question unless you provide more details about your MyString class. How can we help you with an implementation of append without knowing how the string class is represented, or even what you want to do with it?
Unless you're doing this as a learning project, and want to find you how to implement your own string class, I recommend using std::string instead.
While I can't give you a complete solution, I can give you a little tip:
Since "this" is a MyString, and "str" also is a MyString, you should assume that they are both valid. You shouldn't need to check the length. However, you should check that the resulting length is valid:
Although I wouldn't use assert at all, but handle this error in a better way. Coming to think about it, I don't think I would have a maximum capacity at all.
This actually is a project where we are supposed to implement and test our own class. My professor never really explained the project to us, so I really am not sure what it is I am doing with it. The webpage is
No, it is the one function out of the program that was never covered in the class, and I have already done the rest of the project except for this one. I have looked through the textbook numerous times, but all that I can find on concatenations are examples of things like string1 + string 2, and I have no idea how this applies to this particular case. I am looking for help to understand this function.