
图节信息管理系统 图书信息管理系统源程序重book,e+s_book.c 程序源码: mbook.c #include struct node 【char name[lo]: int price: char pub(15]: 1 extern struct node *add(),*del(struct node *) extern struct node *load().*mhdel(struct node ) /体体林林林体林*体林本林体体体林林本本林体本林本和体林林林林体体神/ 体函数功能:显示菜单,选择菜单/ 体输入参量:无/ /体函数输出:选择的菜单序号/ /中中中中中中中中中中中中中中中中中中中中中中中中中年中中中中中中中中中中中单中中中中中中中中中中中中中中中/ int menu_select() { int cn-0: printf(行种中中中种种神中钟钟*种种种神神神中中中*种神*种种种n门: printf(\t\t 1.Add a book'\n") printf(\t\t 2 Display book library\n): printf(\t\t 3.Query a hook\n"): printf(\t\t 4.Delete a book\n"): printf(t\t 5.Save to disk\n"): printf(\t\t 6.Load fron disk \n"); printf(\t\t 7.Mohu search\n"): printf(\t\t 8 Mohu delete\n");
图书信息管理系统 图书信息管理系统源程序 m_book.c + s_book.c 程序源码: m_book.c #include struct node { char name[10]; int price; char pub[15]; }; extern struct node *add(),*del(struct node *); extern struct node *load(),*mhdel(struct node *); /*******************************************************/ /* 函数功能:显示菜单,选择菜单 */ /* 输入参数:无 */ /* 函数输出:选择的菜单序号 */ /*******************************************************/ int menu_select() { int cn=0; printf(" **********************************************\n"); printf("\t\t 1. Add a book\n"); printf("\t\t 2. Display book library\n"); printf("\t\t 3. Query a book\n"); printf("\t\t 4. Delete a book\n"); printf("\t\t 5. Save to disk\n"); printf("\t\t 6. Load from disk \n"); printf("\t\t 7. Mohu search\n"); printf("\t\t 8. Mohu delete\n");

printf(\t\t 0.Exit\n") orintf(nIn陶t(0^8:): for(;: 【scanf(yd,cn): if (cn8)printf("Error Input again(1"6):") else break; return cn: 1 void min(void) struct pode head-NLLL: for(;: clrser0: switch (menu_select() { case 1:head=add (head)break: case 2:print (head):break: case 3:search (head):break: case 4:bead-del(head);break; case 5:save(head):break: case 6:bead-losd();break; case 7:mhsearch(head);hreak: case 8:head-nbdel (head);break: case 0:exit(o): 1 1
printf("\t\t 0. Exit\n"); printf("\t***********************************************\n"); printf("\n Input(0~8): "); for(; ;) { scanf("%d",&cn); if (cn8) printf("Error ! Input again(1~6):"); else break; } return cn; } void main(void) { struct node *head=NULL; for(; ;) { clrscr(); switch(menu_select()) { case 1: head=add(head);break; case 2: print(head);break; case 3: search(head);break; case 4: head= del(head);break; case 5: save(head);break; case 6: head=load();break; case 7: mhsearch(head);break; case 8: head=mhdel(head);break; case 0: exit(0); } } }

s_book.c #include #include (string.h> sinclude struct node char mme[10]: float price: char pub[15]: struct node *link: : struct node◆add(struct node thead》;/体函数功能:创建结点,输入结点数据◆/ void print(struct node whead):/体函数功能:链表输出/ oid save(struet node补head0:/体函数功能:链表存错/ roid search(struct node *head);/e函数功能:战表结点查找/ struct node *del(struct node thead);/体函数功能:结点剩除/ struct node *load(void):/:函数功能:从文件中读入数据,创建链表/ struct pode *hdel(struct node thead):/集函数功能:结点模制到除/ void thsearch(struct mode处ead):/体函数功能:链表结点模概查找/ /球球和球林**和*球林裤/ 佛函数功能:创建结点。输入结点数据/ 体输入参数:链表头指针/ /体函数输出:鼓表头指针/ /体林棒率林体率和车车体率车林幸和*车本率体林和林林率移/ struct mode *add(struet node *head int i; float J: struct node *p.*pnew: pnew"(struct node )nlloc(sizeof(struct node)):
s_book.c #include #include #include struct node { char name[10]; float price; char pub[15]; struct node *link; }; struct node *add(struct node *head ) ; /* 函数功能:创建结点,输入结点数据 */ void print(struct node *head); /* 函数功能:链表输出 */ void save(struct node *head); /* 函数功能:链表存储 */ void search(struct node *head); /* 函数功能:链表结点查找 */ struct node *del(struct node *head); /* 函数功能:结点删除 */ struct node *load(void); /* 函数功能:从文件中读入数据,创建链表 */ struct node *mhdel(struct node *head); /* 函数功能:结点模糊删除 */ void mhsearch(struct node *head); /* 函数功能:链表结点模糊查找 */ /*******************************************************/ /* 函数功能:创建结点,输入结点数据 */ /* 输入参数:链表头指针 */ /* 函数输出:链表头指针 */ /*******************************************************/ struct node *add(struct node *head ) { int i; float jg; struct node *p, *pnew; pnew=(struct node *)malloc(sizeof(struct node));

printf("Please input book name,price,publisher\n"): printf('nao:):scanf(s°,pnew->aam): printf(price:scant (%&jg)pnew->price=jg: printf(publisher:":scanf("%s",pnew->pub): e一>lik=山.: if (head==NULL)return (pnes) p-head: hi1ep>Iink!-L)/体找到尾结点/ p=p->link: p->link=pnew: return (head): /体本中中华车车率中本中中车本中华率中中中中年率率率率本中中率本中中中车中中中中车率本中车中车中/ 体函数功能:链表输出*/ /体输入参数:链表头指针制 /体函数输出:无/ void print(struct node head) I struct node p: p=head: printf('name\tprice\tpublisher\n"): while (p:=NULL) I printf("%s\t%-5.2f\ts-s\n".p->nane,p->price,p->pub): pEp->link: 1 printf("\n\t\tPress any keys!"); xetch():
printf("Please input book name,price,publisher\n"); printf("name:");scanf("%s",pnew->name); printf("price:");scanf("%f",&jg);pnew->price=jg; printf("publisher:");scanf("%s",pnew->pub); pnew->link=NULL; if (head==NULL)return (pnew); p=head; while (p->link!=NULL) /* 找到尾结点 */ p=p->link; p->link=pnew; return (head); } /*******************************************************/ /* 函数功能:链表输出 */ /* 输入参数:链表头指针 */ /* 函数输出:无 */ /*******************************************************/ void print(struct node *head) { struct node *p; p=head; printf("name\tprice\tpublisher\n"); while (p!=NULL) { printf("%s\t%-5.2f\t%-s\n",p->name,p->price,p->pub); p=p->link; } printf("\n\t\tPress any keys!"); getch(); }

体函数功能:链表存储/ 像输入参数:链表头雷针/ 像函数输出:无制 /中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中神/ void save(struct node *head) { FIlE◆fp: struct Bode: if ((fp=fopen ("library",'sb"))==NULL) printf("Can't open file!\n"); exit(1): 1 p-head: while (p!=NULL) { fwrite(p,sizeof(struet node),1.fp): p=p->link: 1 felose(fp): 1 /中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中/ 体函数功能:从文件中读入数据,创建链表/ 输入参数:无/ 年函数输出:鼓表头指针/ /伞中中中中中神中中中中中中中中中中中中中中中中中中中中中中中中中中神中中中中中中中中中神/ struct node *load(void) I FILE *fp: struct nod0和pnes,phead由
/*******************************************************/ /* 函数功能:链表存储 */ /* 输入参数:链表头指针 */ /* 函数输出:无 */ /*******************************************************/ void save(struct node *head) { FILE *fp; struct node *p; if ((fp=fopen("library","wb"))==NULL) { printf("Can't open file!\n"); exit(1); } p=head; while (p!=NULL) { fwrite(p,sizeof(struct node),1,fp); p=p->link; } fclose(fp); } /*******************************************************/ /* 函数功能:从文件中读入数据,创建链表 */ /* 输入参数:无 */ /* 函数输出:链表头指针 */ /*******************************************************/ struct node *load(void) { FILE *fp; struct node *p,*pnew,*phead;

if ((fp-fopen("library","rb"))=-NULL) printf("Can't open file!\n"): exit(1): pnew=(struct node *)malloc(sizeof(struct node)): fread(peew,sizeof(struct node).1.fp); pnew->link=NULL: head归etw p"pnew: while (feof(fp)) pnes=(struet node *)malloc(sizeof(struct node)): if (1!=fread(poew,sizeof(struct node),1.fp))break: pnew->link-NULL: p->link=pnew: p=p->link: 1 fclose(fp); return (phead): 佛函数功能:链表结点查找/ /体输入参数:桂表头蛋针/ 体函数输出:无/ /体车林*体棒棒率率率率本和体本棒本车棒和体移/ void search(struct node *head) char sname[15]: struct node布 printf("Please input book name\n): printf("nane:");scanf("%s".snare):
if ((fp=fopen("library","rb"))==NULL) { printf("Can't open file!\n"); exit(1); } pnew=(struct node *)malloc(sizeof(struct node)); fread(pnew, sizeof(struct node),1,fp); pnew->link=NULL; phead=pnew; p=pnew; while (!feof(fp)) { pnew=(struct node *)malloc(sizeof(struct node)); if (1!=fread(pnew, sizeof(struct node),1,fp)) break; pnew->link=NULL; p->link=pnew; p=p->link; } fclose(fp); return(phead); } /*******************************************************/ /* 函数功能:链表结点查找 */ /* 输入参数:链表头指针 */ /* 函数输出:无 */ /*******************************************************/ void search(struct node *head) { char sname[15]; struct node *p; printf("Please input book name\n"); printf("name:");scanf("%s",sname);

p=head: while (p!=NULL) if (streap(p->name,snane)=0) printf("nane price publshier\n): printf("Book Found:%s $5.2f %s\n",p->mame,p->price,p->pub) printf("\n\t\tPress any keys!); xetch(: return: 1 pp->link; 1 printf("Book Not Exist!\n): printf("\n\t\tPress any keys !")getchO; /体本本本本车本本车率率本本率本本中本体中本本本本木车车率本林本本林本本韩/ 体函数功能!结点除/ 体输入参数:战表头指针/ 体函数输出:返回链表头指针率/ /中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中中/ struct node *del(struct node *head) I char sn[15】,8: int flag-0: struct mode p.q: printf(Please input book name\n"): printf("name:"):scanf("%s",sn): phead: while (p!=NULL)
p=head; while (p!=NULL) { if (strcmp(p->name,sname)==0) { printf(" name price publshier\n"); printf("Book Found: %s %5.2f %s\n",p->name,p->price,p->pub); printf("\n\t\tPress any keys!"); getch(); return; } p=p->link; } printf("Book Not Exist!\n"); printf("\n\t\tPress any keys !"); getch(); } /*******************************************************/ /* 函数功能:结点删除 */ /* 输入参数:链表头指针 */ /* 函数输出:返回链表头指针 */ /*******************************************************/ struct node *del(struct node *head) { char sn[15],s; int flag=0; struct node *p,*q; printf("Please input book name\n"); printf("name:");scanf("%s",sn); p=head; while(p!=NULL) {

while(p!=NULL (stremp (p->nane.sa)!=0) 【qppp>lik: if(stre即(p->nae.sm}=0)kp!=ML】 L flag-1: printf("nane price publshier\n"): printf("Book Found:&s $5.2f %s\n",p->mame,p->price,p->pub) printf(Do you want to del this book(y/n)); scanf(te”,ks: it(s='y'l='Y) if (p==head)head=p->link: else q->link=p>link: free(p): printf("This book is deleted!\n"): printf("\n\t\tPress any keys !)getchO: else printf("\nThis book not delete!\n"): printf("\n\t\tPress any keys!")getchO: return bead; 1 else if(flag!-1) printf("\nNOT found!") printf("\n\t\tPress any key!):getch(): break:
while(p!=NULL &&(strcmp(p->name,sn)!=0)) { q=p;p=p->link;} if((strcmp(p->name,sn)==0)&& p!=NULL) { flag=1; printf(" name price publshier\n"); printf("Book Found: %s %5.2f %s\n",p->name,p->price,p->pub); printf("Do you want to del this book(y/n)"); scanf("\n%c",&s); if(s=='y' || s=='Y') { if(p==head)head=p->link; else q->link=p->link; free(p); printf("This book is deleted!\n"); printf("\n\t\tPress any keys !");getch(); } else { printf("\nThis book not delete!\n"); printf("\n\t\tPress any keys!");getch(); return head; } } else { if(flag!=1) { printf("\nNOT found!"); printf("\n\t\tPress any key!");getch(); } break;

if (p!=NULL) p=p->link: 1 return head: 1 void mhsearch(struct node whead) { char s[15]; int flag-0: struct node和: printf("Please input book name\n"); printf(ne::scanf(%s°,s: p=head由 while(p!=NULL) [ while(p!"NULL (strstr(p->nane.s)=-MULL)) {pp->1ink:】 if (strstr (p->nane,s)!=NULL) printf("nane price publshier\n'): printf("Book Found:&s $5.2f %s\n",p->mame,p->price,p->pub): flag=1: zetch(: 1 else if(flag!-1) printf("\nNOT found!"): printf("\n\t\tPress any key!"):getch():
} if(p!=NULL) { p=p->link; } } return head; } void mhsearch(struct node *head) { char s[15]; int flag=0; struct node *p; printf("Please input book name\n"); printf("name:");scanf("%s",s); p=head; while(p!=NULL) { while(p!=NULL && (strstr(p->name,s)==NULL)) { p=p->link;} if(strstr(p->name,s)!=NULL) { printf(" name price publshier\n"); printf("Book Found: %s %5.2f %s\n",p->name,p->price,p->pub); flag=1; getch(); } else { if(flag!=1) { printf("\nNOT found!"); printf("\n\t\tPress any key!");getch(); }

if (p!=NL) p=p->link: 1 struct node *uhdel(struct node *head) char sn[15],s: int flag0: struct node p.q: printf("Please input book name\n"); printf("name:"):scanf(%s",sn): p-head: while(p!=NULL) { while (p!=NULL &(strstr (p->nane,sm)==NULL)) q=p:p=p->link:) if(stc即(p->aae,sm》I-L》&Mpl-WL) flag-1: printf("nane price publshier\n"): printf("Book Found:%s $5.2f %s\n",p->mame,p->price.p->pub): printf(Do you want to del this book(y/n)): scanf(uc”,ks: if(s'y'Il s'Y) if (p==head)head=p->link: else q->link-p->link: free(p): printf("This book is deleted!\n"):
} if(p!=NULL) { p=p->link; } } } struct node *mhdel(struct node *head) { char sn[15],s; int flag=0; struct node *p,*q; printf("Please input book name\n"); printf("name:");scanf("%s",sn); p=head; while(p!=NULL) { while(p!=NULL &&(strstr(p->name,sn)==NULL)) { q=p;p=p->link;} if((strcmp(p->name,sn)!=NULL)&& p!=NULL) { flag=1; printf(" name price publshier\n"); printf("Book Found: %s %5.2f %s\n",p->name,p->price,p->pub); printf("Do you want to del this book(y/n)"); scanf("\n%c",&s); if(s=='y' || s=='Y') { if(p==head)head=p->link; else q->link=p->link; free(p); printf("This book is deleted!\n");