Advertisement
Guest User

Untitled

a guest
Mar 29th, 2017
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.96 KB | None | 0 0
  1.     data data::operator+=(const data &d)
  2.     {        
  3.         return data(this->day + d.day, this->month + d.month, this->year + d.year);
  4.     }
  5.    
  6.     data data::operator+=(const int &d)
  7.     {
  8.         data temp(day,month,year);
  9.         temp.day = temp.day + d;
  10.        
  11.         for(int i = 0;i<=20;i++)
  12.         {
  13.             if(temp.month == 1 || temp.month == 3 || temp.month == 5 || temp.month == 7 || temp.month == 8 || temp.month == 10 || temp.month == 12)
  14.             {
  15.                 if (temp.day>31)
  16.                 {
  17.                     temp.month++;
  18.                     temp.day = temp.day - 31;
  19.                 }
  20.             }
  21.             if(temp.month == 4 || temp.month == 6 || temp.month == 9 || temp.month == 11  )
  22.             {
  23.                 if (temp.day>30)
  24.                 {
  25.                     temp.month++;
  26.                     temp.day = temp.day - 30;
  27.                 }
  28.             }
  29.             else if(temp.day>28)
  30.             {
  31.                 temp.month++;
  32.                 temp.day = temp.day - 28;
  33.             }
  34.             if(temp.month>12)
  35.             {
  36.                 temp.year++;
  37.                 temp.month = temp.month - 12;
  38.             }
  39.         }
  40.  
  41.         return temp;
  42.        
  43.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement