Homework 3: STRING MANIPULATION

Write a program that adds to the functionality of the class my_string on either page 176 (or more advanced page 198) of the text. Add the fol- lowing member functions:

class my_string{ };

int my_string::length(); /*return length*/

/* substring of n characters starting from first */

my_string my_string::substr(int first, int n);

/*replace from f1- n1 chars using str from f2 with n2 chars*/

my_string& my_string::replace(int f1, int n1, my_string& str, int f2, int n2);

/* return position or -1 if not found of str inside *this */

int my_string::find(my_string str);

Use asserts where appropriate to test pre- and postconditions. In main() test each member function- showing your input data and the appropriate output testing each member function. Use a favorite poem of at least 8 lines of text and print the original poem and the poem modified by replacing various pieces of text.

Due Date: In class April 29, 1997.