C++模块化设计---日历系统

本文探讨了使用C++进行模块化设计来构建一个日历系统的思路。内容涵盖了数据层、显示层和控制层的划分,旨在实现清晰的代码结构和高效的客户端交互。
摘要由CSDN通过智能技术生成

设计思路:

数据层:

#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 +
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值