home *** CD-ROM | disk | FTP | other *** search
- /* Copyright (c) IBM Corp. 1992 */
- #include <stdio.h>
- #include <string.h>
-
-
-
-
- /*-------------------------- Demonstration class ---------------------------*\
- * *
- | Class Word; |
- | |
- | This class contains pointers to strings (words). |
- | Only the pointers are kept in the instance variable. |
- | |
- | Instances can return the theWord pointer. |
- | |
- | Instances can be compared to each other. They have to be able to be |
- | because the list might want to sort the elements. |
- * *
- \*--------------------------------------------------------------------------*/
-
- class Word
- {
- private:
- char *theWord; // Our own copy of the word
- public:
- /*--------------------------------------------------------------------*\
- * Constructors/destructors *
- \*--------------------------------------------------------------------*/
- Word() { // Constructor
- theWord = 0;
- }
- Word(Word const & word) { // copy Constructor
- theWord = word.theWord;
- }
- Word(char *aString) {
- theWord = aString;
- }
- ~Word() { // Destructor
- }
-
- /*--------------------------------------------------------------------*\
- * Member functions *
- \*--------------------------------------------------------------------*/
- char * getElement() const {
- return theWord;
- }
- void fill(char *aString) { // Modify contents
- theWord = aString; // Point to new string
- }
-
- /*--------------------------------------------------------------------*\
- * (In-)Equality operators overloading *
- \*--------------------------------------------------------------------*/
- int operator == (Word const &anOther) const {
- return (strcmp(theWord,anOther.theWord) == 0);
- }
- int operator != (Word const &anOther) const {
- return !(*this == anOther);
- }
- /*--------------------------------------------------------------------*\
- * Ordering operators overloading *
- \*--------------------------------------------------------------------*/
- int operator < (Word const &anOther) const {
- return (strcmp(theWord,anOther.theWord) < 0);
- }
- int operator > (Word const &anOther) const {
- return (strcmp(theWord,anOther.theWord) > 0);
- }
- int operator <= (Word const &anOther) const { return !(*this > anOther); }
- int operator >= (Word const &anOther) const { return !(*this < anOther); }
-
- };
-