Advertisement
Guest User

Untitled

a guest
May 26th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.79 KB | None | 0 0
  1. //add appts to linked list----------------------------------------------------------------------------
  2. void ToDo::addAppt(Appointment* appt)
  3. {
  4.     cout << "\nAdding appointment...\n";
  5.  
  6.     if(head == NULL)
  7.     {
  8.         cout << "\nHead is null..\n";
  9.         head = new Cell(appt, head);
  10.     }
  11.     else
  12.     {
  13.         follow = NULL;
  14.         for(scan = head; scan != NULL; scan = scan -> next)
  15.         {
  16.             if((appt->mWhen <= scan->appt->mWhen) == 1)
  17.             {
  18.                 scan->next = new Cell(appt, scan->next);
  19.                 break;
  20.             }
  21.             else if((appt->mWhen == scan->appt->mWhen) && (follow == NULL))
  22.             {
  23.                 head = new Cell(appt, head);
  24.                 break;
  25.             }
  26.             else if((appt->mWhen <= scan->appt->mWhen) == 2 && (follow != NULL))
  27.             {
  28.                 follow->next = new Cell(appt, follow->next);
  29.                 break;
  30.             }
  31.             follow = scan;
  32.         }
  33.     }
  34.  
  35.     ++numCells;
  36. }
  37.  
  38. //date.hpp--------------------------------------
  39. #include "tools.hpp"
  40.  
  41. #define DAYS 13
  42. #define MONTHABR 13
  43.  
  44. class Date {
  45.     friend class ToDo;
  46.     private: //------------------------------------------------------------------------
  47.         time_t intTime;
  48.         struct tm myTime;
  49.         static const int nDays[DAYS];
  50.         static const cstring monthAbr[MONTHABR];
  51.  
  52.     public: //-------------------------------------------------------------------------
  53.         Date(cstring dateString = NULL);
  54.         ~Date();
  55.         void print();
  56.         void format(cstring, bool*, bool*, int*);
  57.         static void instructions();
  58.         static bool valiDate(int month, int day, int year, int hour, int min);
  59.         bool operator<=(const Date & d) const;
  60.         bool operator==(const Date & d) const;
  61.         bool sameDay(const Date & d) const;
  62.         bool sameTime(const Date & d) const;
  63.         friend ostream &operator<<(ostream &stream, const Date o);  //compiler throws me errors if I declare this as anything but a friend, can't access private data memeber.
  64. };
  65.  
  66. //date.cpp--------------------------------------------------------------------------
  67. //compare dates-----------------------------------------------------------------------
  68. bool Date::operator<=(const Date & d) const
  69. {
  70.     if(myTime.tm_mon == d.myTime.tm_mon)
  71.     {
  72.         if(myTime.tm_mday >= d.myTime.tm_mday)
  73.             return 1;  
  74.     }
  75.     else
  76.         return 2;
  77. }
  78.  
  79. //are dates.mon equal?-----------------------------------------------------------------
  80. bool Date::operator==(const Date & d) const
  81. {
  82.     if(myTime.tm_mon <= d.myTime.tm_mon)
  83.         return true;
  84.     else
  85.         return false;
  86. }
  87.  
  88. //are dates.mday equal?-----------------------------------------------------------------
  89. bool Date::sameDay(const Date & d) const
  90. {
  91.     if(myTime.tm_mday == d.myTime.tm_mday)
  92.         return true;
  93.     else
  94.         return false;
  95. }
  96.  
  97. //is time equal?------------------------------------------------------------------------
  98. bool Date::sameTime(const Date & d) const
  99. {
  100.     if((myTime.tm_hour == d.myTime.tm_hour) && (myTime.tm_min == d.myTime.tm_min))
  101.         return true;
  102.     else
  103.         return false;
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement