用C++设计一个日历程序

2020-04-17 宠物 142阅读
#include "iostream"
#include "string"
#include "iomanip"
using namespace std;
int monthdays[12]={31,28,31,30,31,30,31,31,30,31,30,31};
string weekday[7]={"星期天","星期一","星期二","星期三","星期四","星期五","星期六"};
string monthname[12]={"January","February","March","April","May","June","July","August","September","October","November","December"};
string tiangan[10]={"甲","乙","丙","丁","戊","己","庚","辛","壬","癸"};
string dizhi[12]={"子","丑","寅","卯","辰","巳","午","未","申","酉","戌","亥"};
string shengxiao[12]={"鼠","牛","虎","兔","龙","蛇","马","羊","猴","鸡","狗","猪"};
void showcalendar(int f);
void showpermoncal(int mon,int monthweek,int flag);
int main()
{
int f;
cout<<"请选择操作:"< cin>>f;

showcalendar(f);
return 0;
}
void showcalendar(int f)
{
int year,month,day;
int flag=0,mon=1;
int monthweek,week;
int totaldays;
int T,D,S;//天干,地支,生肖
cout<<"请输入年份: ";
cin>>year;
totaldays=(year-1)*365+(year-1)/4+(year-1)/400-(year-1)/100;
week=(totaldays+1)%7;
monthweek=week;

T=(year+6)%10;
D=(year+8)%12;
S=D;
if((year%4==0&&year%100!=0)||(year%400==0)) flag=1;
cout< cout<<" "< cout<<" 农历"< if(f>=2)
{
cout<<"请输入月份: ";
cin>>month;
if(f==3)
{
cout<<"请输入日期: ";
cin>>day;
while(mon totaldays+=monthdays[mon++-1];
if(month>2&&flag) totaldays++;
totaldays=totaldays+day-1;
week=(totaldays+1)%7;
cout< return;
}
while(mon<=12)
{
if(mon==month)
{showpermoncal(mon,monthweek,flag); break;}
if(mon==2&&flag) monthweek++;
monthweek=(monthweek+monthdays[mon++-1])%7;
}
return;
}
while(mon<=12)
{
showpermoncal(mon,monthweek,flag);
if(mon==2&&flag) monthweek++;
monthweek=(monthweek+monthdays[mon++-1])%7;
}

}
void showpermoncal(int mon,int monthweek,int flag)
{
cout< cout<<"***************"< cout<<"Sun Mon Tue Wen Tur Fri Sat"< for(int i=0;i for(int j=0;j {
cout< if((j+1+monthweek)%7==0) cout< }
if(mon==2&&flag) cout<<"29";
cout<}
声明:你问我答网所有作品(图文、音视频)均由用户自行上传分享,仅供网友学习交流。若您的权利被侵害,请联系fangmu6661024@163.com