万年历
说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。
#include int mon_day[12]={31,28,31,30,31,30,31,31,30,31,30,31}; class CDate { private: int year,month,day; public: CDate(){year=0;month=0;day=0;} CDate(int y,int m,int d) {year=y;month=m;day=d;} void output() {cout< void week()
{char w[7][20]={"星期一","星期二","星期三","星期四","星期五","星期六","星期日"}; char *p[7]={w[0],w[1],w[2],w[3],w[4],w[5],w[6]}; int c;int i;int y;
c=year/100;y=year%100;
i=(((c/4)-2*c+y+(y/4)+(13*(month+1)/5)+day-1)+700)%7; //百度搜的公式 cout<<"This day is:"<<*(p+i-1)<} /**/void input() { cout<<"请输入当前日期!\n"; cout<<"年份:"; cin>>year; cout<<"月份:"; cin>>month; cout<<"日期:"; cin>>day; }
/**/ friend CDate operator+(int d,CDate dt)
{if(dt.year/4==0&&dt.year/100!=0||dt.year/400==0) mon_day[2]=29;
/*// int mon_day[12]={31,28,31,30,31,30,31,31,30,31,30,31}; ; else mon_day[]={31,28,31,30,31,30,31,31,30,31,30,31};*/
dt.day=d+dt.day; while(dt.day>mon_day[dt.month-1]) { dt.day-=mon_day[dt.month-1]; if(++dt.month==13) {dt.month=1; dt.year++;} } return dt; }
friend int operator-(CDate da2,CDate da1)
{int sum=0;/*cout<
if(da2.year==da1.year&&da2.month==da1.month&&da2.day!=da1.day) 月不同日 {
sum=da2.day-da1.day; }
if(da2.year==da1.year&&da2.month>da1.month) //同年不同月 {
for(int i=da1.month;i {
sum+=mon_day[i]; }
sum+=da2.day+(mon_day[da1.month-1]-da1.day); } else {
for(int i=da1.year+1;i { if(i/4==0&&i/100!=0||i/400==0)
sum+=366; else
sum+=365; }
for(int m=da1.month;m<13;m++) {
sum+=mon_day[m-1]; }cout<<"sum="< // sum+=da.lDays;
for(int n=1;n
//同年同
{
sum+=mon_day[n]; }
sum+=da2.day; }/**/
return sum; } };
int main() { CDate d(2000,03,29); cout<<"标准日期为:"; d.output();d.week(); cout<<"标准日期+100天后日期为:"; CDate d1;d1=100+d; d1.output();d1.week(); CDate d2; d2.input();d2.output();d2.week(); cout<<"当前日期与标准日期之间的天数为:"; int f; f=d2-d; cout< return 0; }
本文来源:https://www.wddqw.com/doc/13cbbb24192e45361066f5f6.html