设计思路:
数据层:
#pragma once
#include <ctime>
#include <iostream>
using namespace std;
class ViewDate;
//数据层 --- 进行所有的数据处理
class ModelDate
{
private:
ViewDate* view; //数据层连接显示层
private:
int year;
int month;
int mday; //今天是几号
int curweek; //当天星期
int hour;
int min;
int sec;
int oneweek; //本月1号星期
int mdays; //本月天数
static bool Is_Leap(int y);
static int GetYM_Days(int y, int m);
static int Get_Week(int y, int m, int d = 1);
public:
int GetYear()const; //年
int GetMonth()const; //月
int GetMday()const; //日
int GetCurweek()const; //星期
int GetHour()const; //小时
int GetMin()const; //分
int GetSec()const; //秒
int GetMdays()const; //本月天数
int GetOneweek()const; //本月1号星期
public:
ModelDate();
~ModelDate();
void SetView(ViewDate* pview);
void Now();
void NextMonth();
void PrevMonth();
void NextYear();
void PrevYear();
};
#include"Model.h"
#include"View.h"
//常用静态方法
bool ModelDate::Is_Leap(int y)
{
return (y % 4 == 0 && y % 100 == 0) || (y % 400 == 0);
}
int ModelDate::GetYM_Days(int y, int m)
{
static const int days[] = { 29,31,28,31,30,31,30,31,31,30,31,30,31 };
// 0 1 2 3 4 5 6 7 8 9 10 11 12
if (m == 2 && Is_Leap(y))
{
m = 0;
}
return days[m];
}
int ModelDate::Get_Week(int y, int m, int d)
{
int c = y / 100; //世纪-1
y %= 100; //年份后两位
if (m == 1 || m == 2) //月份>=3 <=14
{
m += 12;
}
return (y +