Unformatted text preview:

MyString h ifndef MYSTRING H define MYSTRING H include iostream using namespace std class MyString Forward Declaration ostream operator ostream const MyString istream operator istream MyString class MyString private char str int len public MyString MyString MyString right MyString char sptr MyString int length const char getValue overloaded operators const MyString operator MyString const char operator const char const MyString operator MyString const char operator const char int operator MyString int operator const char int operator MyString int operator const char bool operator MyString bool operator const char bool operator const char bool operator MyString bool operator const char bool operator MyString bool operator const char bool operator MyString friend ostream operator ostream const MyString friend istream operator istream MyString endif 1 MyString cpp include iostream include MyString h using namespace std MyString MyString str NULL len 0 MyString MyString MyString right str new char right length 1 strcpy str right getValue len right length MyString MyString char sptr len strlen sptr str new char len 1 strcpy str sptr MyString MyString if len 0 delete str int MyString length return len const char MyString getValue return str Overloaded operator Called when operand on the right is another MyString object Returns the calling object const MyString MyString operator MyString right if len 0 delete str str new char right length 1 2 strcpy str right getValue len right length return this Overloaded operator Called when operand on the right is a C string returns the str member of the calling object const char MyString operator const char right if len 0 delete str len strlen right str new char len 1 strcpy str right return str Overloaded operator CAlled when operand on the right is another MyString object Concatenates the str member of right to the str member of the calling object returns the calling object const MyString MyString operator MyString right char temp str str new char strlen str right length 1 strcpy str temp strcat str right getValue if len 0 delete temp len strlen str return this Overloaded operator Called when the operand on the right is a string Concatenates the str member of right to the str member of the calling object Returns the str member of the calling object const char MyString operator const char right char temp str str new char strlen str strlen right 1 strcpy str temp strcat str right if len 0 delete temp return str 3 Overloaded operator Called when the operand on the right is a MyString object Returns true if right str is the same as str int MyString operator MyString right return strcmp str right getValue Overloaded operator Called when the operand on the right is a C String Returns true if right is the same as str int MyString operator const char right return strcmp str right Overloaded operator Called when the operand on the right is a MyString object Returns true if right str is not the same as str int MyString operator MyString right return strcmp str right getValue Overloaded operator Called when the operand on the right is a C String Returns true if right is not the same as str int MyString operator const char right return strcmp str right Overloaded operator Called when the operand on the right is a MyString object Returns true if str is greater than right str bool MyString operator MyString right bool status if strcmp str right getValue 0 status true else status false return status 4 Overloaded operator Called when the operand on the right is a C String Returns true if str is greater than right bool MyString operator const char right bool status if strcmp str right 0 status true else status false return status Overloaded operator Called when the operand on the right is a MyString object Returns true if str is less than right str bool MyString operator MyString right bool status if strcmp str right getValue 0 status true else status false return status Overloaded operator Called when the operand on the right is a C String Returns true if str is less than right bool MyString operator const char right bool status if strcmp str right 0 status true else status false return status Overloaded operator Called when the operand on the right is a MyString object Returns true if str is greater than right str bool MyString operator MyString right bool status 5 if strcmp str right getValue 0 status true else status false return status Overloaded operator Called when the operand on the right is a C String Returns true if str is greater than right bool MyString operator const char right bool status if strcmp str right 0 status true else status false return status Overloaded operator Called when the operand on the right is a MyString object Returns true if str is less than right str bool MyString operator MyString right bool status if strcmp str right getValue 0 status true else status false return status Overloaded operator Called when the operand on the right is a C String Returns true if str is less than right bool MyString operator const char right bool status if strcmp str right 0 status true else status false return status ostream operator ostream strm const MyString obj 6 strm obj str return strm istream operator istream strm MyString obj strm getline obj str obj len strm ignore return strm 7


View Full Document

SMU CSE 2341 - Study Notes

Loading Unlocking...
Login

Join to view Study Notes and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Study Notes and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?