1、void sort_chaxun(struct book *head /按类别查询图书void time_chaxun(struct book *head /按出版时间查询图书void bname_chaxun(struct book *head /按图书名查询图书void xiugai(struct book *head /修改图书信息void paixu(struct book *head /对图书进行排序void num_paixu(struct book *head /按图书编号排序void time_paixu(struct book *head /按图书出版时间排序void pri
2、ce_paixu(struct book *head /按图书价格排序void bname_paixu(struct book *head /按图书名排序void wname_paixu(struct book *head /按作者名排序int main( int choice,n,x,y=1,c,c1=1234。 char a,d,b10,b110=yjk struct book *head=NULL。 while(y system(cls printf(nnnnnnn * 欢迎光临 *nn * 图书信息管理系统 *nnn printf(nn =1-用户登录=n =0-退出系统=n 请输入您
3、的选择: scanf(%d,&nn getchar( switch(n case 0: y=0。 break。 case 1: 请输入您的用户名: gets(b 请输入您的密码: scanf(c if(strcmp(b,b1!=0|c!=c1 验证失败,请重新输入!%cd getchar( system( else 验证通过!请按Enter键进入! x=1。 while(x -n *图书信息管理系统*n -nn *nn | 1-添加图书 2-删除图书 |nn | 3-图书列表 4-图书排序 |nn | 5-查询图书 6-修改图书 |nn | 7-录入数据 0-退出系统 |nn 请输入所选择的序
4、号:choice switch(choice case 0: x=0。break。 head=load( if(head=NULL printf(文件为空,请先录入数据! getchar( break。 else head=addbook(head添加成功!是否将新信息保存到文件?(y/na switch(a case n: break。y fprint(head printf(保存成功! getchar( case 2: if(head=NULL deletebook(head case 3: head=load( print_book(head case 4: paixu(head cas
5、e 5: else chaxun(head case 6: xiugai(head break。 case 7: printf(注意:输入图书编码为0时结束! head=creatbook(是否将输入的信息保存到文件以覆盖文件中已存在的信息? scanf( switch(a case default:您的输入有误,请重新输入! getchar( break。 您的输入有误! 请重新输入! /录入数据并形成链表 struct book *head,*tail,*p。 int num,time,n。 char bname50,wname20,press50,sort50。 int size=siz
6、eof(struct book head=tail=NULL。请输入图书编号:num请输入图书名:%s,bname请输入作者名:,wname请输入出版社:,press请输入类别:,sort请输入出版时间:time请输入价格:%fprice while(1 p=(struct book *malloc(size p-num=num。 strcpy(p-bname,bnamewname,wnamepress,presssort,sorttime=time。price=price。next=NULL。 if(head=NULL head=p。 else tail-next=p。 tail=p。 do
7、 n=yanzheng(head,num if(n=0您输入的编号已存在,请重新输入! while(1 if(num=0 scanf( return head。/插入结点,并且插入后仍按一定顺序 struct book *ptr,*p1,*p2,*p。 int num,time,n=1。 do p=(struct book * p- strcpy(p- p2=head。 ptr=p。 while(ptr-p2-&(p2-next!=NULL p1=p2。 p2=p2-next。 if(ptr-num if(head=p2 head=ptr。 p1-next=ptr。next=p2。 else
8、p2-/验证添加的图书编号是否已存在 struct book *p。 p=head。 while(p! if(p-num=m p=p- if(p=NULL return 0。 else return 1。/将新链表写入文件中 FILE *fp。 char ch=1 struct book *p1。 if(fp=fopen(f1.txt,w=NULLFile open error! exit(0 fputc(ch,fp for(p1=head。p1。p1=p1-next fprintf(fp,%d %s %s %s %s %d %fn,p1-num,p1-bname,p1-wname,p1-pr
9、ess,p1-sort,p1-time,p1- fclose(fp/从文件中读取图书信息 char ch。 struct book *head,*tail,*p1。r ch=fgetc(fp if(ch= while(!feof(fp p1=(struct book *malloc(sizeof(struct book fscanf(fp,%d%s%s%s%s%d%fnp1-sort,&time,& head=p1。next=p1。 tail=p1。 tail- return NULL。/将整个链表的信息输出 struct book *ptr。n没有信息! return。 图书信息列表如下n
10、=n 编号 图书名 作者名 出版社 类别 出版时间 价格n for(ptr=head。ptr。ptr=ptr- %d %s %s %s %s %d %.2fn,ptr-num,ptr-bname,ptr-wname,ptr-press,ptr-sort,ptr-time,ptr-/删除图书信息 int a。 char b,ch= struct book *p1,*p2。请输入要删除的图书编号: p1=head。 if(p1-num=a&next=NULL /对于文件中只有一组数据是否清空文件!b switch(b case 文件已清空! while(p1-num!=a& p2=p1。 p1=p1-num=a是否确定从文件中彻底删除该图书? switch(b case fprint(head删除成功!没有找到要删除的数据! else if(p1=head head=p1-next=p1-/图书查询
copyright@ 2008-2023 冰点文库 网站版权所有
经营许可证编号:鄂ICP备19020893号-2