



版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
#include<stdio.h>#include<stdlib.h>#include<string.h>#include<conio.h>#defineD_LENsizeof(Diary)#defineU_LENsizeof(User)/******************************************/typedefstructstu1chardate[20];charweather[20];chartitle[50];charkeyword[20];
charcontent[300];structstu1*next;}Diary;typedefstructstu2charname[20];charpassword[20];Diary*elem;intnum;structstu2*next;}User;/*********************数原型User*User_init();Diary*DiaryJnit();voidUser_Menu(User*head);〃用户管理菜单函数User*llser_Add(User*head);〃添加用户User*User_Login(User*head);//用户登录User*User_Change(User*head);〃更改用户信息User*User_Delete(User*head);〃删除用户Diary*User_Chioce(User*head,llser*u);//用户选择Diary*Diary_Menu(User*u,inttemp);〃日记管理菜单函数,temp记录是否为自己的日记User*Diary_Create(User*u,inttemp);〃写日记Diary*Xuanze_Sort(Diary*head,intnum);〃按日期选择排序User*Diary_Delete(User*u,inttemp);〃删除日记voidDiary_Search_Menu(Diary*head,intnum);〃查看日记菜单voidDiary_Search_by_Orde(Diary*head,intnum);〃按顺序查找void Diary_Search_by_Keyword(Diary*head);//按关键字查找voidDiary_Search_by_Date(Diary*head);〃按日期查找User*Read_File();〃读取文件voidSave_File(User*head);〃保存文件/******************************************/intmain()User*head;head=llser_init();User_Menu(head);return0;
*******************初始化*******************初始化*********************/User*User_init()〃初始化(returnNULL;}Diary*DiaryJnit()returnNULL;用户菜单*********************/voidUser_Menu(User*head)(intchioce=1;printf("\n欢迎进入日记管理系统\n");printf("\n 按任一键进入主菜单……”);getch();head=User_init();head=Read_File();〃读取文件while(chioce)system(',cls,,);printf("printf("\nH);printf("|信息管理printf("printf("|信息管理printf("printf("|用户信息printf(H|登录printf("|用户信息printfC1|用户printf("|用户|\n"); \n");.添加|\n");.用户|\n");.更改|\n");.删除|\n");.保存用户信息0.退出printf("|该系统 0.退出printfC1 \n");printf(" 输入你的选择(1~8):\n");scanf("%d",&chioce);switch(chioce)(case1:head=User_Add(head);break;case2:head=User_Login(head);break;case
3:head=User_Change(head);break;case4:head=User_Delete(head);break;case5:Save_File(head);break;caseO:exit(O);break;default:printfC1没有该选项!\n”);)})*******************添加用户*******************添加用户*******************User*User_Add(llser*head)User*p,*q;intflag;chartemp_password[20];system("cls");do(p=(User*)malloc(U_LEN);〃申请内存q=head;A:printf(n\n\t输入用户名:\t”);scanf(”%s”,p->name);while(q!=NULL)〃判断该用户是否存在if(strcmp(p->name,q->name)==O)printf(H\n\n该用户已存在,请重新输入。。。。”);gotoA;)q=q->next;}B:printf(H\n\t请输入密码:\tH);〃输入密码并密码加密scanf("%sH,p->password);printf("\n\t请再次输入密码:\tH);scanf("%s,,,temp_password);if(strcmp(temp_password,p->password)!=0)(printf(”\n\t密码不匹配!\n\t\t\t请重新输入..…\n\nH);gotoB;)p->elem=Diary_init();p->num=0;p->next=head;〃进行前插head=p;printf(”\n\t创建用户成功!\nH);printf("\n\t\t\t继续添加用户?是⑴/否(0)”);scanf(“%d”,&flag);}while(flag!=0);return(head);/**m*mm*********************/User*User_Login(User*head)User*p;intflag;chartemp_name[20],temp_password[20];system("cls");A:printf("\n\t输入用户名:\t”);scanf(”%s”,temp_name);printf("\n\t输入密码:\t“);scanf(H%sH,temp_password);p=head;while(p!=NULL)(if(strcmp(p->name,temp_name)==O&&strcmp(p->password,temp_password)==0) 〃寻找符合条件的用户break;p=p->next;}if(p!=NULL)〃存在符合条件的用户printf("\n\t\t\t登陆成功!\n“);system("PAUSE");B:p->elem=User_Chioce(head,p);〃进入用户选择菜单printf(”\n\n\t是(1)否(0)继续查看其他用户日记?\n");scanff^d';&flag);if(flag==1)gotoB;elsereturn(head);)〃不存在符合条件的用户printf("\n\t该用户不存在或密码错误\n“);printf("\t是(1)否(0)继续登录?”);scanf("%d",&flag);if(flag==1)gotoA;elsereturn(head);)}更改用户信息*******************User*User_Change(User*head)(User*p;charpassword[20],temp_password[20],temp_name[20],c;system("cls");printf("\n\t输入要更改用户信息的用户名:\t“);scanf(”%s”,temp_name);printf("\n\t输入该用户密码:\t“);scanf(',%s',,temp_password);p=head;while(p!=NULL)〃寻找符合条件的用户if(strcmp(p->name,temp_name)==O&&strcmp(p->password,temp_password)==0)break;p=p->next;)if(p!=NULL)〃存在符合条件的用户(printf(H\n\t输入新的用户名:\t");scanf(”%s”,temp_name);A:printf("\n\t请输入新密码:\t“);scanf(”%s*password);printf("\n\t请再次输入:\t“);scanf("%s',,temp_password);if(strcmp(password,temp_password)!=0)(printf(H\n\t密码不匹配!请重新输入..…\n\n");gotoA;}printf("\n是否要更改该用户信息,输入Y更改,N则退出?");〃确认是否更改for(;;)(scanf("%c",&c);if(c==,n'||c==,N,)break;if(c=='y'||c=='Y,)(strcpy(p->name,temp_name);strcpy(p->password,temp_password);printf("\n用户信息已被更改\n”);system(“PAUSE“);break;)})〃不存在符合条件的用户printf("\n用户%s不存在\n",temp_name);system("PAUSE");return(head);/********************* jia*********************IUser*User_Delete(User*head)User*p1,*p2;chartemp_password[20],temp_name[20],c;system("cls");printf("\n\t输入要删除的用户名:\t");scanf(”%s”,temp_name);printf("\n\t输入该用户密码:\t“);scanf(”%s”,temp_password);p1=p2=head;while(p1!=NULL)〃寻找符合条件的用户if(strcmp(p1->name,temp_name)==0&&strcmp(p1->password,temp_password)==0)break;p2=p1;p1=p1->next;}if(p1!=NULL)〃存在符合条件的用户(printf("\n该用户为:\t%s",p1・>name);printf("\n是否要删除,输入Y删除,N 贝ij 退出?\nH);〃确认是否删除for(;;)scanf("%c",&c);if(c==,n,||c==,N,)break;if(c=='y,||c=='Y,)(if(p1==head)head=p1->next;elsep2->next=p1->next;printf("\n用户%s以被删除\n”,temp_name);printf("别忘了保存An”);systemC'PAUSE");break;)else〃不存在符合条件的用户printf("\n用户%s不存在\n“,temp_name);system("PAUSE");)return(head);*******************用户选择*******************用户选择*********************/Diary*User_Chioce(User*head,User*u)(chartemp_name[20],temp_password[20];inttemp;User*p,*q;p=head;system("cls");printfC1系统用户有:\nH);〃列出系统的所有用户的用户名while(p!=NULL)printf("%s\n,,,p->name);p=p->next;A:q=head;printf("输入您要查看的日记所属的用户名:W);scanf(”%s”,temp_name);while(q!=NULL)〃寻找符合条件的用户(if(strcmp(temp_name,q->name)==O)break;q=q->next;)if(q==NULL)〃不存在符合条件的用户(printf("不存在该用户,重新输入!!\n");gotoA;}else〃存在符合条件的用户(if(q->name==u->name)〃查看自己日记时temp=1;else〃查看他人日记时temp=O;q->elem=Diary_Menu(q,temp);return(q->elem);/*********************曰]己单*********************/Diary*Diary_Menu(User*u,inttemp)(charflag='O';while(1)system("clsH);printf(M \n);printf("| 日记管理 |\n");printf(" -\n)printf(" | 1'写日记 |\nH);printf(" | 2.删除日记 |\nH);printfC1 | 3.查看日记 |\nH);printfC1 \n");输入你printf(H输入你的选择(1~3):\n“);flag=getche();switch(flag)case'T:u=Diary_Create(u,temp);break;printf("\nn);u=Diary_Delete(u,temp);break;Diary_Search_Menu(u->elem,u->num);break;}getchar();printf("\n\n\t是否继续进行该用户日记操作?(y/n)”);if(getchar()=='n'||getchar()=="N')(break;})return(u->elem);/********************* 7^ 曰[己*********************/User*Diary_Create(User*u,inttemp)Diary*p=NULL;intflag;chartemp_password[20];system("cls',);if(temp==O)〃日记为他人的时候,进行密码输入与确认A:printf("\n\n\t这是%s的日记,不属于您,请输入该用户的密码:”,u->name);scanf("%s',,temp_password);if(strcmp(u->password,temp_password)!=0)printf(H\n\t密码错误,无权写入!是(1)否(0)继续?");scanf("%d*&flag);if(flag==O)return(u);elsesystem(HclsH);gotoA;
)dop=(Diary)dop=(Diary*)malloc(D_LEN);〃申请内存printf("\n\t输入天气:\t”);scanf("%sn,p->weather);printf("\n\t输入日期(如2010-01-01):\t");scanf("%sH,p->date);printf("\n\t输入标题:\t");scanf("%sH,p->title);printf("\n\t输入关键字:\t“);seanf("%sn,p->keyword);printf("\n\t内容:\t“);scanf("%s",p->content);p->next=u->elem;〃进行前插u->elem=p;u->num++;〃日记数记录printf("\n写下一篇日记?是⑴否(0)");scanf("%d”,&flag);}while(flag);u->elem=Xuanze_Sort(u->elem,u->num);return(u);按日期选择排序*********************/*********************/Diary*Xuanze_Sort(Diary*head,intnum)(inti;Diary*p,*p1,*p2,*temp,*flag;p=p2=head;〃记录链表的头for(i=0;i<num;i++)temp=p1=head;〃记录要查找链表的开始点while(p1->next!=NULL)〃找到要查找链表段的最小节点if(strcmp(temp->date,p1->next->date)>0)(flag=p1;temp=p1->next;)p1=p1->next;)if(i==O) 〃记录第一次找到的最小节点p=p2=temp;if(temp==head)〃找出的小数等于寻找开头的那个数时p2=head;head=head->next;)else 〃找出的小数不是寻找开头的那个数时(flag->next=temp->next;p2->next=temp;temp->next=head;p2=p2->next;})return(p);/*********************日[已*********************/User*Diary_Delete(llser*u,inttemp)chartemp_date[20],temp_password[20];intflag,n;Diary*p,*p1,*p2;p=p1=p2=u->elem;system("cls");if(u->num==O)printf(”\n\t该用户没有日记)system("PAUSE");return(u);}printf(H\n\t用户%s的日记有:\n*u->name); //列出所在用户的所有日记printf("%20s%20s\n\n\n”「关键字日期”);while(p!=NULL)printf(H%20s%20s\n",p->title,p->date);p=p->next;Aprintf("输入你要删除的日记的日期:\n");scanf(”%s”,temp_date);while(strcmp(temp_date,p1->date)&&p1!=NULL) 〃查找符合条件的记录(p2=p1;p1=p1->next;)if(strcmp(temp_date,p1->date)==0)〃存在符合条件的记录时if(temp==O)〃他人日记时,进行密码输入与确认(B:printf("您要删的是%5的日记,不属于您,请输入该用户的密55:\n",u->name);scanf(,,%s",temp_password);if(strcmp(u->password,temp_password)!=0)(printf("密码错误,无权删除!是(1)否(0)继续?)scanfC%dH,&flag);if(flag==O)return(u);else(system(Hcls");gotoB;))}system("clsH);printf("\n\t 天气 :\t%s”,p1->weather);〃打印该日记信息printf("日期:\t%s”,p1->date);printf("\n\t标题:\t%s",p1->title);printf("\n\t 内W:\t%sn,p1->content);printf("\n\n\t是否删除该篇日记?是⑴/否(0)”); 〃确认删除操作scanff^d';&flag);if(flag==1)(if(p1==u->elem)〃删除的结点为日记链表头结点时u->elem=p1->next;else〃删除的结点不为日记链表头结点时p2->next=p1->next;printf(H\n\n\t已成功删除!H);}elseprintf("\n\t不存在该日记!\n”);printf("\n\n\t是⑴/否(0)继续删除操作?) 〃判断是否继续删除其他日记scantier,&n);if(n==1)gotoA;elsereturn(u);/*********************看日*********************IvoidDiary_Search_Menu(Diary*head,intnum)charflag-O';if(num==0)system("clsH);printf("\n\t该用户没有日记)system("PAUSE");return;while(1)system(',clsH);printf(H \n");printfC1| 查看日记 |\n");printf(" \n");printf(" I 1.按关键字查看 |\nH);printf(" I 2.按日期查看 |\nH);printfC1 I 3.按顺W);序查看W);printf("
\n");\n");输入你printf("输入你的选择(1~3):\n“);flag=getche();switch(flag)(caseT:Diary_Search_by_Keyword(head);break;Diary_Search_by_Date(head);break;printf("\n");Diary_Search_by_Orde(head,num);break;)getchar();printf("\n\n\t是否继续查看?(y/n)");if(getchar()=='n'||getchar()=="N')(break;}按关键字查看*******************voidDiary_Search_by_Keyword(Diary*head)(Diary*p1;chartemp_keyword[20];system("cls");printf("\n\t输入关键字:\t“);scanf(',%s',,temp_keyword);p1=head;while(p1!=NULL)〃查找符合条件的记录if(strcmp(p1->keyword,temp_keyword)==O)break;p1=p1->next;)if(p1!=NULL)〃存在符合条件的记录,打印日记信息(printf("\n\t天气:\t%s 日期:\t%s",p1->weather,p1->date);printf("\n\t标题:\t%s”,p1->title);printf(H\n内容:\t%s”,p1->content);)else〃不存在符合条件的记录
printf(“\n\t没有关键字为%s的日记",temp_keyword);)*******************日期查看*******************日期查看*******************voidDiary_Search_by_Date(Diary*head)(Diary*p1;chartemp_date[10];system("clsn);printf(“\n\t输入日期:\t“);scanf("%s”,temp_date);p1=head;while(p1!=NULL)〃查找符合条件的记录if(strcmp(p1->date,temp_date)==0)break;p1=p1->next;)if(p1!=NULL)〃存在符合条件的记录,打印日记信息(printf("\n\t天气:\t%s日期:\t%s”,p1->weather,p1->date);printf("\n\t标题p1->title);printf("\n内容:\t%s”,p1->content);else〃不存在符合条件的记录printf("\n\t没有日期为%s的日记",temp_date);,********************按顺序杳看voidDiary_Search_by_Orde(Diaryvoid*head,intnum)Diary*p;inttemp_num,i,flag;system("cls");printf("\n\t该用户有%(1篇日记”,num);A:printf("\n\n\n\t您要查看第几篇日记:\t“);scanf(H%d",&temp_num);p=head;if(temp_num<1||temp_num>num)〃当数字小于1或大于日记篇数时(if(temp_num>num)printf(”\n\t没有这么多日记)elseprintf(H\n\t输入的数字应大于等于一H\-printf("\n请重新输入");gotoA;)else〃数字标准时,查找符合条件的日记记录(for(i=1;i<temp_num;i++)(p=p->next;)}B:system(”cls");printf("\n\t天气:\t%s",p->weather);〃打印日记信息printf("日期:\t%s”,p・>date);printf("\n\t标题:\t%s”,p・>title);printf("\n\t内容:\t%s\p->content);printf("\n下一篇?是⑴/否(0)H);〃判断是否继续查看下一篇日记scanfC%d",&flag);if(flag==1)(if(p->next==NULL)(printf("没有下一篇\n
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 山东省济南市长清五中学2024-2025学年初三下学期第二次阶段性考试化学试题试卷含解析
- 宁波工程学院《房地产市场营销》2023-2024学年第二学期期末试卷
- 三门峡社会管理职业学院《病理学》2023-2024学年第二学期期末试卷
- 四平职业大学《中国当代影视文学研究》2023-2024学年第二学期期末试卷
- 荆门职业学院《结构力学Ⅱ》2023-2024学年第一学期期末试卷
- 上海海事大学《现代水文地质学》2023-2024学年第一学期期末试卷
- 辽东学院《城市规划与GIS》2023-2024学年第二学期期末试卷
- 工业金属探伤标准试块租赁及质量追溯协议
- 电动汽车电机控制系统研发与产品生命周期管理合同
- 网红烧烤品牌授权培训与咨询服务合同
- 静脉输液不良反应及处理 课件
- 乡土中国的性别差异
- 高速铁路概论单元高速铁路发展概况课件
- 北师大版2025三年级语文下学期期中课堂知识检测考试
- 宁波浙大宁波理工学院招聘13名事业编制工作人员笔试历年参考题库附带答案详解
- 精神科医疗质量指标十二项控制评价体系
- 延安精神知识讲座课件
- 企业宣传岗试题及答案
- 上海市金山区2025届高三高考二模地理试卷(含答案)
- 《电气控制技术》课件-反接制动控制
- 华为市场面试题及答案
评论
0/150
提交评论