diff --git a/yxt.h b/yxt.h new file mode 100644 index 0000000..128b2e5 --- /dev/null +++ b/yxt.h @@ -0,0 +1,362 @@ +#include +#include +#include +#include +#define MAX_MEMO_LENGTH 100 // 备忘录内容最大长度 +#define MAX_MEMOS 100 +#define MAX_LENGTH 100 +#define FILE_NAME "memos.txt" +#define D 0.2422 +int isHoliday(int year,int month,int day) //判断是否节假日 +{ + int n,L=0; + float C; + if(year%4==0&&year%100!=0||year%400==0) + { + L=1; + } + if(year>1949&&month==1&&day==1)//元旦 + { + return 1; + } + if(year>=2021&&month==1&&day==10)//中国人民警察节 + { + return 2; + } + if(year>1910&&month==3&&day==8)//妇女节 + { + return 3; + } + if(year>1915&&month==3&&day==12)//植树节 + { + return 4; + } + if(year>=1900&&year<2000)//清明节 + { + C=4.81; + if((year%100*D+C)-L==day) + { + return 5; + } + } + if(year>2000) + { + C=5.59; + if((year%100*D+C)-L==day) + { + return 5; + } + } + if(month==5&&day==1) //劳动节 + { + return 6; + } + if(year>1939&&month==5&&day==4) //青年节 + { + return 7; + } + if(year>1912&&month==5&&day==12)//护士节 + { + return 8; + } + if(year>2017&&month==5&&day==30)//全国科技工作者日 + { + return 9; + } + if(year>1949&&month==6&&day==1)//儿童节 + { + return 10; + } + if(year>1932&&month==8&&day==1)//中国人民解放军建军节 + { + return 11; + } + if(year>2018&&month==8&&day==19)//中国医师节 + { + return 12; + } + if(year>1984&&month==9&&day==10)//教师节 + { + return 13; + } + if(year>1949&&month==10&&day==1)//国庆节 + { + return 14; + } + if(year>2000&&month==11&&day==8)//记者节 + { + return 15; + } + if(year>1971&&month==2&&day==7)//二七纪念日 + { + return 16; + } + if(year>2015&&month==4&&day==15) //全民国家安全教育日 + { + return 17; + } + if(year>2016&&month==4&&day==24)//中国航天日 + { + return 18; + } + if(year>2017&&month==5&&day==10)//中国品牌日 + { + return 19; + } + if(year>2009&&month==5&&day==12)//全民防灾减灾日 + { + return 20; + } + if(year>2011&&month==5&&day==19)//中国旅游日 + { + return 21; + } + if(year>1990&&getWeekDay(year,month,day)==0&&month==5&&day>=15&&day<=21)//中国助残日 + { + return 22; + } + if(year>1925&&month==5&&day==30)//五州纪念日 + { + return 23; + } + if(year>1972&&month==6&&day==5)//环境日 + { + return 24; + } + if(year>2017&&getWeekDay(year,month,day)==6&&month==6&&day>=8&&day<=13)//文化和自然遗产日 + { + return 25; + } + if(year>1991&&month==6&&day==25)//全国土地日 + { + return 26; + } + if(year>1937&&month==7&&day==7)//七七抗战纪念日 + { + return 27; + } + if(year>2005&&month==7&&day==11)//中国航海日 + { + return 28; + } + if(year>2009&&month==8&&day==8)//全名健身日 + { + return 29; + } + if(year>2023&&month==8&&day==15)//全民生态日 + { + return 30; + } + if(year>2017&&month==8&&day==25)//残疾预防日 + { + return 31; + } + if(year>1945&&month==9&&day==3)//中国人民抗日战争胜利纪念日 + { + return 32; + } + if(year>2016&&month==9&&day==5)//中华慈善日 + { + return 33; + } + if(year>1931&&month==9&&day==18)//九一八纪念日 + { + return 34; + } + if(year>2001&&getWeekDay(year,month,day)==6&&month==9&&day>=15&&day<=20)//全民国防教育日 + { + return 35; + } + if(year>2014&&month==9&&day==30)//烈士纪念日 + { + return 36; + } + if(year>2014&&month==10&&day==17)//国家扶贫日 + { + return 37; + } + if(year>2012&&month==12&&day==2)//全国交通安全日 + { + return 38; + } + if(year>2014&&month==12&&day==4)//国家宪法日和全国法制宣传日 + { + return 39; + } + if(year>2001&&year<=2014&&month==12&&day==4)//全国法制宣传日 + { + return 40; + } + if(year>2013&&month==12&&day==13)//南京大屠杀死难者国家公祭日 + { + return 41; + } + if(year>=1900&&year<=2100&&month==12&&day==25) + { + return 42; + } + else + { + return 0; + } +} +// 备忘录结构体 +typedef struct { + char content[MAX_LENGTH]; + int completed; +} Memo; + +// 全局备忘录数组 +Memo memos[MAX_MEMOS]; +int memo_count = 0; + +// 从文件加载备忘录数据 +void load_memos() { + FILE *fp = fopen(FILE_NAME, "r"); + if (fp == NULL) { + // 文件不存在,无需加载数据 + return; + } + + char line[MAX_LENGTH]; + while (fgets(line, MAX_LENGTH, fp)!= NULL && memo_count < MAX_MEMOS) { + // 移除换行符 + line[strcspn(line, "\n")] = '\0'; + strcpy(memos[memo_count].content, line); + + fgets(line, MAX_LENGTH, fp); + memos[memo_count].completed = (line[0] == '1'); + + memo_count++; + } + + fclose(fp); +} + +// 将备忘录数据保存到文件 +void save_memos() { + int i; + FILE *fp = fopen(FILE_NAME, "w"); + if (fp == NULL) { + printf("无法保存备忘录数据!\n"); + return; + } + + for ( i = 0; i < memo_count; i++) { + fprintf(fp, "%s\n", memos[i].content); + fprintf(fp, "%d\n", memos[i].completed); + } + + fclose(fp); +} + +// 添加备忘录 +void add_memo() { + if (memo_count < MAX_MEMOS) { + printf("请输入备忘录内容:(xx年xx月xx日和内容)"); + fgets(memos[memo_count].content, MAX_LENGTH, stdin); + // 移除换行符 + memos[memo_count].content[strcspn(memos[memo_count].content, "\n")] = '\0'; + memos[memo_count].completed = 0; + memo_count++; + printf("备忘录添加成功!\n"); + save_memos(); + system("pause"); + } else { + printf("备忘录已满,无法添加!\n"); + system("pause"); + } +} + +// 查看备忘录 +void view_memos() { + int i; + if (memo_count == 0) { + printf("没有备忘录事项!\n"); + system("pause"); + } else { + printf("备忘录列表:\n"); + for ( i = 0; i < memo_count; i++) { + printf("%d. [%c] %s\n", i + 1, memos[i].completed? 'X' : ' ', memos[i].content); + } + system("pause"); + } +} + +// 标记备忘录为已完成 +void mark_completed() { + int index; + printf("请输入要标记为已完成的备忘录编号:"); + scanf("%d", &index); + getchar(); // 消耗换行符 + if (index > 0 && index <= memo_count) { + memos[index - 1].completed = 1; + printf("备忘录已标记为已完成!\n"); + save_memos(); + system("pause"); + } else { + printf("无效的备忘录编号!\n"); + system("pause"); + } +} + +// 删除备忘录 +void delete_memo() { + int index,i; + printf("请输入要删除的备忘录编号:"); + scanf("%d", &index); + getchar(); // 消耗换行符 + if (index > 0 && index <= memo_count) { + for ( i = index - 1; i < memo_count - 1; i++) { + memos[i] = memos[i + 1]; + } + memo_count--; + printf("备忘录删除成功!\n"); + save_memos(); + system("pause"); + } else { + printf("无效的备忘录编号!\n"); + system("pause"); + } +} + +void memo() { + int choice; + + // 加载备忘录数据 + load_memos(); + + do { + system("cls"); + printf("1. 添加备忘录\n"); + printf("2. 查看备忘录\n"); + printf("3. 标记为已完成\n"); + printf("4. 删除备忘录\n"); + printf("0. 退出\n"); + printf("请选择操作:"); + scanf("%d", &choice); + getchar(); // 消耗换行符 + + switch (choice) { + case 1: + add_memo(); + break; + case 2: + view_memos(); + break; + case 3: + mark_completed(); + break; + case 4: + delete_memo(); + break; + case 0: + printf("感谢使用备忘录程序!\n"); + save_memos(); + break; + default: + printf("无效的选择,请重新输入!\n"); + system("pause"); + } + } while (choice!= 0); +}