诚毅小家|集美大学生活【集美大学,诚毅学院,水产学院,师范学院,美术学院,财经学院,体育学院,航海学院,集美学村,石鼓路,龙舟池】

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
热搜: 活动 交友 discuz
查看: 564|回复: 4

C语言万年历(不完整版)

[复制链接]
发表于 2010-7-11 09:38:58 | 显示全部楼层 |阅读模式
本帖最后由 守护¥云 于 2010-7-11 12:57 编辑

额,,,,弄了大半个星期,还是没能改好,就是不能显示阴历,咳,,,,C这东西还真是讨厌。不过要是有人不嫌弃的话有用到可以拿去用下哈!
下面是主界面图

  1. #include<string.h>
  2. #include<dos.h>
  3. #include<time.h>
  4. #include<stdio.h>
  5. #include<bios.h>
  6. #include<stdlib.h>
  7. #include<conio.h>
  8. #define LEFT 0x4b00
  9. #define RIGHT 0x4d00
  10. #define ESC 0x011b
  11. #define ENTER 0x1c0d
  12. char *a[4]={"left","right","up","down"};/*设定上下左右按键数组*/
  13. int num=3000,key,year=2006;/*设定初始年份变量*/
  14. int i,j,first=3,w=30;/*设定变量、窗口变量*/
  15. char *month[12]={"Junuary","February","March","April","May","June","July","August","September","October","November","December"};
  16. int mon[12]={31,28,31,30,31,30,31,31,30,31,30,31};/*设定月份天数数组*/
  17. int fd[12]={0};/*定义按键数组、各年每月的天数及月分名称*/
  18. int getkey()
  19. {char lowbyte;
  20. int press;
  21. while(bioskey(1)==0)
  22. press=bioskey(0);
  23. lowbyte=press&0xff;
  24. press=press&0xff00+toupper(lowbyte);
  25. return(press);
  26. }
  27. void sch()
  28. {window(22,24,29,24);
  29. textbackground(GREEN);
  30. clrscr();
  31. textcolor(15);
  32. cprintf("\nSearch");}

  33. void sch_0()
  34. {window(22,24,29,24);
  35. textbackground(GREEN);
  36. clrscr();
  37. textcolor(128);
  38. cprintf("\nSearch ");} /*设定搜索窗口*/

  39. void backk()
  40. {window(32,24,36,24);
  41. textbackground(GREEN);
  42. clrscr();
  43. textcolor(15);
  44. cprintf("\nM1-4");}

  45. void backk_0()
  46. {window(32,24,36,24);
  47. textbackground(GREEN);
  48. clrscr();
  49. textcolor(128);
  50. cprintf("\nM1-4");} /*建1-4月份按键窗口*/

  51. void left()
  52. {
  53. window(39,24,43,24);
  54. textbackground(GREEN);
  55. clrscr();
  56. textcolor(15);
  57. cprintf("\nM5-8");}

  58. void left_0()
  59. {window(39,24,43,24);
  60. textbackground(GREEN);
  61. clrscr();
  62. textcolor(128);
  63. cprintf("\nM5-8");} /*建5-8月份按键窗口*/

  64. void right()
  65. {window(46,24,52,24);
  66. textbackground(GREEN);
  67. clrscr();
  68. textcolor(15);
  69. cprintf("\nM9-12");}

  70. void right_0()
  71. {window(46,24,52,24);
  72. textbackground(GREEN);
  73. clrscr();
  74. textcolor(128);
  75. cprintf("\nM9-12");} /*建9-12月份按键窗口*/
  76. void lun_()
  77. {window(55,24,60,24);
  78. textbackground(GREEN);
  79. clrscr();
  80. textcolor(15);
  81. cprintf("\ntime");
  82. }
  83. void lun_0()
  84. {window(55,24,60,24);
  85. textbackground(GREEN);
  86. clrscr();
  87. textcolor(128);
  88. cprintf("\ntime"); /*建系统时间按键窗口*/
  89. }

  90. void clock_()
  91. {window(63,24,68,24);
  92. textbackground(GREEN);
  93. clrscr();
  94. textcolor(15);
  95. cprintf("\nclock");
  96. }

  97. void clock_0()
  98. {window(63,24,68,24);
  99. textbackground(GREEN);
  100. clrscr();
  101. textcolor(128);
  102. cprintf("\nclock");}/*设定闹钟按键窗口*/
  103. }
  104. void iexit()
  105. {window(71,24,76,24);
  106. textbackground(GREEN);
  107. clrscr();
  108. textcolor(15);
  109. cprintf("\nExit");}

  110. void iexit_0()
  111. {window(71,24,76,24);
  112. textbackground(GREEN);
  113. clrscr();
  114. textcolor(128);
  115. cprintf("\nExit");} /*建退出按键窗口*/



  116. void jiance(int n)
  117. {switch(n)
  118. {case 0:sch_0();left();right();lun_();clock_();iexit();backk();break;
  119. case 1:backk_0();left();right();lun_();clock_();iexit();sch();break;
  120. case 2:left_0();right();lun_();clock_();iexit();sch();backk();break;
  121. case 3:right_0();left();lun_();clock_();iexit();sch();backk();break;
  122. case 4:lun_0();clock_();iexit();sch();backk();left();right();break;
  123. case 5:clock_0();iexit();sch();backk();left();right();lun_();break;
  124. case 6:iexit_0();left();right();lun_();clock_();sch();backk();break;
  125. default:exit(0);
  126. }
  127. } /*实现搜索、日期各窗口间的切换的函数*/

  128. void quzhi()
  129. {window(8,24,20,24);
  130. textbackground(2);
  131. clrscr();
  132. textcolor(BLACK);
  133. cscanf("%d",&year);
  134. }/*搜索输入年份窗口*/


  135. void month1_4()
  136. {
  137. for(i=0;i<2;i++)
  138. {window(2+i*w,3,29+w*i,11);
  139. textbackground(5);
  140. clrscr();
  141. textcolor(BLACK);/*设定1-4月份显示窗口*/
  142. cprintf(" %s\n",month);
  143. gotoxy(1,2);cprintf(" Mon Tue Wed Thu Fri Sat Sun");
  144. gotoxy(4*(fd-1)+1,3);
  145. for(j=1;j<=mon;j++)
  146. {cprintf("%3d ",j);
  147. }
  148. }
  149. for(i=2;i<4;i++)
  150. {window(2+(i-2)*w,13,29+w*(i-2),21);
  151. textbackground(5);
  152. clrscr();
  153. textcolor(BLACK);
  154. cprintf(" %s\n",month);
  155. gotoxy(1,2);cprintf(" Mon Tue Wed Thu Fri Sat Sun");
  156. gotoxy(4*(fd-1)+1,3);
  157. for(j=1;j<=mon;j++)
  158. {cprintf("%3d ",j);
  159. }
  160. }
  161. } /*1-4月份的窗口设置及计算函数*/

  162. void month5_8()
  163. {for(i=0;i<2;i++)
  164. {window(2+i*w,3,29+w*i,11);
  165. textbackground(5);
  166. clrscr();
  167. textcolor(BLACK); /*设定5-8月份显示窗口*/
  168. cprintf(" %s\n",month[i+4]);
  169. gotoxy(1,2);cprintf(" Mon Tue Wed Thu Fri Sat Sun");
  170. gotoxy(4*(fd[i+4]-1)+1,3);
  171. for(j=1;j<=mon[i+4];j++)
  172. {cprintf("%3d ",j);
  173. }
  174. }
  175. for(i=2;i<4;i++)
  176. {window(2+(i-2)*w,13,29+w*(i-2),21);
  177. textbackground(5);
  178. clrscr();
  179. textcolor(BLACK);
  180. cprintf(" %s",month[i+4]);
  181. gotoxy(1,2);cprintf(" Mon Tue Wed Thu Fri Sat Sun");
  182. gotoxy(4*(fd[i+4]-1)+1,3);
  183. for(j=1;j<=mon[i+4];j++)
  184. {cprintf("%3d ",j);
  185. }
  186. }
  187. } /*5-8月份的窗口设置及计算函数*/

  188. void month9_12()
  189. {for(i=0;i<2;i++)
  190. {window(2+i*w,3,29+w*i,11);
  191. textbackground(5);
  192. clrscr();
  193. textcolor(BLACK);/*设定9-12月份显示窗口*/
  194. cprintf(" %s\n",month[i+8]);
  195. gotoxy(1,2);cprintf(" Mon Tue Wed Thu Fri Sat Sun");
  196. gotoxy(4*(fd[i+8]-1)+1,3);
  197. for(j=1;j<=mon[i+8];j++)
  198. {cprintf("%3d ",j);
  199. }
  200. }
  201. for(i=2;i<4;i++)
  202. {window(2+(i-2)*w,13,29+w*(i-2),21);
  203. textbackground(5);
  204. clrscr();
  205. textcolor(BLACK);
  206. cprintf(" %s",month[i+8]);
  207. gotoxy(1,2);cprintf(" Mon Tue Wed Thu Fri Sat Sun");
  208. gotoxy(4*(fd[i+8]-1)+1,3);
  209. for(j=1;j<=mon[i+8];j++)
  210. {cprintf("%3d ",j);
  211. }
  212. }
  213. } /*9-12月份的窗口设置及计算函数*/


  214. void calendar(int year)
  215. {int x,cha;
  216. long day=0;
  217. window(1,2,80,22);
  218. textbackground(YELLOW);
  219. clrscr();/*设定年份显示窗口*/
  220. if(year<2007)
  221. {for(x=year;x<2007;x++)
  222. {if((x%4==0&&x%100!=0)||x%400==0)/*判断是否为润年*/
  223. day+=366;
  224. else day+=365;}
  225. cha=day%7;
  226. first=(7+1-cha)%7;
  227. if(first==0)first=7;
  228. }/*对星期的排*/
  229. if(year==2007)first=1;
  230. if(year>2007)
  231. {for(x=2007;x<year;x++)
  232. {if((x%4==0&&x%100!=0)||x%400==0)
  233. day+=366;
  234. else day+=365;}
  235. cha=day%7;
  236. first=(1+cha)%7;
  237. if(first==0)first=7;
  238. }
  239. if((year%4==0&&year%100!=0)||year%400==0)
  240. mon[1]=29;
  241. else mon[1]=28;/*判断是否为润年、确定二月份天数*/
  242. fd[0]=first;
  243. for(j=1;j<12;j++)
  244. {fd[j]=(fd[j-1]+mon[j-1])%7;
  245. if(fd[j]==0)fd[j]=7;}
  246. month1_4();}
  247. int GetMinute(char *s)
  248. {
  249. char *p;
  250. p = (char *)malloc(10);
  251. strcpy(p, s);
  252. while(*p != ':')
  253. {
  254. p++;
  255. }
  256. p++;
  257. return atoi(p);
  258. }
  259. void clock_1()
  260. {
  261. char s[10];
  262. int hour,minute;/*设定小时、分钟变量*/
  263. time_t t;
  264. struct tm *timeinfo;
  265. printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nplease input the time like [18:30]:\n\n\n\n\n\n\n\n\n\n\n");
  266. gets(s); /*显示请输入时间如[18:30]*/
  267. hour = GetHour(s);
  268. minute = GetMinute(s);
  269. while(!kbhit())/*设定按任意键退出*/
  270. {
  271. time(&t);
  272. timeinfo = localtime(&t);
  273. if(timeinfo->tm_hour < hour)continue;
  274. else if(timeinfo->tm_min < minute)continue;
  275. else
  276. {
  277. printf("Time is up!Wake up!\n\007"); getch();
  278. system("c: [url=file://\\she.wav]\\she.wav[/url]");
  279. main();
  280. }
  281. }
  282. }
  283. int GetHour(char *s)
  284. {
  285. char *p, *q;
  286. p = (char *)malloc(10);
  287. strcpy(p, s);
  288. q = p;
  289. while(*q != ':')
  290. {
  291. q++;
  292. }
  293. *q = '\0';
  294. return atoi(p);
  295. }

  296. void time_1()
  297. {
  298. struct date d; /*设置系统日期变量*/
  299. struct time t; /*设置系统时间变量*/
  300. while(!kbhit())
  301. {
  302. clrscr();
  303. gettime(&t); /*获取系统时间*/
  304. getdate(&d); /*获取系统日期*/
  305. printf("\n\n\n\n\n\n\n\n\n\n \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n Today is: %d.%d.%d \n",d.da_year,d.da_mon,d.da_day);
  306. printf(" \n\n The current time: %d:%d:%d \n\n\n\n\n\n\n\n\n\n\n\nplease press any key to exit!",t.ti_hour,t.ti_min,t.ti_sec);
  307. sleep(1);
  308. main();
  309. }
  310. } /*设置单独的系统时间窗口,运行后按任意键退出*/

  311. void jiance2(int n)
  312. {void nian(int year);
  313. switch(n)
  314. {case 0:getch( );quzhi();calendar(year);nian(year);break;
  315. case 1:month1_4();break;
  316. case 2:month5_8();break;
  317. case 3:month9_12();break;
  318. case 4:time_1();break;
  319. case 5:clock_1();break;
  320. case 6:exit(0);break;
  321. default:exit(0);}
  322. } /*对特定的按键调用相应的函数*/

  323. void ping()
  324. {clrscr();
  325. window(1,1,80,1);
  326. textbackground(BLUE);
  327. clrscr();
  328. gotoxy(6,1);
  329. textcolor(WHITE);
  330. cprintf("Lunar-Calendar");/*设定日历主题条目。字体颜色及窗口大小*/
  331. window(2,1,4,1);
  332. textbackground(0);
  333. clrscr();
  334. window(1,2,80,22);
  335. textbackground(YELLOW);
  336. clrscr();/*设定主页面窗口大小、背景颜色*/
  337. window(1,23,80,25);
  338. textbackground(BLUE);
  339. clrscr();
  340. window(8,24,20,24);
  341. textbackground(15);/*设定按键栏的背景、字体大小、及窗口*/
  342. clrscr();
  343. sch_0();
  344. left();
  345. right();
  346. lun_();
  347. clock_();
  348. iexit();
  349. backk();
  350. calendar(2006);/*显示初始化年份*/
  351. }
  352. void nian(int year)
  353. {window(62,5,78,5);
  354. textbackground(RED);
  355. clrscr();
  356. textcolor(GREEN);
  357. cprintf("\n Calendar");
  358. window(64,7,75,11);
  359. textbackground(15);
  360. clrscr();
  361. textcolor(2);
  362. cprintf("\n Year");
  363. gotoxy(3,4);
  364. cprintf("%6d",year);
  365. window(62,13,78,20);
  366. textbackground(8);
  367. clrscr();
  368. textcolor(9);
  369. cprintf("\n=====welcom=====");
  370. gotoxy(1,4);
  371. cprintf(" calendar");
  372. gotoxy(1,6);
  373. cprintf(" system");
  374. return;/*设定桌面右侧的窗口、如欢迎进入日历系统。。。*/
  375. }
  376. main()
  377. {
  378. clrscr();
  379. sch_0();
  380. backk();
  381. left();
  382. right();
  383. lun_();
  384. clock();
  385. iexit();
  386. ping(); /*运行主函数*/
  387. calendar(2006);
  388. nian(2006);
  389. while(key!=28)
  390. {if(bioskey(1))key=bioskey(0);
  391. switch(key) /*设定相应按键函数*/
  392. {case LEFT:num--;jiance(num%7);key=0;break;
  393. case RIGHT:num++;jiance(num%7);key=0;break;
  394. case ENTER:jiance2(num%7);key=0;break;
  395. case ESC:exit(0);/*各按键功能函数*/
  396. default:key=0;break;}
  397. }
  398. }
复制代码

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x
 楼主| 发表于 2010-7-11 09:41:05 | 显示全部楼层
本帖最后由 守护¥云 于 2010-7-11 12:58 编辑

谢谢五楼的提示,我改好了

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x
发表于 2010-7-11 11:43:48 | 显示全部楼层
你也是大一的么。。。这么快就把C语言学完了。那个设置颜色的变量半天才看懂
发表于 2010-7-11 11:59:08 | 显示全部楼层
不错...把文字界面设置得很好
发表于 2010-7-11 11:59:54 | 显示全部楼层
在工具栏上面有个代码的...你用户这个功能把你的代码全部括起来


  1. void main()
  2. {
  3.     return;
  4. }
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|Archiver|手机版|小黑屋|诚毅小家 ( 小家社区工作室 闽ICP备05007965号 )

GMT+8, 2024-12-22 15:09 , Processed in 0.054583 second(s), 24 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表