




免费预览已结束,剩余24页可下载查看
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
# include# include# include/*/struct tushu_node int num; char leibie20; char name30; char author20; char press20; char time20; double price; struct tushu_node*next; file *fpp; /*定义fpp为全局变量*/struct tushu_node*head,*tail,*p; int quanxian(); /* 核查权限的函数 */int inputchioce(); /* 显示主菜单的函数 */void save(); /* 保存链表为文件的函数 覆盖以前的信息 */void save1(); /* 保存链表为文件的函数 不覆盖以前的信息 只在创建时调用一次*/struct tushu_node* wjtolb(); /* 从文件中读取数据并建立图书信息的链表的函数 */int luruxinxi(); /* 录入学生信息的函数 */struct tushu_node * luruxinxi_chuangjian(); /* 创建图书信息的函数 */struct tushu_node * luruxinxi_charu(); /*插入图书信息的函数*/struct tushu_node * luruxinxi_shanchu(); /*删除图书信息的函数*/struct tushu_node * luruxinxi_xiugai(); /*修改图书信息的函数*/int liulantushu(); /* 浏览图书信息的函数 */ int chaxuntushu(); /* 查询图书信息的函数 */void chaxuntushu_num(); /* 按编号查询图书 */void chaxuntushu_name(); /* 按书名查询图书 */void chaxuntushu_price(); /* 按价格查询图书 */void paixutushu(); /* 为图书排序的函数 */struct tushu_node* paixutushu_price(); /* 为图书按价格排序的函数 */struct tushu_node* paixutushu_time(); /* 为图书按出版时间排序的函数 */void sfjx() ; /* 写个小函数,判断是否继续,让程序更完美 在排序中使用 */int tongjitushu_shumu(); /* 统计图书数目的函数 */void shiyongshuoming(); /* 使用说明的函数 */*/int main()int chioce; chioce=quanxian(); /*核查用户是否有使用该管理系统的权限的函数*/if(chioce=1) /*若取得权限 则返回值为1 */ system(cls);inputchioce();exit(0);/*/int inputchioce() /* 主菜单 */int mychioce,x=-1;printf(n+欢 迎 你+nn);printf(*+ 主 菜 单 +*n);printf(* 1- 录入(删除 修改)图书信息 * * 2-(按规则)查询图书信息 *n); printf(* 3- 浏览图书信息 * * 4- 为图书(按规则)排序 *n); printf(* 5- 统计图书(数目) * * 6- 帮助 *n);printf(* 0- 退出系统 * * *n); printf(*+*n);printf(n 恭喜你获得使用权限,请你选择:);scanf(%d,&mychioce); switch(mychioce) case 1:luruxinxi();break;case 2:chaxuntushu();break;case 3:liulantushu();break;case 4:paixutushu();break;case 5: tongjitushu_shumu(); printf(nn是否继续操作? 请选择(继续-1/退出-0)); scanf(%d,&x); if(x=1)system(cls);inputchioce(); if(x=0)printf(nn谢谢你的使用! 再见n); exit (0); if(x!=1&x!=0)system(cls); printf(选择有误,默认返回主菜单,请重新选择:n); inputchioce();break;case 6:shiyongshuoming();break;case 0: printf( nn 谢谢你的使用!再见 nn);break; default: system(cls); printf(n 选择有误,请重新选择:n); inputchioce(); break;/*/int quanxian()int m=1,n=3,flag=0;char mima20;doprintf(nn 你好,欢迎使本图书信息管理系统!n); printf(nn); printf(【现在进行权限核查】 n-友情提醒:你共有3次输入密码的机会!n); printf(nn );if(n=2|n=1)printf(注意:你已输入错误%d次 剩余输入次数: %d 请输入密码:,3-n,n);if(n=3) printf(剩余输入次数: %d 请输入密码:,n); scanf(%s,mima);if(strcmp(mima,chenbo0916)=0)flag=1; return flag; m+;n-;system(cls);while(strcmp(mima,chenbo0916)!=0&mnum,p-leibie,p-name,p-author,p-press,p-time,&p-price);if(head=null)head=p;p1=p;elsep1-next=p;p2=p1;p1=p; p2-next=null;free(p);(*n)-;fclose(fp);return head;/*/int luruxinxi()int k; printf( |+录入 信息+|n);printf( | 1- 创建或添加图书信息 * * 2- 删除图书信息 |n); printf( | 3- 修改图书信息 * * 0- 还回主菜单 |n);printf(请你再次选择具体操作:);scanf (%d,&k);system(cls); /* 清屏*/ switch(k) case 1:luruxinxi_chuangjian();break;case 2:luruxinxi_shanchu();break;case 3:luruxinxi_xiugai();break; case 0: inputchioce();break; default: system(cls); printf(选择有误,默认返回主菜单,请重新选择:n); inputchioce(); break;/*/struct tushu_node * luruxinxi_chuangjian() /* 创建图书信息的函数 */ int num; char leibie10; char name30; char author20; char press20;char time20; double price; int size=sizeof(struct tushu_node); head=tail=null; printf(n请依次输入图书的n编号 类别 书名 作者 出版社 出版时间 价格(以“0”结束输入): n); scanf(%d,&num);if(num!=0)scanf(%s%s%s%s%s%lf,leibie,name,author,press,time,&price); while(num!=0) p=(struct tushu_node*)malloc(size); p-num=num; strcpy(p-leibie,leibie); strcpy(p-name,name); strcpy(p-author,author);strcpy(p-press,press);strcpy(p-time,time);p-price=price;p-next=null;if(head=null)head=p;elsetail-next=p; tail=p; printf(n请继续输入图书的n编号 类别 书名 作者 出版社 出版时间 价格(以“0”结束输入): n); scanf(%d,&num); if(num!=0) scanf(%s%s%s%s%s%lf,leibie,name,author,press,time,&price); if(num=0) /* 若判断数字为0,则退出 */system(cls); save1(head); inputchioce(); return head; /*/void save1(struct tushu_node* p1) /* 将链表保存为文件的函数 不覆盖以前的信息 */if( (fpp=fopen(1.txt,a)=null )printf(打开文件失败!); exit(0);while(p1!=null) fprintf(fpp, %d %s %s %s %s %s %lf n,p1-num,p1-leibie,p1-name,p1-author,p1-press,p1-time,p1-price); p1=p1-next;if(fclose(fpp) printf(关闭文件失败!n); exit(0);/*/void save(struct tushu_node* p1) /* 将链表保存为文件的函数 覆盖以前的信息 */ if( fpp=fopen(1.txt,w)=null )printf(打开文件失败!); exit(0);while(p1!=null) fprintf(fpp, %d %s %s %s %s %s %lf n,p1-num,p1-leibie,p1-name,p1-author,p1-press,p1-time,p1-price); p1=p1-next;if(fclose(fpp)printf(关闭文件失败!n); exit(0);/*/struct tushu_node * luruxinxi_shanchu() /* 删除某本图书信息(按编号删除) */int x=-1,n=0; int numm; int num; char leibie10; char name30; char author20; char press20;char time20; double price; struct tushu_node*ptr1,*ptr2; struct tushu_node*head=null; printf(n所有的图书信息如下:n); /* 删除前 先遍历所有图书,方便看清要删除哪一本*/ if(fpp=fopen(1.txt,r)=null) /* 输入要删除的图书编号之前 先遍历所有图书信息 */ printf( 打开文件失败 ! );exit(0);elseprintf(nn编号 类别 书名 作者 出版社 出版时间 价格n); while(!feof(fpp) fscanf(fpp,%d%s%s%s%s%s%lf,&num,leibie,name,author,press,time,&price); printf(%d %s %s %s %s %s %lfn,num,leibie,name,author,press,time,price); if(fclose(fpp)printf(关闭文件失败!n);exit(0); head=wjtolb(head,&n); /* 从文件中读取数据 将数据创建为链表 */ printf(n 输入需要删除的图书的编号:); scanf(%d,&numm);while(head!=null&head-num=numm)ptr2=head;head=head-next;free(ptr2);if(head=null)return null;ptr1=head;ptr2=head-next;while(ptr2!=null)if(ptr2-num=numm)ptr1-next=ptr2-next; free(ptr2);else ptr1=ptr2; ptr2=ptr1-next; save(head); /* 重新保存为文件 */ printf( 编号为%d的图书已删除 并将删除后的信息保存至文件 ,numm); printf(nn是否继续操作? 请选择(继续-1/退出-0)); scanf(%d,&x); if(x=1) system(cls); inputchioce(); if(x=0) printf(nn谢谢你的使用! 再见n); exit (0); if(x!=1&x!=0) system(cls); printf(选择有误,默认返回主菜单,请重新选择:n); inputchioce(); return head;/*/struct tushu_node * luruxinxi_xiugai() /*修改图书信息的函数(按编号修改)*/int n=0,x=-1,t; int num; int numm; char leibie10; char name30; char author20; char press20;char time20; double price; struct tushu_node*head=null; struct tushu_node*p; printf(n所有的图书信息如下:n);if( (fpp=fopen(1.txt,r)=null ) /* 输入要修改的图书编号之前 先遍历所有图书信息 */ printf( 打开文件失败 ! );exit(0);else printf(nn编号 类别 书名 作者 出版社 出版时间 价格n); while(!feof(fpp) fscanf(fpp,%d%s%s%s%s%s%lf,&num,leibie,name,author,press,time,&price); printf(%d %s %s %s %s %s %lfn,num,leibie,name,author,press,time,price); if(fclose(fpp)printf(关闭文件失败!n);exit(0); printf(n输入需要修改的图书的编号:); scanf(%d,&numm); system(cls); /* 先遍历后选择完要修改的图书编号后 清屏*/head=wjtolb(head,&n); printf(nn); printf(1-修改图书编号 2-修改图书类别n); printf(3-修改图书书名 4-修改图书作者n); printf(5-修改图书出版社 6-修改图书出版时间n); printf(7-修改图书价格 n); printf(nn); printf(编号为%d本图书的信息为:n,numm); if(head!=null&head-num=numm) /*修改头结点*/ printf(编号 类别 书名 作者 出版社 出版时间 价格n);printf(%d %s %s %s %s %s %lfn,head-num,head-leibie,head-name,head-author,head-press,head-time,head-price);printf(请选择需要修改的图书信息的成分:);scanf(%d,&t);switch(t) case 1:printf( 请输入图书%d的新编号:n,numm);scanf(%d,&num);head-num=num;break;case 2:printf( 请输入图书%d的新类别:n,numm);scanf(%s,leibie); strcpy(head-leibie,leibie);break;case 3:printf( 请输入图书%d的新书名:n,numm);scanf(%s,name); strcpy(head-name,name);break;case 4:printf( 请输入图书%d的新作者:n,numm);scanf(%s,author); strcpy(head-author,author);break;case 5:printf( 请输入图书%d的新出版社:n,numm);scanf(%s,press); strcpy(head-press,press);break;case 6:printf( 请输入图书%d的新出版时间:n,numm);scanf(%s,time); strcpy(head-time,time);break;case 7:printf( 请输入图书%d的新价格:n,numm);scanf(%lf,&price); head-price=price;break; default: system(cls); printf(选择有误,默认返回主菜单,请重新选择:n); inputchioce();break; save(head); printf(nn是否继续操作? 请选择(继续-1/退出-0)); scanf(%d,&x); if(x=1) system(cls);inputchioce(); if(x=0) printf(nn谢谢你的使用! 再见n); exit (0); if(x!=1&x!=0) system(cls); printf(选择有误,默认返回主菜单,请重新选择:n); inputchioce(); else /* 要修改的不是头节点 */p=head-next;/do 用do-while语句事不能对第二本图书进行修改/p=p-next;while(p!=null&p-num!=numm); while(p!=null&p-num!=numm) p=p-next; if(p!=null&p-num=numm) /* 修改其他节点 */ printf(nn编号 类别 书名 作者 出版社 出版时间 价格n); printf(%d %s %s %s %s %s %lfn, p-num,p-leibie,p-name,p-author,p-press,p-time,p-price); printf(请选择需要修改的图书信息的成分:); scanf(%d,&t); switch(t) case 1:printf( 请输入图书%d的新编号:n,numm);scanf(%d,&num); p-num=num;break;case 2:printf( 请输入图书%d的新类别:n,numm);scanf(%s,leibie); strcpy(p-leibie,leibie);break;case 3:printf( 请输入图书%d的新书名:n,numm);scanf(%s,name); strcpy(p-name,name);break;case 4:printf( 请输入图书%d的新作者:n,numm);scanf(%s,author); strcpy(p-author,author);break;case 5:printf( 请输入图书%d的新出版社:n,numm);scanf(%s,press); strcpy(p-press,press);break;case 6:printf( 请输入图书%d的新出版时间:n,numm);scanf(%s,time); strcpy(p-time,time);break;case 7:printf( 请输入图书%d的新价格:n,numm);scanf(%lf,&price); p-price=price;break; default: system(cls); printf(选择有误,请重新选择:n); inputchioce();break; save(head); printf(nn是否继续操作? 请选择(继续-1/退出-0)); scanf(%d,&x); if(x=1) system(cls); inputchioce(); if(x=0) printf(nn谢谢你的使用! 再见n); exit (0); if(x!=1&x!=0) system(cls); printf(选择有误,默认返回主菜单,请重新选择:n); inputchioce(); return head;/*/int liulantushu() /* 浏览图书信息的函数 */ int num; char leibie10;char name30;char author20; char press20;char time20;double price; int x=-1;if( (fpp=fopen(1.txt,r)=null )printf( 打开文件失败 ! );exit(0);elseprintf(nn编号 类别 书名 作者 出版社 出版时间 价格n); while(!feof(fpp)fscanf(fpp,%d%s%s%s%s%s%lf,&num,leibie,name,author,press,time,&price); printf(%dt%st%st%st%st%st%lfn,num,leibie,name,author,press,time,price); if(fclose(fpp)printf(关闭文件失败!n);exit(0); printf(nn是否继续操作? 请选择(继续-1/退出-0)); scanf(%d,&x); if(x=1) system(cls); inputchioce(); if(x=0) printf(nn谢谢你的使用! 再见n); exit (0); if(x!=1&x!=0) system(cls); printf(选择有误,默认返回主菜单,请重新选择:n); inputchioce(); /*/int chaxuntushu() /* 查询图书信息 */int k;int n=0; struct tushu_node*head=null;head=wjtolb(head,&n); printf( |+ 查询图书信息+|n);printf( | 1- 按编号查询图书信息 * * 2- 按书名查询图书信息 |n); p
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
评论
0/150
提交评论