#include "..\std_lib_facilities.h"

struct Date {
    int y;  /// year
    int m;  /// month
    int d;  /// day
    void showDate();
};

void Date::showDate() {
    cout << '(' << m << "," << d << "," << y << ')';
}

/// helper functions:
/**if (year is not exactly divisible by 4) then (it is a common year)
else
if (year is not exactly divisible by 100) then (it is a leap year)
else
if (year is not exactly divisible by 400) then (it is a common year)
else (it is a leap year)
The years 2000 and 2400 are leap years,
while 1800, 1900, 2100, 2200, 2300 and 2500 are common years.
    */
bool isLeapYear(int y) {
    if(y%4!=0) return false;
    else if(y%100!=0) return true;
    else if(y%400!=0) return false;
    else return true;
}

void init_day(Date& dd, int y, int m, int d) {
/// check that (y,m,d) is a valid date
    if(m>12 || m < 1 || d<1)
        cerr << "\nThat's an invalid month or day."
             << endl;
    if(m==2) {
        if(isLeapYear(y))
            if(d>29)
                cerr << "\nNot more than 29 days in a leap year."
                     << endl;
    }   else if(d>28)
            cerr << "\nNot more than 28 days in a leap year."
                 << endl;
    if(m==1||m==3||m==5||m==7||m==8||m==10||m==12)
        if(d>31)
             cerr << "\nNot more than 31 days in month " << m
                  << endl;
    else if (d>30)
        cerr << "\nNot more than 30 days in month " << m
             << endl;
/// if it is, use it to initialize dd
    dd.d = d;
    dd.m = m;
    dd.y = y;
}

///================================================
/// increase dd by 1 day
void add_one_day(Date& dd)
{
    if(dd.m==2) {
        if(dd.d == 29) {
            dd.d=0;
            ++dd.m;
            cout << '*' << endl;
        }
        /**if(isLeapYear(dd.y) && dd.d==28) {
            ++dd.d;
        }*/
        else if(dd.d==28) {
            dd.d=0;
            ++dd.m;
            cout << '^' << endl;
        }
    }
    else if((dd.m==1||dd.m==3||dd.m==5||dd.m==7||dd.m==8||dd.m==10)&&dd.d==31) {
        dd.d=0;
        ++dd.m;
        cout << '%' << endl;
    }
    else if(dd.m==12 && dd.d==31) {
        cout << "\nhaha\n";
        dd.d=0;
        dd.m=1;
        ++dd.y;
    }
    else if((dd.m==4||dd.m==6||dd.m==9||dd.m==11) && dd.d==30) {
        dd.d=0;
        ++dd.m;
        cout << '+' << endl;
    }
    ++dd.d;
    cout << '.';
}

/// increase dd by n days
void add_days(Date& dd, int n) {
    for(int i = 0; i < n; ++i)
        add_one_day(dd);
}
