home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / yacl-012.zip / basedemo / remind2 / remind.cxx < prev   
C/C++ Source or Header  |  1995-03-07  |  2KB  |  64 lines

  1.  
  2.  
  3. // A second version of the reminder program: prints out the data in
  4. // chronological order.
  5. //
  6. // M. A. Sridhar
  7. // Feb 13, 1994
  8.  
  9. #include <iostream.h>
  10. #include "base/base.h"
  11.  
  12. class ReminderEntry: public CL_Object {
  13.  
  14. public:
  15.     ReminderEntry (const CL_Date& dt, const CL_String& msg)
  16.         : _date (dt), _msg (msg) {};
  17.     const CL_Date&   Date () const {return _date;};
  18.     const CL_String& Message () const {return _msg;};
  19.     
  20.     short Compare (const CL_Object&) const;
  21.     // Override inherited Compare, so that sorting is possible
  22.  
  23. protected:
  24.     // Data elements:
  25.     CL_Date _date;
  26.     CL_String _msg;
  27. };
  28.  
  29.  
  30. short ReminderEntry::Compare (const CL_Object& o) const
  31. {
  32.     const ReminderEntry& entry = (const ReminderEntry&) o; // Cast down
  33.     short r = _date.Compare (entry._date);
  34.     return r ? r : _msg.Compare (entry._msg);
  35. }
  36.  
  37.  
  38.  
  39. // -------------------------- Main program --------------------------    
  40.  
  41. void main ()
  42. {
  43.     CL_Date today = CL_Date::Today();
  44.     CL_String s;
  45.     CL_ObjectSequence result;
  46.     while (s.ReadLine (cin)) {
  47.         if (s.Size() <= 0) continue; // Allow for blank lines
  48.         CL_String fld[2];
  49.         s.Split (fld, 2);
  50.         short month = fld[0].Field (1, "/").AsLong();
  51.         short day   = fld[0].Field (2, "/").AsLong();
  52.         CL_Date date (today.Year(), month, day);
  53.         if (date.IsLegal() && date.IsBetween (today, today+4))
  54.             result.Add (new ReminderEntry (date, fld[1]));
  55.     }
  56.     result.Sort ();
  57.     for (short i = 0; i < result.Size(); i++) {
  58.         ReminderEntry* p = (ReminderEntry*) result[i];
  59.         cout << p->Date() << ":" << p->Message() << endl;
  60.     }
  61.     result.DestroyContents(); // Prevent memory leaks
  62. }
  63.  
  64.