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) {}

// 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(-1) is the biggest size_t there is: 2641 on most machines. Don't mess up by writing a while loop for rfind that says something like while(pos >= 0). Such a while loop would go on forever. Also, don't hack your way around this by converting to ints: that loses information and could create another bug. Instead use a while loop like while(pos != -1). In order to make this comparison, -1 is correctly cast as a size_t. Because size_t cannot be negative you should be careful about subtracting numbers. In substr you may want to check whether pos

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 Databases Questions!