mramine364

date.h

Mar 12th, 2016
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.70 KB | None | 0 0
  1. #ifndef DATE_PRO_DATE_H
  2. #define DATE_PRO_DATE_H
  3.  
  4. #include <iostream>
  5.  
  6. using namespace std;
  7.  
  8. class date {
  9. private:
  10.     int day, month, year;
  11.     int getWday();
  12.     int *months_days;
  13.     void init();
  14.     void update_months_days();
  15.     void increment();
  16.     void decrement();
  17.  
  18. public:
  19.     date();
  20.     date(date const& d);
  21.     date(int d,int m, int y);
  22.     date(int m, int y);
  23.     date(int y);
  24.  
  25.     ~date(){
  26.         delete[] months_days;
  27.     }
  28.  
  29.     bool isBissextile();
  30.  
  31.     friend ostream &operator<<(ostream &out, date const& d);
  32.     void PrintDate();
  33.  
  34.     date operator++(int); // post fix
  35.     date operator--(int);
  36.     date operator++(); // pre fix
  37.     date operator--();
  38.     date operator+(int d);
  39.     date operator+=(int d);
  40.     date operator-(int d);
  41.     date operator-=(int d);
  42.  
  43.     bool operator==(date const& d);
  44.     bool operator!=(date const& d);
  45.     bool operator<(date const& d);
  46.     bool operator<=(date const& d);
  47.     bool operator>(date const& d);
  48.     bool operator>=(date const& d);
  49.  
  50.     int operator-(date const& d);
  51.  
  52.     int getDay() const {
  53.         return day;
  54.     }
  55.  
  56.     void setDay(int day) {
  57.         this->day = (day < 1) ? 1 : ( (day > months_days[month - 1]) ? months_days[month - 1] : day );
  58.     }
  59.  
  60.     int getYear() const {
  61.         return year;
  62.     }
  63.  
  64.     void setYear(int year) {
  65.         this->year = (year < 1) ? 1 : year;  //cout << "1 \n";
  66.         update_months_days();  //cout << "1 \n";
  67.         setDay(day);
  68.     }
  69.  
  70.     int getMonth() const {
  71.         return month;
  72.     }
  73.  
  74.     void setMonth(int month) {
  75.         this->month = (month < 1) ? 1 : ( (month > 12) ? 12 : month );
  76.         setDay(day);
  77.     }
  78.  
  79. };
  80.  
  81. #endif //DATE_PRO_DATE_H
Advertisement
Add Comment
Please, Sign In to add comment