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
DynamicStringconst 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.
DynamicStringconst 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& operatorconst 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 ie the number of characters in the array not including the null char
const char cstr const Returns a pointer to the underlying char array
char charatint position const Returns the char at the specified position
char& operator Returns the char at the specified position
bool startsWithconst DynamicString& other const Returns true if other is a prefix of this string
bool endsWithconst DynamicString& other const Returns rue if other is a suffix of this string
int compareconst DynamicString& other const Returns a negative integer if this is less than other, 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 Aa
DynamicString& toLower Converts the string to lowercase
DynamicString& toUpper Converts the string to uppercase
DynamicString& replacechar old, char new Replace all instances of old with new
int findchar needle, int start const Return the first index of the specified char or 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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
