功能;
有参构造
设置时间
日历加一
输出时间
#includeclass CDate{public: CDate(int Year, int Month, int Day) :m_Year(Year), m_Month(Month), m_Day(Day) {}; void oper() { isFlag(); if (flag == 0) { dayAdd(29); } else { dayAdd(28); } if (m_Month > 12) { m_Month = 1; m_Year++; } show(); }; void setDate(int Year, int Month, int Day) { m_Year = Year; m_Month = Month; m_Day = Day; } void show() { std::cout << m_Year << "/" << m_Month << "/" << m_Day << std::endl; }private: int m_Year; int m_Month; int m_Day; int flag = 0; void isFlag() { if (m_Year % 400 == 0) flag = 0; else { if (m_Year % 4 == 0 && m_Year % 100 != 0) flag = 0; else flag = 1; } } void dayAdd(int m) { switch (m_Month) { case 1: { m_Day++; if (m_Day > 31) { m_Day = 1; m_Month++; } }break; case 2: { m_Day++; if (m_Day > m) { m_Day = 1; m_Month++; } }break; case 3: { m_Day++; if (m_Day > 31) { m_Day = 1; m_Month++; } }break; case 4: { m_Day++; if (m_Day > 30) { m_Day = 1; m_Month++; } }break; case 5: { m_Day++; if (m_Day > 31) { m_Day = 1; m_Month++; } }break; case 6: { m_Day++; if (m_Day > 30) { m_Day = 1; m_Month++; } }break; case 7: { m_Day++; if (m_Day > 31) { m_Day = 1; m_Month++; } }break; case 8: { m_Day++; if (m_Day > 31) { m_Day = 1; m_Month++; } }break; case 9: { m_Day++; if (m_Day > 30) { m_Day = 1; m_Month++; } }break; case 10: { m_Day++; if (m_Day > 31) { m_Day = 1; m_Month++; } }break; case 11: { m_Day++; if (m_Day > 30) { m_Day = 1; m_Month++; } }break; case 12: { m_Day++; if (m_Day > 31) { m_Day = 1; m_Month++; } }break; default: break; } }};int main(){ CDate cdt(2010, 2, 28); cdt.show(); cdt.oper();}