A. Continue the implementation of the String class. Add each of the following:
a. A constructor String (int n, char c) that initializes the string with n copies of the character c.
b. The + operator to perform concatenation of two String objects.
c. A member function compare (String) that returns -1, 0, or 1 depending upon whether the string is lexicographically less than, equal to, or greater than the argument. Then, using this member function, provide definitions for the comparison operators <, , and >=.
d. A function resize (int n, char c) that changes the size of the string to n, either truncating characters from the end, or inserting new copies of character c.
e. The function call operator, so that s(int start, int length) returns a substring starting at the given position of the given size.
B. Our String class always deletes the old character buffer and reallocates a new character buffer on assignment or in the copy constructor. This need not be done if the new value is smaller than the current value, and hence would fit in the existing buffer. Rewrite the String class so that each instance will maintain an integer data field indicating the size of the buffer, then only reallocate a new buffer when necessary. Abstract the common tasks from the assignment operator and the copy constructor, and place them into an internal method.
Need Solution email me:
topsolutions8@gmail.com
a. A constructor String (int n, char c) that initializes the string with n copies of the character c.
b. The + operator to perform concatenation of two String objects.
c. A member function compare (String) that returns -1, 0, or 1 depending upon whether the string is lexicographically less than, equal to, or greater than the argument. Then, using this member function, provide definitions for the comparison operators <, , and >=.
d. A function resize (int n, char c) that changes the size of the string to n, either truncating characters from the end, or inserting new copies of character c.
e. The function call operator, so that s(int start, int length) returns a substring starting at the given position of the given size.
B. Our String class always deletes the old character buffer and reallocates a new character buffer on assignment or in the copy constructor. This need not be done if the new value is smaller than the current value, and hence would fit in the existing buffer. Rewrite the String class so that each instance will maintain an integer data field indicating the size of the buffer, then only reallocate a new buffer when necessary. Abstract the common tasks from the assignment operator and the copy constructor, and place them into an internal method.
Need Solution email me:
topsolutions8@gmail.com