Question: Implement the following string methods in DynamicString.cpp: DynamicString ( ) / / Constructs an empty string. Allocating enough memory to store the null character DynamicString

Implement the following string methods in DynamicString.cpp:
DynamicString()// Constructs an empty string. Allocating enough memory to store the null character
DynamicString(const char* str)// Constructs a string by copying the characters from the char array str to this object. You should dynamically allocate enough memory for the entire string.
DynamicString(const DynamicString& other)// Constructs a string by copying the characters from the "other" DynamicString object. You should dynamically allocate enough memory for the entire string.
~DynamicString()// Deletes the memory used for storing the char array since this DynamicString object is being destroyed.
DynamicString& operator=(const DynamicString& other)// Deletes the memory previously used for storing the char array and creates a new array. The characters from the "other" DynamicString are copied into this array.
int len() const // Returns the length of this string (i.e. the number of characters in the array not including the null char)
const char* c_str() const // Returns a pointer to the underlying char array
char char_at(int position) const // Returns the char at the specified position
char& operator // Returns the char at the specified position
bool startsWith(const DynamicString& other) const // Returns true if other is a prefix of this string
bool endsWith(const DynamicString& other) const // Returns rue if other is a suffix of this string
int compare(const DynamicString& other) const // Returns a negative integer if this is less than other, 0 if this is equal to other, and a positive integer if this is larger than other. Note that for strings, "a" is less than "b", as "a" comes in the dictionary before "b". Likewise "a" comes before "aa" in the dictionary. Computer case sensitivity also applies which naturally makes "A"<"a".
DynamicString& toLower()// Converts the string to lowercase
DynamicString& toUpper()// Converts the string to uppercase
DynamicString& replace(char old, char new)// Replace all instances of old with new
int find(char needle, int start=0) const // Return the first index of the specified char or -1 if the char is not found starting from index start.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!