C++小项目-----日历系统

项目展示

项目代码:

#include<iostream>
#include<iomanip>
using namespace std;

int Date(int y, int m, int d)
{
	int week;
	if (m == 1 || m == 2)
	{
		y = y - 1;
		m = m + 12;
	}

	week = (d + 2 * m + 3 * (m + 1) / 5 + y + y / 4 - y / 100 + y / 400 + 1) % 7;  //利用基姆拉尔森计算公式计算某年某月某日是星期几
	                                                                              //(其中基姆拉尔森计算公式:
	                                                                             //W = (d + 2 * m + 3 * (m + 1) / 5 + y + y / 4 - y / 100 + y / 400 + 1) % 7
	return week;
}

int DayNumofMonth(int y, int m)
{
	int monthmax = 0;
	switch (m)
	{
	case 1:
	case 3:
	case 5:
	case 7:
	case 8:
	case 10:
	case 12:
		monthmax = 31;
		break;
	case 4:
	case 6:
	case 9:
	case 11:
		monthmax = 30;
		break;
	case 2:
		if (y % 4 == 0 && y % 100 != 0 || y % 400 == 0)
			monthmax = 29;
		else
			monthmax = 28;
	}
	return monthmax;
}

void DisCalendar(int y, int m)
{
	//标题模块
	cout << "    公元 " << y << "年    第" << m << "月日历" << endl;
	int a = 1;
	for (a = 0; a < 7; a++)
		cout << setw(5) << a;
	cout << endl << "===========================================" << endl;

	//日期模块
	int Date(int y, int m, int d);
	int b = 0, week;
	week = Date(y, m, 1);
	for (b = 0; b < week; b++)
		cout << setw(5) << " ";//每月一号对应的周几前面要有缩进
	int DayNumofMonth(int y, int m);
	int c = 1, monthmax;
	monthmax = DayNumofMonth(y, m);
	while(c <= monthmax)
	{
		cout << setw(5) << c;
		c++;
		week++;
		if (week % 7 == 0)
			cout << endl;
	}
	cout << endl << "===========================================" << endl;
}

//增加菜单模块
void MenuFunc()
{
	while (1)
	{
		int n;
		cout << "***************************" << endl;
		cout << "请输入1或0进入程序" << endl << "1----日历查询" << endl << "0----推出程序" << endl;
		cout << "***************************" << endl;
		cin >> n;
		if (n == 0)
			break;
		if (n == 1)
		{
			int y, m;
			cout << "请输入年份:";
			cin >> y;
			cout << "请输入月份:";
			cin >> m;
			cout << endl;
			void DisCalendar(int y, int m);
			DisCalendar(y, m);
		}
	}
}

int main()
{
	MenuFunc();
	return 0;
}

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值