日記管理系統(tǒng)_第1頁(yè)
日記管理系統(tǒng)_第2頁(yè)
日記管理系統(tǒng)_第3頁(yè)
日記管理系統(tǒng)_第4頁(yè)
已閱讀5頁(yè),還剩74頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

#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;/*********************數(shù)原型User*User_init();Diary*DiaryJnit();voidUser_Menu(User*head);〃用戶管理菜單函數(shù)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);〃日記管理菜單函數(shù),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);//按關(guān)鍵字查找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歡迎進(jìn)入日記管理系統(tǒng)\n");printf("\n 按任一鍵進(jì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("|該系統(tǒng) 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沒(méi)有該選項(xiàng)!\n”);)})*******************添加用戶*******************添加用戶*******************User*User_Add(llser*head)User*p,*q;intflag;chartemp_password[20];system("cls");do(p=(User*)malloc(U_LEN);〃申請(qǐng)內(nèi)存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該用戶已存在,請(qǐng)重新輸入。。。?!?;gotoA;)q=q->next;}B:printf(H\n\t請(qǐng)輸入密碼:\tH);〃輸入密碼并密碼加密scanf("%sH,p->password);printf("\n\t請(qǐng)?jiān)俅屋斎朊艽a:\tH);scanf("%s,,,temp_password);if(strcmp(temp_password,p->password)!=0)(printf(”\n\t密碼不匹配!\n\t\t\t請(qǐng)重新輸入..…\n\nH);gotoB;)p->elem=Diary_init();p->num=0;p->next=head;〃進(jìn)行前插head=p;printf(”\n\t創(chuàng)建用戶成功!\nH);printf("\n\t\t\t繼續(xù)添加用戶?是⑴/否(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);〃進(jìn)入用戶選擇菜單printf(”\n\n\t是(1)否(0)繼續(xù)查看其他用戶日記?\n");scanff^d';&flag);if(flag==1)gotoB;elsereturn(head);)〃不存在符合條件的用戶printf("\n\t該用戶不存在或密碼錯(cuò)誤\n“);printf("\t是(1)否(0)繼續(xù)登錄?”);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請(qǐng)輸入新密碼:\t“);scanf(”%s*password);printf("\n\t請(qǐng)?jiān)俅屋斎?\t“);scanf("%s',,temp_password);if(strcmp(password,temp_password)!=0)(printf(H\n\t密碼不匹配!請(qǐng)重新輸入..…\n\n");gotoA;}printf("\n是否要更改該用戶信息,輸入Y更改,N則退出?");〃確認(rè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輸入要?jiǎng)h除的用戶名:\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是否要?jiǎng)h除,輸入Y刪除,N 貝ij 退出?\nH);〃確認(rèn)是否刪除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系統(tǒng)用戶有:\nH);〃列出系統(tǒng)的所有用戶的用戶名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)〃查看自己日記時(shí)temp=1;else〃查看他人日記時(shí)temp=O;q->elem=Diary_Menu(q,temp);return(q->elem);/*********************曰]己?jiǎn)?********************/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是否繼續(xù)進(jìn)行該用戶日記操作?(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)〃日記為他人的時(shí)候,進(jìn)行密碼輸入與確認(rèn)A:printf("\n\n\t這是%s的日記,不屬于您,請(qǐng)輸入該用戶的密碼:”,u->name);scanf("%s',,temp_password);if(strcmp(u->password,temp_password)!=0)printf(H\n\t密碼錯(cuò)誤,無(wú)權(quán)寫入!是(1)否(0)繼續(xù)?");scanf("%d*&flag);if(flag==O)return(u);elsesystem(HclsH);gotoA;

)dop=(Diary)dop=(Diary*)malloc(D_LEN);〃申請(qǐng)內(nèi)存printf("\n\t輸入天氣:\t”);scanf("%sn,p->weather);printf("\n\t輸入日期(如2010-01-01):\t");scanf("%sH,p->date);printf("\n\t輸入標(biāo)題:\t");scanf("%sH,p->title);printf("\n\t輸入關(guān)鍵字:\t“);seanf("%sn,p->keyword);printf("\n\t內(nèi)容:\t“);scanf("%s",p->content);p->next=u->elem;〃進(jìn)行前插u->elem=p;u->num++;〃日記數(shù)記錄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;〃記錄要查找鏈表的開始點(diǎn)while(p1->next!=NULL)〃找到要查找鏈表段的最小節(jié)點(diǎn)if(strcmp(temp->date,p1->next->date)>0)(flag=p1;temp=p1->next;)p1=p1->next;)if(i==O) 〃記錄第一次找到的最小節(jié)點(diǎn)p=p2=temp;if(temp==head)〃找出的小數(shù)等于尋找開頭的那個(gè)數(shù)時(shí)p2=head;head=head->next;)else 〃找出的小數(shù)不是尋找開頭的那個(gè)數(shù)時(shí)(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該用戶沒(méi)有日記)system("PAUSE");return(u);}printf(H\n\t用戶%s的日記有:\n*u->name); //列出所在用戶的所有日記printf("%20s%20s\n\n\n”「關(guān)鍵字日期”);while(p!=NULL)printf(H%20s%20s\n",p->title,p->date);p=p->next;Aprintf("輸入你要?jiǎng)h除的日記的日期:\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)〃存在符合條件的記錄時(shí)if(temp==O)〃他人日記時(shí),進(jìn)行密碼輸入與確認(rèn)(B:printf("您要?jiǎng)h的是%5的日記,不屬于您,請(qǐng)輸入該用戶的密55:\n",u->name);scanf(,,%s",temp_password);if(strcmp(u->password,temp_password)!=0)(printf("密碼錯(cuò)誤,無(wú)權(quán)刪除!是(1)否(0)繼續(xù)?)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標(biāo)題:\t%s",p1->title);printf("\n\t 內(nèi)W:\t%sn,p1->content);printf("\n\n\t是否刪除該篇日記?是⑴/否(0)”); 〃確認(rèn)刪除操作scanff^d';&flag);if(flag==1)(if(p1==u->elem)〃刪除的結(jié)點(diǎn)為日記鏈表頭結(jié)點(diǎn)時(shí)u->elem=p1->next;else〃刪除的結(jié)點(diǎn)不為日記鏈表頭結(jié)點(diǎn)時(shí)p2->next=p1->next;printf(H\n\n\t已成功刪除!H);}elseprintf("\n\t不存在該日記!\n”);printf("\n\n\t是⑴/否(0)繼續(xù)刪除操作?) 〃判斷是否繼續(xù)刪除其他日記scantier,&n);if(n==1)gotoA;elsereturn(u);/*********************看日*********************IvoidDiary_Search_Menu(Diary*head,intnum)charflag-O';if(num==0)system("clsH);printf("\n\t該用戶沒(méi)有日記)system("PAUSE");return;while(1)system(',clsH);printf(H \n");printfC1| 查看日記 |\n");printf(" \n");printf(" I 1.按關(guān)鍵字查看 |\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是否繼續(xù)查看?(y/n)");if(getchar()=='n'||getchar()=="N')(break;}按關(guān)鍵字查看*******************voidDiary_Search_by_Keyword(Diary*head)(Diary*p1;chartemp_keyword[20];system("cls");printf("\n\t輸入關(guān)鍵字:\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標(biāo)題:\t%s”,p1->title);printf(H\n內(nèi)容:\t%s”,p1->content);)else〃不存在符合條件的記錄

printf(“\n\t沒(méi)有關(guān)鍵字為%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標(biāo)題p1->title);printf("\n內(nèi)容:\t%s”,p1->content);else〃不存在符合條件的記錄printf("\n\t沒(méi)有日期為%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)〃當(dāng)數(shù)字小于1或大于日記篇數(shù)時(shí)(if(temp_num>num)printf(”\n\t沒(méi)有這么多日記)elseprintf(H\n\t輸入的數(shù)字應(yīng)大于等于一H\-printf("\n請(qǐng)重新輸入");gotoA;)else〃數(shù)字標(biāo)準(zhǔn)時(shí),查找符合條件的日記記錄(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標(biāo)題:\t%s”,p?>title);printf("\n\t內(nèi)容:\t%s\p->content);printf("\n下一篇?是⑴/否(0)H);〃判斷是否繼續(xù)查看下一篇日記scanfC%d",&flag);if(flag==1)(if(p->next==NULL)(printf("沒(méi)有下一篇\n

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論