求该帮做做题!急 在线等 20

编写一万年历系统要求模仿现实生活中的挂历,编程实现一个万年历。程序实现的主要功能:1)当前页以系统当前日期的月份为准显示当前月的每一天(显示出日及对应的星期几)。2)当系... 编写一万年历系统
要求模仿现实生活中的挂历,编程实现一个万年历。程序实现的主要功能:
1) 当前页以系统当前日期的月份为准显示当前月的每一天(显示出日及对应的星期几)。
2) 当系统日期变到下一月时,系统自动翻页到下一月(可选项)。
求各位C语言高手帮忙!!
展开
 我来答
阿斯顿鄙视
2011-05-31
知道答主
回答量:8
采纳率:0%
帮助的人:0
展开全部
题BT,不想做啊
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
袁渝昂
2011-06-01
知道答主
回答量:34
采纳率:0%
帮助的人:7.7万
展开全部
不会
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
忙里偷腥
2011-06-14 · TA获得超过431个赞
知道小有建树答主
回答量:230
采纳率:0%
帮助的人:121万
展开全部
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<conio.h>
#include<math.h>
#include<time.h>

///
#define YUANDAN 1
typedef struct
{
//农历年份
int lunar_year;
//农历月份
int lunar_month;
//农历日期
int lunar_day;
//本月天数
int current_mday;
//本年闰月
int leap_month;
//闰月标记
int leap_flag;
}Lunar_info;
typedef struct
{
//阳历年份
int era_year;
//阳历月份
int era_month;
//阳历日期
int era_day;
}Chinese_era;
int s_year;
int s_month;
int s_day;
static int t_year;
static short today = YUANDAN;
/*1900-2050年的农历数据
数据格式说明:
5位十六进制数字 例:04bd8
1位:是否为闰月(30天) 0:不是 1:是
2、3、4位:转换二进制为:0100 1011 1101(1为30天,0为29天)
04bd8表示为(13个月):29,30,29,29,30,29,30,30,30(闰月),30,30,29,30;
5位:如果有闰月,则为月份,没有则为0, 此为8月*/
int lunar_info[]=
{
0x04bd8,0x04ae0,0x0a570,0x054d5,0x0d260,0x0d950,0x16554,0x056a0,0x09ad0,0x055d2,
0x04ae0,0x0a5b6,0x0a4d0,0x0d250,0x1d255,0x0b540,0x0d6a0,0x0ada2,0x095b0,0x14977,
0x04970,0x0a4b0,0x0b4b5,0x06a50,0x06d40,0x1ab54,0x02b60,0x09570,0x052f2,0x04970,
0x06566,0x0d4a0,0x0ea50,0x06e95,0x05ad0,0x02b60,0x186e3,0x092e0,0x1c8d7,0x0c950,
0x0d4a0,0x1d8a6,0x0b550,0x056a0,0x1a5b4,0x025d0,0x092d0,0x0d2b2,0x0a950,0x0b557,
0x06ca0,0x0b550,0x15355,0x04da0,0x0a5b0,0x14573,0x052b0,0x0a9a8,0x0e950,0x06aa0,
0x0aea6,0x0ab50,0x04b60,0x0aae4,0x0a570,0x05260,0x0f263,0x0d950,0x05b57,0x056a0,
0x096d0,0x04dd5,0x04ad0,0x0a4d0,0x0d4d4,0x0d250,0x0d558,0x0b540,0x0b6a0,0x195a6,
0x095b0,0x049b0,0x0a974,0x0a4b0,0x0b27a,0x06a50,0x06d40,0x0af46,0x0ab60,0x09570,
0x04af5,0x04970,0x064b0,0x074a3,0x0ea50,0x06b58,0x055c0,0x0ab60,0x096d5,0x092e0,
0x0c960,0x0d954,0x0d4a0,0x0da50,0x07552,0x056a0,0x0abb7,0x025d0,0x092d0,0x0cab5,
0x0a950,0x0b4a0,0x0baa4,0x0ad50,0x055d9,0x04ba0,0x0a5b0,0x15176,0x052b0,0x0a930,
0x07954,0x06aa0,0x0ad50,0x05b52,0x04b60,0x0a6e6,0x0a4e0,0x0d260,0x0ea65,0x0d530,
0x05aa0,0x076a3,0x096d0,0x04bd7,0x04ad0,0x0a4d0,0x1d0b6,0x0d250,0x0d520,0x0dd45,
0x0b5a0,0x056d0,0x055b2,0x049b0,0x0a577,0x0a4b0,0x0aa50,0x1b255,0x06d20,0x0ada0,
0x14b63
};
/*天干*/
char Gan[10][3]={"甲","乙","丙","丁","戊","己","庚","辛","壬","癸"};
/*地支*/
char Zhi[12][3]={"子","丑","寅","卯","辰","巳","午","未","申","酉","戌","亥"};
/*生肖*/
char Animals[12][3]={"鼠","牛","虎","兔","龙","蛇","马","羊","猴","鸡","狗","猪"};
/*24节气*/
char solar_term[24][5]=
{
"小寒","大寒","立春","雨水","惊蛰","春分",
"清明","谷雨","立夏","小满","芒种","夏至",
"小暑","大暑","立秋","处暑","白露","秋分",
"寒露","霜降","立冬","小雪","大雪","冬至"
};
/*农历日*/
char chinese_day[30][5]=
{
"初一","初二","初三","初四","初五","初六","初七",
"初八","初九","初十","十一","十二","十三","十四",
"十五","十六","十七","十八","十九","廿十","廿一",
"廿二","廿三","廿四","廿五","廿六","廿七","廿八",
"廿九","卅十"
};
char build[4][5]={"光绪","宣统","民国","建国"};
/*农历月*/
char chinese_month[12][5]={"正","二","三","四","五","六","七","八","九","十","冬","腊"};

注意:**********以上内容复制粘贴到记事本中,重命名为 《calendar.h》不带引号*******

#include "calendar.h"
void TIME()
{
static char *week[]={"日","一","二","三","四","五","六"};
time_t t;
struct tm *tp;
t=time(NULL);
tp=localtime(&t);
printf("%d年%02d月%02d日",tp->tm_year+1900,tp->tm_mon+1,tp->tm_mday);
printf(" %02d:%02d:%02d ",tp->tm_hour,tp->tm_min,tp->tm_sec);
printf("星期%s\t ",week[tp->tm_wday]);
}

void buffer(int n)
{
time_t start,end;
start=time(NULL);
end=time(NULL);
while(end-start<n)
end=time(NULL);
}

int leap(int year)
{
if(year%4==0&&year%100!=0||year%400==0) return 366;
else return 365;
}

void Olympic() //奥运会倒记时
{

time_t t;
struct tm *tp;
t=time(NULL);
tp=localtime(&t);
if(tp->tm_year+1900 > 2008 || (tp->tm_year+1900 >= 2008 && tp->tm_mon+1 >= 8 && tp->tm_mday >= 23 ))
{
printf(" 2008北京奥运会已成功举办! ");
}
else
{
printf("距离2008北京奥运会还有");
if(tp->tm_year+1900 == 2008)
tp->tm_yday += leap(tp->tm_year+1900-1);
printf("%03d天",585-tp->tm_yday);
printf("%02d小时%02d分%02d秒 ",23+8-tp->tm_hour,59+8-tp->tm_min,60+8-tp->tm_sec);
}
}

int day(int month)
{
if(month==1||month==3||month==5||month==7||month==8||month==10||month==12) return 31;
if(month==4||month==6||month==9||month==11) return 30;
if(month==2&&leap(s_year)==366) return 29;
else return 28;
}

int get_solar_total(int solar_year, int solar_month)
{
int total;
int temp_num;
total=0;
for (temp_num=1900;temp_num<solar_year;temp_num++)
{
total+=leap(temp_num);
}
for(temp_num=1;temp_num<solar_month;temp_num++)
{
total+=day(temp_num);
}
return total;
}

int get_week(int solar_year, int solar_month)
{
int week;
int total;
/* 1900.01.01为星期一*/
week=2;
total=get_solar_total(solar_year, solar_month);
total%=7;
week=week+total;
week%=7;
if (week==0)
week=7;
return week;
}

int get_leap_month(int lunar_year)
{
return lunar_info[lunar_year-1900]&0xf;
}

int get_leap_month_day(int lunar_year)
{
if (get_leap_month(lunar_year))
return ((lunar_info[lunar_year-1900]&0x10000)?30:29);
else
return(0);
}

int get_lunar_month_total(int lunar_year, int lunar_month)
{
return ((lunar_info[lunar_year-1900]&(0x10000>>lunar_month))?30:29);
}

int get_lunar_year_total(int lunar_year)
{
/*348 = 29*12 */
int sum=348;
int i;
for(i=0x8000;i>0x8; i>>=1)
sum+=(lunar_info[lunar_year-1900]&i)?1:0;
return(sum+get_leap_month_day(lunar_year));
}

void get_chinese_era(int num, char *str)
{
strcpy(str, Gan[num%10]);
strcat(str, Zhi[num%12]);
}
/*24节气算法
void sTerm(int n)
{
double offDate;
//offDate=31556925974.7*(s_year-1900)+sTermInfo[n]*60000;
}*/
/*返回农历信息*/
int get_lunar_info(int solar_year, int solar_month, Lunar_info *l_info,Chinese_era *china_era)
{
int i;
int total;
int temp_num;
/*阳历1900年01月31日为农历1900年01月01日*/
total=get_solar_total(solar_year,solar_month)-30;
china_era->era_day=total+40;
/*将13和14月作为下一年的1月和2月,便于确定Y年M月D日是星期几
蔡勒公式求星期几:W=[C/4]-2C+y+[y/4]+[13×(M+1)/5]+d-1*/
china_era->era_month=14;
for(i=1900;i<2051&&total>=0;i++)
{
/*temp_num记录从1900到2050年闰年和平年的天数*/
temp_num=get_lunar_year_total(i);
total-=temp_num;
/*累计月*/
china_era->era_month+=12;
}
l_info->lunar_year=i;
if(total<0)
{
total+=temp_num;
/*减年*/
l_info->lunar_year--;
china_era->era_month-=12;
}
/*1864年为农历甲子年*/
china_era->era_year=l_info->lunar_year-1864;
/*返回是否存在闰月*/
l_info->leap_month=get_leap_month(l_info->lunar_year);
l_info->leap_flag=0;
for(i=1;i<13 &&total>0;i++)
{
if (l_info->leap_month>0&&i==(l_info->leap_month+1)&&l_info->leap_flag==0)
{
--i;
temp_num=get_leap_month_day(l_info->lunar_year);
/*存在闰月*/
l_info->leap_flag=1;
}
else
temp_num=get_lunar_month_total(l_info->lunar_year, i);
if (l_info->leap_flag==1&&i==(l_info->leap_month+1))
l_info->leap_flag=0;
total-=temp_num;
if (l_info->leap_flag==0)
china_era->era_month++;
}
if(total==0&&l_info->leap_month>0&&i==l_info->leap_month+1)
if(l_info->leap_flag==1)
l_info->leap_flag=0;
else
{
l_info->leap_flag=1;
--i;
--china_era->era_month;
}
if(total<0)
{
total+=temp_num;
--i;
--china_era->era_month;
}
l_info->lunar_month=i;
l_info->lunar_day=total+1;
if (l_info->leap_flag==0)
l_info->current_mday=get_lunar_month_total(l_info->lunar_year,l_info->lunar_month);
else
l_info->current_mday=get_leap_month_day(l_info->lunar_year);
return 0;
}
/*输出农历日期信息*/
int out_chinese(Lunar_info *l_info,char *chinese_str)
{
/*初一不打印*/
if (l_info->lunar_day!=1)
{
strcpy(chinese_str, chinese_day[l_info->lunar_day-1]);
if (l_info->lunar_day==15&&l_info->lunar_month==1)
strcpy(chinese_str, "元宵节");
if(l_info->lunar_day==5&&l_info->lunar_month==5)
strcpy(chinese_str, "端午节");
if(l_info->lunar_day==7&&l_info->lunar_month==7)
strcpy(chinese_str, "情人节");
if(l_info->lunar_day==15&&l_info->lunar_month==7)
strcpy(chinese_str, "中元节");
if (l_info->lunar_day==15&&l_info->lunar_month==8)
strcpy(chinese_str, "中秋节");
if (l_info->lunar_day==9&&l_info->lunar_month==9)
strcpy(chinese_str, "重阳节");

if(l_info->lunar_month==12)
{
if(l_info->lunar_day==30)
strcpy(chinese_str, "除夕");
if(l_info->current_mday<30&&l_info->lunar_day==29)
strcpy(chinese_str, "除夕");
if (l_info->lunar_day==8)
strcpy(chinese_str, "腊八节");
if (l_info->lunar_day==23)
strcpy(chinese_str, "小年");
}

}
else
{
if (l_info->leap_flag==1)
{
//如果存在闰月就将汉字闰复制到数组里,再连接农历月份
strcpy(chinese_str, "闰");
strcat(chinese_str,chinese_month[l_info->lunar_month-1]);
strcat(chinese_str, "月");
}
else
{
if (l_info->lunar_month==1)
strcpy(chinese_str, "春节");
else
{
strcpy(chinese_str,chinese_month[l_info->lunar_month-1]);
strcat(chinese_str, "月");
if(get_lunar_month_total(l_info->lunar_year,l_info->lunar_month)==30)
strcat(chinese_str,"大");
else
strcat(chinese_str,"小");
}
}
}
return 0;
}

/*阳历节日转换
void convertTochar(int year ,int month,int day)
{
static char temp[9];
int y;
strcpy(temp,"元旦");
memset(temp,0,sizeof(temp));
if(s_year >= year && s_month == month && s_day == day)
itoa(s_day,temp,10);
puts(temp);
}*/
/*界面输出*/
void sub_menue()
{
int week,s_month_total,space_num,c_num;
int i,j,flag;
char tmp_str[9];
Chinese_era c_ear;
Lunar_info l_info;
/*每个月一号为星期几*/
week=get_week(s_year,s_month);
/*返回当月的天数*/
s_month_total=day(s_month);
//将已开辟内存空间tmp_str的首sizeof(tmp_str)个字节的值设为值0,作用在于可以方便的清空结构类型的数组或变量。
memset(&c_ear,0,sizeof(c_ear));
memset(&l_info,0,sizeof(l_info));
/*返回农历信息*/
get_lunar_info(s_year,s_month,&l_info,&c_ear);
memset(tmp_str,0,sizeof(tmp_str));
/*确定干支*/
get_chinese_era(s_year-1864,tmp_str);
if(s_year>=1949)
{
//中华人民共和国纪年
t_year=s_year-1949;
flag=3;
}
else if(s_year<1949&&s_year>1911)
{
//民国纪年
t_year=s_year-1911;
flag=2;
}
else if(s_year<1912&&s_year>1908)
{
//宣统纪年
t_year=s_year-1908;
flag=1;
}
else
{
//光绪纪年
t_year=s_year-1874;
flag=0;
}
system("cls");
printf("\t  ╭───────────────────────────╮\n");
printf("\t1、↑年| 万年历 |\n");

printf("\t |───────────────────────────|\n");
printf("\t2、↓年| 今天是:");
TIME();
printf("|\n");
printf("\t |───────────────────────────|\n");
printf("\t3、↑月| ");
Olympic();
printf("|\n");
printf("\t |───────────────────────────|\n");
printf("\t4、↓月| 公历:%d年%02d月 %s%3d年 农历:%s年 【%s】 |\n",
s_year,s_month,build[flag],t_year,tmp_str, Animals[(s_year-1864)%12]);
printf("\t |───────────────────────────|\n");
printf("\t5、Exit|星期日 星期一 星期二 星期三 星期四 星期五 星期六|\n");
printf("\t |───────────────────────────|\n");
printf("\t | ");
space_num=week;
for (i=1; i<space_num;i++)
{
printf(" ");
}
c_num=0;
for (i=1; i<=s_month_total;i++)
{
s_day=i;
printf("%02d",s_day);
week+=1;
if((week>7)||(i==s_month_total))
{
week=1;
printf("\n |");
if (i<7)
{
for (j=1;j<space_num;j++)
{
printf(" ");
}
week=space_num;
}
else
week=1;
while(1)
{
week+=1;
memset(tmp_str,0,sizeof(tmp_str));
out_chinese(&l_info,tmp_str);
printf("% 6s", tmp_str);
if (l_info.lunar_day<l_info.current_mday)
l_info.lunar_day=l_info.lunar_day+1;
else
{
if ((l_info.lunar_month==l_info.leap_month)&&l_info.leap_flag==0)
{
/*存在闰月,返回天数*/
l_info.current_mday=get_leap_month_day(l_info.lunar_year);
l_info.leap_flag=1;
}
else
{
l_info.lunar_month=l_info.lunar_month+1;
if (l_info.lunar_month>12)
{
l_info.lunar_month=1;
/*月数大于12进年*/
l_info.lunar_year=l_info.lunar_year+1;
}
/*返回闰月的天数*/
l_info.current_mday=get_lunar_month_total(l_info.lunar_year, l_info.lunar_month);
l_info.leap_flag=0;
}
l_info.lunar_day=1;
}
c_num++;
if ((week>7)||(c_num==s_month_total))
{
week=1;
printf("\n | ");
break;
}
else
printf(" ");
}
}
else
printf(" ");
}
printf("\n");
printf("\t ╰───────────────────────────╯\n");
}
main()
{
char tmp_str[9];
int curr_year,curr_month;
time_t t;
struct tm *tp;
t=time(NULL);
tp=localtime(&t);
lable:;
s_year=tp->tm_year+1900;
s_month=tp->tm_mon+1;
sub_menue();
while (1)
{
printf("\t\t 你可以输入年份(1900-2050),也可以输入(1-5)!\n请输入:");
/*将已开辟内存空间tmp_str的首sizeof(tmp_str)个字节的值设为值0,作用在于可以方便的清空结构类型的数组或变量。*/
memset(tmp_str,0,sizeof(tmp_str));
gets(tmp_str);
/*atoi将字符串转换成整型数,用curr_month,curr_year接收输入的值*/
curr_month=curr_year=atoi(tmp_str);
/*上一年*/
if(curr_year==1&&strlen(tmp_str)==1)
{
s_year--;
if(s_year<1900)
s_year=2050;
}
/*下一年*/
else if(curr_year==2&&strlen(tmp_str)==1)
{
s_year++;
if(s_year>2050)
s_year=1900;
}
/*上一月*/
else if(curr_month==3&&strlen(tmp_str)==1)
{
s_month--;
if (s_month<1)
{
s_year-=1;
s_month=12;
if(s_year<1900)
s_year=2050;
}
}
/*下一月*/
else if(curr_month==4&&strlen(tmp_str)==1)
{
s_month++;
if (s_month>12)
{
s_year+=1;
s_month=1;
if(s_year>2050)
s_year=1900;
}
}
/*退出*/
else if(curr_year==5&&strlen(tmp_str)==1)
{
system("cls");
printf("\n\n\n\n\n\n\n\n\t\t\t 谢 谢 使 用, 再 见 !!!\n\t\t\t ");
buffer(1);
exit(0);
}
else
{
s_year=atoi(tmp_str);
if (strlen(tmp_str)>4||(s_year<1900)||(s_year>2050))
{
printf("\t\t\t Error:年份输入错误,重新输入!!!\n");
buffer(1);
goto lable;
}
printf("请输入月份(1-12):");
memset(tmp_str,0,sizeof(tmp_str));
gets(tmp_str);
s_month=atoi(tmp_str);
if (strlen(tmp_str)>2||(s_month<1)||(s_month>12))
{
printf("\t\t\t Error:月份输入错误,重新输入!!!\n");
buffer(1);
goto lable;
}
}
sub_menue();
}
}
**********以上内容到c语言软件中编译,执行,然后把上面的那个记事本放到和此程序相同的文件夹内,切记!!********

参考资料: 搜狐网站

已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式