Question
//codes in DynamicString.cpp #include DynamicString.h int DynamicString::myStringLen(const char* str){ //TODO::Implement me return -1; } DynamicString::DynamicString(){ //TODO::1::Implement me } DynamicString::DynamicString(const char* str){ //TODO::1::Implement me } int
//codes in DynamicString.cpp
#include "DynamicString.h"
int DynamicString::myStringLen(const char* str){ //TODO::Implement me return -1; }
DynamicString::DynamicString(){ //TODO::1::Implement me }
DynamicString::DynamicString(const char* str){ //TODO::1::Implement me }
int DynamicString::len() const{ //TODO::1::Implement me return -1; }
const char* DynamicString::c_str() const{ //TODO::1::Implement me return nullptr; }
char& DynamicString::char_at(int position){ //TODO::1::Implement me char* a = new char('a'); return *a; }
char DynamicString::char_at(int position) const{ //TODO::1::Implement me return 'a'; }
char& DynamicString::operator[](int position){ //TODO::1::Implement me char* a = new char('a'); return *a; }
char DynamicString::operator[](int position) const{ //TODO::1::Implement me return 'a'; }
bool DynamicString::isPrefix(const DynamicString& other) const{ //TODO::1::Implement me return false; }
bool DynamicString::isIPrefix(const DynamicString& other) const{ //TODO::1::Implement me return false; }
bool DynamicString::isSuffix(const DynamicString& other) const{ //TODO::1::Implement me return false; }
bool DynamicString::isISuffix(const DynamicString& other) const{ //TODO::1::Implement me return false; }
int DynamicString::compare(const DynamicString& other) const{ //TODO::1::Implement me return 0; }
int DynamicString::iCompare(const DynamicString& other) const{ //TODO::1::Implement me return 0; }
DynamicString& DynamicString::toLower(){ //TODO::1::Implement me return *this; }
DynamicString& DynamicString::toUpper(){ //TODO::1::Implement me return *this; }
DynamicString::DynamicString(const DynamicString& other){ //TODO::2::Implement me }
DynamicString::~DynamicString(){ //TODO::2::Implement me }
DynamicString& DynamicString::operator=(const DynamicString& other){ //TODO::2::Implement me return *this; }
DynamicString DynamicString::trim(){ //TODO::2::Implement me return *this; }
DynamicString DynamicString::operator+(const DynamicString& other) const{ //TODO::2::Implement me return *this; }
DynamicString DynamicString::concat(const DynamicString& other) const{ //TODO::2::Implement me return *this; }
int DynamicString::find(int start, char c) const{ //TODO::2::Implement me return -1; }
int DynamicString::reverseFind(int start, char c) const{ //TODO::2::Implement me return -1; }
void DynamicString::subStr(char* buf, int start, int end) const{ //TODO::2::Implement me }
String Library Part 2 Assignment
When implementing the String class you are not allowed to use the string header file, cstring header file or C++ strings.
Requirements:
Implement the following string methods correctly and pass all the test cases. There shouldn't be any memory leaks.
- DynamicString() //Constructs an empty string
- DynamicString(const char* str) //Constructs a string by copying the characters from he char array str
- int len() const //returns the length of this string
- const char* c_str() const // returns a pointer to the underlying char array
- char& char_at(int position) //returns the char at the specified position
- char char_at(int position) const // returns the char at the specified position
- char& operator[](int position) // returns the char at the specified position
- char operator[](int position) const // returns the char at the specified position
- bool isPrefix(const DynamicString& other) const //True if other is a prefix of this string
- bool isIPrefix(const DynamicString& other) const //True if other is a prefix of this string ignoring case(capitalization)
- bool isSuffix(const DynamicString& other) const //True if other is a suffix of this string
- bool isISuffix(const DynamicString& other) const //True if other is a suffix of this string ignoring case (capitalization)
- int compare(const DynamicString& other) const // negative if this is smaller than other, 0 if this is equal to other, positive if this is larger than other
- int iCompare(const DynamicString& other) const // same as compare but is case-insensetive
- DynamicString& toLower() // converts the string to lowercase
- DynamicString& toUpper() // converts the string to uppercase
- DynamicString(const DynamicString& other) //Creates a deep-copy of other
- DynamicString& operator=(const DynamicString& other) //Creates a deep-copy of other and assigns it to this
- ~DynamicString() //Destructor frees dynamically allocated memory
- DynamicString& DynamicString::trim() //Removes leading and trailing whitespace characters from the string
- DynamicString DynamicString::operator+(const DynamicString& other) const //Concatenates this with other and returns a copy of the concatenation.
- DynamicString DynamicString::concat(const DynamicString& other) const //Concatenates this with other and returns a copy of the concatenation.
- int DynamicString::find(int start, char c) const //Return the index of the first occurrence of the char c. (-1 if the char c is not in the string)
- int DynamicString::reverseFind(int start, char c) const //Return the index of the last occurrence of the char c. (-1 if the char c is not in the string)
- void DynamicString::subStr(char* buf, int start, int end) const //Stores a substring of this in buf. The substring starts at start (inclusive) and ends at end (exclusive).
Helpful C++ library methods:
- tolower
- toupper
- out_of_range
- isspace
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started