【C++】日期计算机
欢迎大家来到小恶魔频道
好久不见,甚是想念
今天我们要讲述的是一个日期类计算机的代码实现
引言:
我们日常生活中可能会有一个烦恼。
今天几月几号?过n天后又是几月几号?某年某月某天和x年x月x天相差几天?你和男/女朋友的相识了几天?等等。这些问题好麻烦,我不想去算,所以我们的日期计算机也就油然而生了。
头文件的准备
头文件的声明代码:
#pragma once #include #inclu using namespace std; class Date { public: // 获取某年某月的天数 int GetMonthDay(int year, int month) { static int days[13] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31,30,31 }; int day = days[month]; if (month == 2 && (year & 4 == 0 && year % 100 != 0) || (year % 400 == 0)) { day += 1; } return day; } //打印函数 void Print() { cout
文章版权声明:除非注明,否则均为主机测评原创文章,转载或复制请以超链接形式并注明出处。