本程序演示了日期的基本计算方法,目的计算两个日期之间相差的天数,并且计算填入的日期当天是星期几,此演示程序主要是使用VS2010,但这个程序可以支持Linux的使用,如需在Linux上使用请自行修改。
#include "stdafx.h"
#include <iostream>
using namespace std;
struct Date{
int year;
int month;
int day;
};
//计算是否为闰年
bool isLeapYear(int year)
{
return (year%4==0&&year%100!=0)||year%400==0;
}
//计算每个月的天数
int daysOfMonth(int month,int year)
{
switch(month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
return 31;
break;
#include "stdafx.h"
#include <iostream>
using namespace std;
struct Date{
int year;
int month;
int day;
};
//计算是否为闰年
bool isLeapYear(int year)
{
return (year%4==0&&year%100!=0)||year%400==0;
}
//计算每个月的天数
int daysOfMonth(int month,int year)
{
switch(month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
return 31;
break;