您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 管理学资料 > 数据结构通讯录管理系统
#includestdio.h#includestdlib.h#includestring.h#includeconio.hstructrecord{charname[20];charstreet[20];charcity[20];chareip[20];charstate[20];}student[500];structslnode{recorddate;structslnode*next;structslnode*prior;};typedefslnode*linklist;linklistl;intnum=0;FILE*fp;voidmainmenu();voidsearchmenu();voidenter();voidsearch();voiddisplay();voidload();voidsave();voiddelet();voidlistinsert();voidinitlist();voidmain(){initlist();load();listinsert();while(1)mainmenu();}voidload(){if((fp=fopen(student.bin,rb))==NULL){printf(\n\t\tͨѶ¼Îļþ²»´æÔÚ);if((fp=fopen(student,wb))==NULL){printf(\n\t\t½¨Á¢Ê§°Ü);exit(0);}else{printf(\n\t\tͨѶ¼ÎļþÒѽ¨Á¢);printf(\n\t\t°´ÈÎÒâ¼ü½øÈëÖ÷²Ëµ¥);getch();return;}exit(0);}fseek(fp,0,2);if(ftell(fp)0){rewind(fp);for(num=0;!feof(fp)&&fread(&student[num],sizeof(structrecord),1,fp);num++);printf(\n\t\tÎļþµ¼Èë³É¹¦);printf(\n\t\t°´ÈÎÒâ¼ü·µ»ØÖ÷²Ëµ¥);getch();return;}printf(\n\t\tÎļþµ¼Èë³É¹¦);printf(\n\t\tͨѶ¼ÎļþÖÐÎÞÈκμͼ);printf(\n\t\t°´ÈÎÒâ¼ü·µ»ØÖ÷²Ëµ¥);getch();return;}voidmainmenu()//Ö÷²Ëµ¥{charchoic;system(cls);printf(\n\t\t***************»¶Ó½øÈëͨѶ¼ϵͳ***************);printf(\n\t\t******************1-ÐÂÌí¼Í¼******************);printf(\n\t\t******************2-²éÕÒÁªÏµÈË****************);printf(\n\t\t******************3-ɾ³ýÁªÏµÈË***************);printf(\n\t\t******************4-±£´æÍ˳ö*****************);printf(\n\t\t******************5-²»±£´æÍ˳ö***************);printf(\n\t\t************************************************);printf(\n\t\tÇëÑ¡Ôñ£º);choic=getch();switch(choic){case'1':enter();break;case'2':searchmenu();break;case'3':delet();break;case'4':save();break;case'5':exit(0);default:mainmenu();}}voidsearchmenu()//²éѯ²Ëµ¥{charchoic;system(cls);printf(\n\t\t*******************²éѯ²Ëµ¥*******************);printf(\n\t\t****************1-ÏÔʾËùÓÐ********************);printf(\n\t\t****************2-°´ÐÕÃû²éѯ******************);printf(\n\t\t****************3-·µ»ØÖ÷²Ëµ¥******************);printf(\n\t\t************************************************);printf(\n\t\tÇëÑ¡Ôñ£º);choic=getch();switch(choic){case'1':display();break;case'2':search();break;case'3':mainmenu();break;}}voidenter()//Ìí¼Ó¼Í¼{printf(\n\t\t****************ÇëÊäÈëѧÉúÐÅÏ¢****************\n);printf(\n\t\tÐÕÃû:);scanf(%s,&student[num].name);printf(\n\t\t½ÖµÀ:);scanf(%s,&student[num].street);printf(\n\t\t³ÇÊÐ:);scanf(%s,&student[num].city);printf(\n\t\tÊäÈëÓʱà:);scanf(%s,&student[num].eip);printf(\n\t\t¹ú¼Ò:);scanf(%s,&student[num].state);num++;printf(\n\t\tÊÇ·ñ¼ÌÐøÌí¼Ó?(Y/N):);if(getch()=='y')enter();return;}voiddisplay()//ÏÔʾËùÓÐ{inti;system(cls);if(num!=0){printf(\n\t\t***************ÒÔÏÂΪͨѶ¼ËùÓÐÐÅÏ¢************);for(i=0;inum;i++){printf(\n\t\tÐÕÃû£º%s,student[i].name);printf(\n\t\t½ÖµÀ£º%s,student[i].street);printf(\n\t\t³ÇÊУº%s,student[i].city);printf(\n\t\tÓʱࣺ%s,student[i].eip);printf(\n\t\t¹ú¼Ò£º%s,student[i].state);printf(\t\t);if(i+1num){printf(\n\t\t__________________________);system(pause);}}printf(\n\t\t************************************************);}elseprintf(\n\t\tͨѶ¼ÖÐÎÞÈκμͼ);printf(\n\t\t°´ÈÎÒâ¼ü·µ»ØÖ÷²Ëµ¥£º);getch();return;}voidsave()//дÈëÎļþ{inti;if((fp=fopen(student,wb))==NULL){printf(\n\t\tÎļþ´ò¿ªÊ§°Ü);}for(i=0;inum;i++){if(fwrite(&student[i],sizeof(structrecord),1,fp)!=1){printf(\n\t\tдÈëÎļþ´íÎó!\n);}}fclose(fp);printf(\n\t\tͨѶ¼ÎļþÒѱ£´æ);printf(\n\t\t°´ÈÎÒâ¼üÍ˳ö³ÌÐò\n\t\t);exit(0);}voidlistinsert()//Ôö¼ÓÒ»¸ö½áµã{linklists,p=l;for(inti=0;inum;i++){s=newslnode;strcpy(s-date.name,student[i].name);strcpy(s-date.city,student[i].city);strcpy(s-date.street,student[i].street);strcpy(s-date.eip,student[i].eip);strcpy(s-date.state,student[i].state);s-prior=p-prior;s-next=p;p-prior-next=s;p-prior=s;p=p-next;}}voidinitlist(){l=newslnode;l-next=l;l-prior=l;}voidsearch(){intj=0,a=0;linklistp=l;printf(\n\t\t*****************°´ÐÕÃû²éÕÒ*******************);charname[20];printf(\n\t\tÇëÊäÈëÐÕÃû:);scanf(%s,name);for(inti=a;inum;i++,p=p-next){if(strcmp(name,p-next-date.name)==0){printf(²éѯµ½µÄÐÅÏ¢:);printf(\n);printf(ÐÕÃû:);printf(%s,p-next-date.name);printf(\n);printf(³ÇÊÐ:);printf(%s,p-next-date.city);printf(\n);printf(¹ú¼Ò:);printf(%s,p-next-date.state);printf(\n);printf(½ÖµÀ:);printf(%s,p-next-date.street);printf(\n);printf(ÓÊÕþ±àÂë:);printf(%s,p-next-date.eip);j++;}if(j==0)printf(\t\t¸ÃͨѶ¼ûÓиÃÈË!);if((i+1)num){printf(\n\t\tÊÇ·ñ¼ÌÐø²éÕÒÏàͬÃû×ÖµÄѧÉúÐÅÏ¢£º(y/n));if(getch()=='y'){a=i;continue;}elsereturn;}else{printf(\n\t\t°´ÈÎÒâ¼ü·µ»ØÖ÷²Ëµ¥);getch();return;}}}voiddelet(){inta=0;intfindmark=0;intj;intdeletemark=0;inti;charname[20];printf(\n\t\tÇëÊäÈëҪɾ³ýѧÉúÐÕÃû£º);scanf(%s,name);for(i=a;inum;i++){if(strcmp(student[i].name,name)==NULL){printf(\n\t\tÒÔÏÂÊÇÄúҪɾ³ýµÄѧÉú¼Í¼£º);findmark++;printf(\n\t\t________________________________);printf(\n\t\tÐÕÃû£º%s,student[i].name);printf(\n\t\t½ÖµÀ£º%s,student[i].street);printf(\n\t\t³ÇÊУº%s,student[i].city);printf(\n\t\tÓʱࣺ%s,student[i].eip);printf(\n\t\t¹ú¼Ò:%s,student[i].state);p
本文标题:数据结构通讯录管理系统
链接地址:https://www.777doc.com/doc-6353422 .html