Question: // hpp MyString() : s(0) {} MyString(char c) : s(1,c) {} MyString substr(size_t pos, size_t len = -1) const; MyString(size_t n) :s(n) {} MyString(size_t n,

// hpp
MyString() : s(0) {} MyString(char c) : s(1,c) {}
MyString substr(size_t pos, size_t len = -1) const;
MyString(size_t n) :s(n) {} MyString(size_t n, char c) : s(n, c) {}
size_t find(char c, size_t pos = 0) const; size_t rfind(char c, size_t pos = -1) const;
size_t find(const MyString& str, size_t pos = 0) const; size_t rfind(const MyString& str, size_t pos = -1) const;
// cpp
size_t MyString::find(char c, size_t pos) const {
// fill
return -1;
}
size_t MyString::rfind(char c, size_t pos) const {
// fill return -1; }
MyString MyString::substr(size_t pos, size_t len) const {
// fill
return MyString(subs); }
size_t MyString::find(const MyString& str, size_t pos) const { // fill return -1; }
size_t MyString::rfind(const MyString& str, size_t pos) const { // fill return -1; }
// main - test
int main() {
cout
cout
return 0;
}
In MyString.cpp, give appropriate definitions for substr, and overloaded find and rfind. DO NOT DELETE #include "students-ignore3.h". Some important comments: In MyString.cpp I have put the "empty" function definitions in order from easiest to most difficult. You can find good descriptions of what these functions are supposed to do here, although you should be familiar with what they are supposed to do already! The first declaration of find reads size_t find (char c, size_t pos = 0) const; This means that if str is an instance of MyString, calling str.find('!') is the same as calling str.find('!',0). When pos is not specified it takes on the default value of 0. You should write your definition to work for any value of pos. Notice that a size_t can never be negative. When I return -1 in the empty" definitions, that is cast to a size_t and static_cast
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
