home *** CD-ROM | disk | FTP | other *** search
/ The Devil's Doorknob BBS Capture (1996-2003) / devilsdoorknobbbscapture1996-2003.iso / Dloads / OTHERUTI / MASTER-1.ZIP / SOURCE / CHAP06 / CHAP06.LZH / SORTED.CPP < prev    next >
C/C++ Source or Header  |  1992-07-16  |  2KB  |  85 lines

  1. // SORTED.CPP
  2. // Demonstrates use of the SortedArray class.
  3. // Compile using the Large memory model.
  4. #include <iostream.h>
  5. #include <sortable.h>
  6. #include <sortarry.h>
  7. #include <string.h>
  8. #include <stdlib.h>
  9.  
  10. class TLogEntry : public Sortable {
  11. public:
  12.   TLogEntry(char * NewCallSign,
  13.     char * NewContactNum,
  14.     char * NewExchange,
  15.     int NewMode,
  16.     int NewBand,
  17.     long NewTime,
  18.     long NewDate ) : Sortable () {
  19.       strcpy( CallSign, NewCallSign );
  20.       strcpy( ContactNum, NewContactNum );
  21.       strcpy( Exchange, NewExchange );
  22.       Mode = NewMode;
  23.       Band = NewBand;
  24.       ContactTime = NewTime;
  25.       ContactDate = NewDate;
  26.        }
  27.   virtual hashValueType hashValue() const;
  28.   virtual classType isA() const {return __firstUserClass;}
  29.   virtual int isEqual( const Object& testObject) const
  30.      { if (stricmp( ((TLogEntry&)testObject).CallSign, CallSign ))
  31.        return 0;
  32.        else return 1;
  33.      }
  34.   virtual int isLessThan( const Object& Obj1 ) const
  35.   {  if (stricmp( ((TLogEntry&)Obj1).CallSign, CallSign ) > 0)
  36.        return 1;
  37.        else return 0;
  38.   }
  39.   virtual char *nameOf() const {return "TLogEntry";}
  40.   virtual void printOn( ostream& outputStream) const
  41.       { outputStream << CallSign;}
  42.   friend void Display(Object& o, void * );
  43. private:
  44.   char CallSign[11];
  45.   char ContactNum[11];
  46.   char Exchange[35];
  47.   int Mode, Band;
  48.   long ContactTime;
  49.   long ContactDate;
  50. };
  51.  
  52. hashValueType TLogEntry::hashValue() const
  53. {
  54.   return atoi( ContactNum );
  55. }
  56.  
  57.  
  58. void Display(Object& o, void * )
  59. {
  60.   cout << ((TLogEntry&)o).ContactNum << " " <<
  61.       ((TLogEntry&) o).CallSign << "\n";
  62. };
  63.  
  64. void main(void)
  65. {
  66.   SortedArray LogBook( 30 );
  67.   TLogEntry Contact1( "KF7VY", "0001", "59 EWA", 0, 0, 0, 0 );
  68.   TLogEntry Contact2( "N7VPL", "0002", "59 EWA", 0, 0, 0, 0 );
  69.   TLogEntry Contact3( "W6ZRJ", "0003", "59 SCV", 0, 0, 0, 0 );
  70.   TLogEntry Contact4( "N6IIU", "0004", "59 SF", 0, 0, 0, 0 );
  71.   TLogEntry Contact5( "N7LCG", "0005", "59 WWA", 0, 0, 0, 0 );
  72.  
  73.   LogBook.add( Contact1 );
  74.   LogBook.add( Contact2 );
  75.   LogBook.add( Contact3 );
  76.   LogBook.add( Contact4 );
  77.   LogBook.add( Contact5 );
  78.  
  79.   cout << "Total number of items in bag = " <<
  80.       LogBook.getItemsInContainer() << "\n";
  81.   LogBook.forEach( Display, NULL );
  82.  
  83.   LogBook.flush();
  84. }
  85.