C语言大作业(图书管理)

合集下载

C大作业图书管理系统实验报告

C大作业图书管理系统实验报告

附件1:学号:00126《面向对象程序设计》大作业题目学生成绩管理系统学院文法学院专业教育学班级教育学1201姓名杨欣指导教师鄢红国2013 年12 月20 日目录一设计目的 (1)二大作业的内容 (2)三大作业的要求与数据 (3)四大作业应完成的工作 (4)五总体设计(包含几大功能模块) (5)六详细设计(各功能模块的具体实现算法——流程图) (6)七调试分析(包含各模块的测试用例,及测试结果) (7)八总结 (8)十参考资料 (9)一大作业的目的《面向对象程序设计》是一门实践性很强的课程,通过大作业不仅可以全方位检验学生知识掌握程度和综合能力,而且还可以进一步加深、巩固所学课程的基本理论知识,理论联系实际,进一步培养自己综合分析问题和解决问题的能力。

更好地掌握运用C++语言独立地编写、调试应用程序和进行其它相关设计的技能。

二大作业的内容对图书信息(包括编号、书名、总入库数量、当前库存量、已借出本数等)进行管理,包括图书信息的输入、输出、查询、删除、排序、统计、退出.将图书的信息进行记录,信息内容包含:(1)图书的编号(2)图书的书名(3)图书的库存量。

假设,现收集到了一个图书馆的所有图书信息,要求用C语言编写一个简单的图书管理系统,可进行录入、查询、修改和浏览等功能。

学习相关开发工具和应用软件,熟悉系统建设过程。

三大作业的要求与数据1、用C语言实现系统;2、对图书信息(包括编号、书名、总入库数量、当前库存量、已借出本数)进行管理,包括图书信息的输入、输出、查询、删除、排序、统计、退出.3、图书信息包括:其内容较多,为了简化讨论,要求设计的管理系统能够完成以下功能:(1) 每一条记录包括一本图书的编号、书名、库存量(2) 图书信息录入功能:(图书信息用文件保存,可以一次完成若干条记录的输入。

)(3) 图书信息显示浏览功能:完成全部图书记录的显示。

(4) 查询功能:完成按书名查找图书记录,并显示。

C大作业图书馆管理系统

C大作业图书馆管理系统

C大作业图书馆管理系统《图书馆管理系统》大作业说明书学生姓名董勋凯学号 2412332 所属学院电信工程学院专业电气工程及其自动化班级电气123班组长董勋凯电信工程学院制目录摘要............................................. 错误!未定义书签。

1. 图书管理系统概述.............................. 错误!未定义书签。

1.1图书管理系统总体设计思想概述.................. 错误!未定义书签。

1.2总体设计流程图 ............................... 错误!未定义书签。

2. 图书管理系统详细设计.......................... 错误!未定义书签。

2.1C++中应用程序编程............................. 错误!未定义书签。

2.1.1结构体,存放书籍及借书信息.................. 错误!未定义书签。

2.1.2页头函数,能够经过参数menu_item,显示当前状态 .. 错误!未定义书签。

2.1.1主要功能函数源代码.......................... 错误!未定义书签。

2.2算法调试、测试过程中出现的问题及解决方案...... 错误!未定义书签。

2.2.1本系统调试过程中遇到问题:.................. 错误!未定义书签。

2.2.2本系统调试过程中遇到问题的原因:............ 错误!未定义书签。

2.2.3本系统调试过程中遇到问题的解决办法及步骤:.. 错误!未定义书签。

课程设计总结和体会............................... 错误!未定义书签。

主要参考资料..................................... 错误!未定义书签。

摘要随着计算机技术的不断应用和提高,计算机已经深入到社会生活的各个角落。

C语言实训图书管理链表结构

C语言实训图书管理链表结构

目录1、问题定义 (3)2、系统设计 (3)2.1 总体设计 (3)2.2 详细设计 (4)2.2.1数据结构设计 (4)2.2.2 主控main()函数执行流程 (5)2.2.3输入记录模块 (5)2.2.4输出记录模块 (5)2.2.5添加记录模块 (5)2.2.6删除记录模块 (6)2.2.7查询记录模块 (6)2.2.8函数功能描述 (6)3、系统实现 (7)3.1 编码 (7)3.1.1 程序预处理 (7)3.1.2 主函数main() (7)3.1.3 主菜单界面 (10)3.1.4 显示图书信息 (11)3.1.5增加图书信息 (11)3.1.6删除图书信息 (12)3.1.7查询图书信息 (14)3.2 测试与调试 (15)3.2.1 概述 (15)3.2.2 程序测试 (16)4、系统维护 (20)5、归纳总结 (20)5.1 开发经验 (20)5.2 实训中遇到的问题及解决方法 (20)5.3 设计中尚存的不足之处 (21)5.4 感想和心得体会 (21)图书管理02本题目设计目的是训练学生的基本编程能力,了解管理信息系统的开发流程,熟悉C语言的文件和单链表的各种基本操作。

本程序中涉及结构体、单链表等方面的知识。

通过本程序的训练,使学生能对C语言的文件操作有一个更深刻的了解,掌握利用单链表存储结构实现对图书管理的原理,为进一步开发出高质量的管理信息系统打下坚实的基础。

1、问题定义创建一个图书信息管理系统。

假设系统中每本图书信息只包括编号、书名、作者名字、单价、出版社名字。

程序的运行效果如下图所示,选择菜单实现相应功能。

2、系统设计2.1 总体设计采用模块化的程序设计方法,即将较大的任务按照一定的原则分为一个个较小的任务,然后分别设计各个小任务。

需要注意的是划分出来的模块应该相对独立但又相关,且容易理解。

可以用模块化层次结构图(即模块图)来分析其任务的划分,一般从上到下进行,最上面一层是主模块,下面各层是其上一层模块的逐步细化描述。

图书馆管理系统c语言

图书馆管理系统c语言
if(t0!=1&&t2==1)
/*t0不等于1则表示正常返回,t2=1则表示在此之前有过删除,这时就保存用户已确认的删除并返回*/
{if((i!=0)&&(i%10==0))/*用于分屏显示*/
{printf(“\n\n请记录需要删除的图书编号。任意键继续……”);
getch();
puts(“\n\n”);
}
printf_one(i);/*调用显示一个记录的函数*/
}
do
{printf(“\n\n请输入您需要删除的图书编号 。 NO.:”);
{printf(“\n成功删除,是否继续删除?\n\n\t 1). 是2)返回并保存\t[ ]\b\b);
scanf(“%d”,&t0);
t2=1;/*来控制保存,使w2=1是标记已有过的记录*/
}
eles
{to=0;
if(t2==1)
ts[k]=s;
}
/*到此处由于用户没有确认这次删除。使t0=0,为了终止循环,ts[k]=s;则把备份的s恢复给ts[k],这样使得在此之前删除过的成功保存而本次不删除*/
puts("\t\t\t7. 图书借阅\n");
puts("\t\t\t8. 图书归还\n");
puts("\t\t\t9. 退出系统\n");
puts("\t\t\t\n\n\n*****************************\n\n");
/*对功能选项的显示*/
printf("选择使用功能种类(1--9)[ ]\b\b");
scanf(“%f”,&t.bh );/*输入需要删除的图书编号*/

C语言程序设计大作业--图书管理系统

C语言程序设计大作业--图书管理系统

C语言程序设计大作业设计报告一.设计方案本程序旨在用一个C语言程序实现简单的图书馆图书管理系统,程序包含平时的借书,还书,新书录入,查询功能,用简单明了的人机交互界面快速实现图书管理的目的。

二.模块说明及代码分析1.主函数:源代码:void main(){int a;printf("\n");printf("\n");printf(" ( ^_^ ) WELCOME!\n");printf("\n");printf("\n");printf("\n");printf("\n");printf("\n");printf("\t〉〉-------------BJTU图书管理系统--------------〈〈");printf("\n");printf("\n");printf("\n");printf("\n");printf("\n");printf("\n");printf("\n");do {printf("1.借书 2.还书 3.新书录入4.查询 0.退出");printf("\n");printf("\n");printf("\n");printf("\n");printf("请选择序号:");scanf("%d",&a);switch(a){case 1:jieshu();break;case 2:huanshu();break;case 3:xinshu();break;case 4:chaxun();break;case 0:break;default:printf("请选择正确的序号!\n");printf("\n");}}while(a!=0);printf("谢谢使用图书管理系统!\n");}主函数提供人机交互界面,让操作者选择所需的操作项目,并有退出选项。

C++大作业 图书管理系统 实验报告

C++大作业  图书管理系统 实验报告

附件1:学号:0121213640126《面向对象程序设计》大作业题目学生成绩管理系统学院文法学院专业教育学班级教育学1201姓名杨欣指导教师鄢红国2013 年12 月20 日目录一设计目的 (1)二大作业的内容 (2)三大作业的要求与数据 (3)四大作业应完成的工作 (4)五总体设计(包含几大功能模块) (5)六详细设计(各功能模块的具体实现算法——流程图) (6)七调试分析(包含各模块的测试用例,及测试结果) (7)八总结 (8)十参考资料 (9)一大作业的目的《面向对象程序设计》是一门实践性很强的课程,通过大作业不仅可以全方位检验学生知识掌握程度和综合能力,而且还可以进一步加深、巩固所学课程的基本理论知识,理论联系实际,进一步培养自己综合分析问题和解决问题的能力。

更好地掌握运用C++语言独立地编写、调试应用程序和进行其它相关设计的技能。

二大作业的内容对图书信息(包括编号、书名、总入库数量、当前库存量、已借出本数等)进行管理,包括图书信息的输入、输出、查询、删除、排序、统计、退出.将图书的信息进行记录,信息内容包含:(1)图书的编号(2)图书的书名(3)图书的库存量。

假设,现收集到了一个图书馆的所有图书信息,要求用C语言编写一个简单的图书管理系统,可进行录入、查询、修改和浏览等功能。

学习相关开发工具和应用软件,熟悉系统建设过程。

三大作业的要求与数据1、用C语言实现系统;2、对图书信息(包括编号、书名、总入库数量、当前库存量、已借出本数)进行管理,包括图书信息的输入、输出、查询、删除、排序、统计、退出.3、图书信息包括:其内容较多,为了简化讨论,要求设计的管理系统能够完成以下功能:(1) 每一条记录包括一本图书的编号、书名、库存量(2) 图书信息录入功能:(图书信息用文件保存,可以一次完成若干条记录的输入。

)(3) 图书信息显示浏览功能:完成全部图书记录的显示。

(4) 查询功能:完成按书名查找图书记录,并显示。

c++大作业_图书管理系统

c++大作业_图书管理系统

cout<<"--| 请选择操作:"<<endl ;
cout<<"--| 1:查看所有读者 |-----------"<<endl;
cout<<"--| 2:添加读者 |-----------"<<endl;
cout<<"--| 3:删除读者 |------------"<<endl;
cout<<"--| 4:查找读者 |------------"<<endl;
cout<<"--| 5:查找图书 |-------------"<<endl ;
cout<<"--| 6:退出
|-------------"<<endl ;
cout<<"\n \n" ;
cout<<"输入相关序号选择>:"<<endl;
}
void print_reader()//读者登录界面
{
cout<<"---------欢迎使用:---------------"<<endl ;
从功能角度来看,应当实现的功能包括: (1)借还功能
对经过身份认证的合法用户进行的主要服务 (2)查询功能
对合法用户给予的查询书籍、个人借阅状况,及对管理人员提供的方便维护的服务 (3)维护功能
对图书、读者等添加,编辑,修改,删除等操作 (4)存储功能
将读者、图书信息存储于文件中,方便下次使用

C语言大作业之图书管理系统的实现详程

C语言大作业之图书管理系统的实现详程

C语⾔⼤作业之图书管理系统的实现详程⽬录主要内容概要设计项⽬源码结构体登录界⾯函数选择界⾯函数操作界⾯函数添加函数查找函数删除函数借书管理函数信息储存函数还书函数修改函数添加借书函数查找借书函数借书管理函数主函数总结序时间在流去,我们在长⼤。

嗨,这⾥是狐狸~~今天是2022年的⼀⽉四⽇了,元旦⼩长假也过去了,新年新⽓象,新年新⽬标,我们要向前看,不要执意过去了,感谢过去,把握现在,展望未来,这是我们现在应该做的。

好了,废话不多说,今天我们分享⼀个系统,确实也有许久没有分享过系统了,今天就给⼤家详细讲⼀下这个图书管理系统吧。

主要内容开发⼀个图书信息管理系统,图书信息包括:图书编号、书名、作者、出版社、类别、出版时间、价格等基本信息(也可以根据⾃⼰情况进⾏扩充,⽐如是否借出、库存量等)。

使之能提供以下基本功能:(1)图书信息录⼊功能(图书信息⽤⽂件保存)--输⼊(2)图书信息浏览功能--输出(3)查询功能(⾄少⼀种查询⽅式)、排序功能(⾄少⼀种排序⽅式):(4)图书信息的删除与修改扩展功能:可以按照⾃⼰的程度进⾏扩展。

⽐如(1)简单的权限处理(2)报表打印功能(3)甚⾄根据⾃⼰情况,可以加上学⽣信息,并扩充为图书借阅系统。

(4)模糊查询(5)综合查询(6)统计功能⽐如统计处某⼀类别的图书信息或筛选出⼩于指定数量库存的图书信息等等。

概要设计1 图书录⼊可以录⼊图书名,作者,出版社,出版⽇期,价格!录⼊图书编号时函数就会判断此编号是否存在,若存在不能成功录⼊!2 图书浏览可以浏览全部图书!3 图书查询提供按图书编号模糊查询,按图书名关键字查询,按图书编号精确查询,按图书名精确查询!模糊查询和关键字查询事通过⽐价字符串的相似度⽽实现的!4 修改删除图书可以通过图书查询来查询操作的图书编号,通过编号操作!函数会提⽰⽤户是否调⽤图书查询来找到⾃⼰想要操作的图书的编号。

如果某⼀本图书已经被借阅那么⽤户就不能删除该图书!5 借阅图书通过学号和图书编号进⾏借阅!如果该学号是第⼀次借阅那么会提⽰⽤户输⼊⾃⼰的姓名,并存⼊student.txt,⽅便以后借阅与归还!6 归还图书先提供学号,然后程序会输出该学号借阅的所有图书,然后再通过编号归还!7 借阅查询可查询某个学⽣已借但未归还的图书!项⽬源码先建⽴结构体,定义结构体成员123456789101112131415161718192021222324252627282930typedef struct book/*图书结构体*/{char num[10]; /*书号*/char name[10]; /*书名*/char auth[10]; /*作者*/int count;int sum;}Book;typedef struct borrow/*借书结构体*/{char id[20];char user[20];char book[20];char bookid[20];struct borrow *next;}BBnode,*BBlink;struct user{char num[10];/* 学号 */char pass[15];char name[15];char sex[10];};typedef struct unode{struct user data;struct unode *next;}Unode,*Ulink;Unode *os;登录界⾯函数123456789101112131415161718int login(Ulink l){ /*****************登陆窗⼝初始化****************************/while(!flag){char User_id[10],password[10],tmp;int i=0;User_id[0]='\0';23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80textcolor(YELLOW);cputs("ESC = EXIT");textcolor(WHITE);textbackground(179);box(1,1,80,24);h_line(2,3,78);gotoxy(15,2);cputs("Login now please input the User__ID and Password");bar_(30,10,23,5,5);/******************账号过滤*********************/while(User_id[0]=='\0'){gotoxy(31,11);textcolor(YELLOW);textbackground(5);cputs("User__ID:");gotoxy(31,13);cputs("Password:");textbackground(179);textcolor(WHITE);gotoxy(28,7);cputs("please input the User__ID!");textbackground(179);textcolor(YELLOW);gotoxy(27,11);putch(272);gotoxy(27,13);putch(' ');gotoxy(40,11);tmp=getch();if(tmp==27){flg=27;return0;}while(tmp!='\r'&&i<=9&&(tmp>=64&&tmp<=90)||(tmp>=97&&tmp<=122||(tmp>=48&&tmp<=57))) {textcolor(YELLOW);textbackground(5);putch(tmp);User_id[i]=tmp;i++;tmp=getch();if(tmp==27){flg=27;return0;}}User_id[i]='\0';}/**********************密码过滤****************************/while(password[0]=='\0'){gotoxy(28,7);textbackground(179);textcolor(WHITE);cputs(" input the password now ");textbackground(179);textcolor(YELLOW);gotoxy(27,13);putch(272);gotoxy(27,11);putch(' ');gotoxy(40,13);i=0;tmp=getch();if(tmp==27){flg=27;return0;858687888990919293949596979899100101102103104105106107108109110111112password[i]=tmp;i++;tmp=getch(); if(tmp==27) {flg=27;return 0;}}password[i]='\0';}/*************把账号和密码进⾏对⽐验证**************/if(!strcmp(User_id,"admin")&&!strcmp(password,"admin")){ return 2; }if(cmps(l,User_id,password)){return 1;}}}选择界⾯函数1234567891011121314151617181920212223void choose(){while(1){ textbackground(179);clrscr();gotoxy(33,2);textcolor(WHITE);cputs("Administrastor");textcolor(YELLOW);box(1,1,80,24);h_line(2,3,78);gotoxy(3,6);cputs(">>>er Management----------------------------<<<");gotoxy(3,10);cputs(">>>-------------------------2.Book Management----------------------------<<<"); gotoxy(3,14);cputs(">>>-------------------------3.Borrow Books-------------------------------<<<");gotoxy(30,22);textcolor(RED);cputs("Please Select");28293031323334353637383940414243444546474849505152if(flg=='3')borrow();if(flg==27){ flg=-1;return;}} }void admin(){while(1){choose(); if(flg=='1') bookss();if(flg=='2')users();if(flg=='3')borrow();if(flg==27){return;}}}操作界⾯函数1234567891011121314151617181920212223242526void user(Ulink h){int flag;BBlink l,p,r;/* 连表 */FILE *fp; /* ⽂件指针 */int count=0;l=(BBnode*)malloc(sizeof(BBnode));l->next=NULL;r=l;fp=fopen(bfile,"rb");if(fp==NULL){ fp=fopen(bfile,"wb");}while(!feof(fp)){ p=(BBnode*)malloc(sizeof(BBnode)); if(fread(p,sizeof(BBnode),1,fp)) /* 将⽂件的内容放⼊接点中 */ {p->next=NULL;r->next=p; r=p; /* 将该接点挂⼊连中 */ count++; }313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778textcolor(YELLOW);box(1,1,80,24);h_line(2,3,78); gotoxy(3,2); textcolor(RED);cputs("A.");textcolor(BLUE);cputs("my message "); textcolor(RED); cputs("B."); textcolor(BLUE);cputs("modyfy my message ");textcolor(RED); cputs("C."); textcolor(BLUE); cputs("my borrow ");textcolor(RED);cputs("D."); textcolor(BLUE); cputs("search book"); textcolor(YELLOW);gotoxy(50,50);flag=getch();switch(flag) { case 'a': show(os);break; /*************添加⽤户**********/ case 'b':Modify_user(h);Save(h); break;/*************删除⽤户**********/ case 'c': Myborrow(); break;case 'd':usersearch();break; case 27: return; } }}添加函数图书的添加,包括⽤户添加以及管理员添加16 7 8 9 1011 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63void add(blink l){Bnode *p,*r,*s;char num[10];r=l;s=l->next;while(r->next!=NULL)r=r->next;textcolor(RED);gotoxy(25,4);cputs("INPUT THE MESSAGE ABOUT BOOK"); gotoxy(31,10);textcolor(YELLOW);cputs("Book ID:");scanf("%s",num);p=(Bnode *)malloc(sizeof(Bnode));while(s){if(strcmp(s->data.num,num)==0){textcolor(WHITE);gotoxy(25,15);cputs("This ID:");printf("'%s'",num);cputs("is exist!");gotoxy(25,22);cputs("please Press any key to continue..."); gotoxy(255,252);getch();return;}s=s->next;}strcpy(p->data.num,num);gotoxy(31,12);textcolor(YELLOW);cputs("Input Book name:");scanf("%s",p->);gotoxy(31,14);cputs("input your Book auth:");scanf("%s",p->data.auth);gotoxy(31,16);cputs("input your Book count:");scanf("%d",&p->data.count);bookcount=p->data.count+bookcount;p->data.sum=0;p->next=NULL;r->next=p;r=p;gotoxy(30,22);textcolor(RED);cputs("Add Book Success ");getch();textcolor(YELLOW);}/*******管理员添加⽤户*******/void Add(Ulink l){Unode *p,*r,*s;char num[10];r=l;s=l->next;while(r->next!=NULL)r=r->next;6869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109textcolor(YELLOW);cputs("User ID:");scanf("%s",num);p=(Unode *)malloc(sizeof(Unode)); while(s){if(strcmp(s->data.num,num)==0){ gotoxy(25,15); cputs("This ID:"); printf("'%s'",num);cputs("is exist!");gotoxy(25,22); textcolor(RED); cputs("please Press any key to continue..."); gotoxy(255,252);getch();return;} s=s->next;}strcpy(p->data.num,num);gotoxy(31,12);textcolor(YELLOW);cputs("Input Password:");scanf("%s",p->data.pass);gotoxy(31,14);cputs("input your name:");scanf("%s",p->);gotoxy(31,16);cputs("input the sex:");scanf("%s",p->data.sex);p->next=NULL;r->next=p;r=p;gotoxy(30,22);cputs("Add User Success ");usercount++;getch();textcolor(YELLOW);}查找函数⽤户查找以及管理员查找123456712 13 14 15 16 17 18 19 20 21 22 23 2425 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69/*******管理员查找图书*******/void qur(blink l){int sel;char findmess[20];Bnode *p;if(!l->next){gotoxy(30,4);textcolor(WHITE);cputs("Not Find Bookdata");getch();return;}textcolor(RED);gotoxy(25,4);cputs("Please Select Search Type !"); gotoxy(10,8);textcolor(WHITE);cputs("1.Search by ID");gotoxy(10,10);cputs("2.Search by Name");gotoxy(10,12);cputs("Please Select 1 or 2:");scanf("%d",&sel);if(sel==1){gotoxy(36,8);textcolor(YELLOW);cputs("Input the search ID:");scanf("%s",findmess);p=locate(l,findmess,"num");if(p){gotoxy(36,12);textcolor(WHITE);cputs("Book ID:");printf("%s",p->data.num);gotoxy(36,14);textcolor(WHITE);cputs("Book Name:");printf("%s",p->);gotoxy(36,16);textcolor(WHITE);cputs("Book author:");printf("%s",p->data.auth);gotoxy(36,18);textcolor(WHITE);cputs("Book count:");printf("%d",p->data.count);getch();textcolor(YELLOW);gotoxy(30,21);74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 textcolor(RED);cputs("Not finde ");getch();}}else if(sel==2) /* 姓名 */{gotoxy(36,8);textcolor(YELLOW);cputs("Input the search name:");scanf("%s",findmess);p=locate(l,findmess,"name");if(p){gotoxy(36,12);textcolor(WHITE);cputs("Book ID:");printf("%s",p->data.num);gotoxy(36,14);textcolor(WHITE);cputs("Book Name:");printf("%s",p->);gotoxy(36,16);textcolor(WHITE);cputs("Book author:");printf("%s",p->data.auth);gotoxy(36,18);textcolor(WHITE);cputs("Book count:");printf("%d",p->data.count);getch();textcolor(YELLOW);}else{textcolor(RED);gotoxy(30,22);cputs("Not finde ");}}else{textcolor(RED);gotoxy(30,22);cputs("Error !!");getch();}}/*******⽤户查找图书*******/void usersearch(){int sel;char findmess[20];Bnode *p;blink l;/* 连表 */FILE*fp; /* ⽂件指针 */int count=0;Bnode *P,*r;l=(Bnode*)malloc(sizeof(Bnode));l->next=NULL;r=l;fp=fopen(file,"rb");if(fp==NULL){fp=fopen(file,"wb");}while(!feof(fp)){P=(Bnode*)malloc(sizeof(Bnode));if(fread(P,sizeof(Bnode),1,fp)) /* 将⽂件的内容放⼊接点中 */ {P->next=NULL;bookcount=bookcount+P->data.count;booksum=booksum+P->data.sum;136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 r->next=P;r=P; /* 将该接点挂⼊连中 */count++;}}fclose(fp); /* 关闭⽂件 */if(!l->next){gotoxy(30,4);textcolor(WHITE);cputs("Not Find Bookdata");getch();return;}textcolor(RED);gotoxy(25,4);cputs("Please Select Delete Type !"); gotoxy(10,8);textcolor(WHITE);cputs("1.Search by ID");gotoxy(10,10);cputs("2.Search by Name");gotoxy(10,12);cputs("Please Select 1 or 2:");scanf("%d",&sel);if(sel==1){gotoxy(36,8);textcolor(YELLOW);cputs("Input the search ID:");scanf("%s",findmess);p=locate(l,findmess,"num");if(p){gotoxy(36,12);textcolor(WHITE);cputs("Book ID:");printf("%s",p->data.num);gotoxy(36,14);textcolor(WHITE);cputs("Book Name:");printf("%s",p->);gotoxy(36,16);textcolor(WHITE);cputs("Book author:");printf("%s",p->data.auth);gotoxy(36,18);textcolor(WHITE);cputs("Book count:");printf("%d",p->data.count-p->data.sum); getch();textcolor(YELLOW);}else{gotoxy(30,22);textcolor(RED);cputs("Not finde ");getch();}}else if(sel==2){gotoxy(36,8);textcolor(YELLOW);cputs("Input the search name:");scanf("%s",findmess);p=locate(l,findmess,"name");if(p){gotoxy(36,12);textcolor(WHITE);cputs("Book ID:");printf("%s",p->data.num);198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 gotoxy(36,14);textcolor(WHITE);cputs("Book Name:");printf("%s",p->);gotoxy(36,16);textcolor(WHITE);cputs("Book author:");printf("%s",p->data.auth);gotoxy(36,18);textcolor(WHITE);cputs("Book count:");printf("%d",(p->data.count-p->data.sum)); getch();textcolor(YELLOW);}else{textcolor(RED);gotoxy(30,22);cputs("Not finde ");}}else{textcolor(RED);gotoxy(30,22);cputs("Error !!");getch();}}/*******图书查找*******/int cmpbook(blink l,char id[],char na[]){char findm[20];Bnode *p;if(!l->next){gotoxy(25,4);textcolor(RED);cputs("Not Find Book");getch();return0;}strcpy(findm,id);p=locate(l,findm,"num");if(p){strcpy(findm,na);p=locate(l,findm,"name");if(p){return1;}else{textcolor(RED);gotoxy(30,22);cputs("Book name is NULL ");getch();return0;}}else{gotoxy(30,22);textcolor(RED);cputs("Book id is NULL ");getch();return0;}260261262263264265266267268269270271272273274275276277278279280281282283284285286287}删除函数图书的删除12345678 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25void del(blink l){int sel;Bnode *p,*r;char findmess[20];if(!l->next){gotoxy(25,4);textcolor(RED);cputs("=====>not thing could delete!\n"); getch();return;}textcolor(RED);gotoxy(25,4);puts("Please Select Delete Type !");gotoxy(10,8);textcolor(WHITE);cputs("1.Delete by Book ID");26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 gotoxy(10,10);cputs("2.Delete by Book Name");gotoxy(10,12);cputs("Please Select 1 or 2:");scanf("%d",&sel);if(sel==1){gotoxy(36,8);textcolor(YELLOW);cputs("Input the delete ID:");scanf("%s",findmess);p=locate(l,findmess,"num");if(p){bookcount=bookcount-p->data.count; r=l;while(r->next!=p)r=r->next;r->next=p->next;free(p);gotoxy(30,22);textcolor(RED);cputs("Delete success!\n");textcolor(YELLOW);}else{textcolor(RED);gotoxy(30,22);cputs("Error !!");}}else if(sel==2){gotoxy(36,8);textcolor(YELLOW);cputs("Input the delete name:");scanf("%s",findmess);p=locate(l,findmess,"name");if(p){r=l;while(r->next!=p)r=r->next;r->next=p->next;free(p);gotoxy(30,22);textcolor(RED);cputs("Delete success!\n");bookcount--;textcolor(YELLOW);}else{gotoxy(25,18);cputs("Not find!!");}}else{textcolor(RED);gotoxy(30,22);cputs("Error !!");}getch();textcolor(YELLOW);}借书管理函数1234567 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56void borrow(){while(1){int flag;BBlink l,p,r;/* 连表 */FILE*fp; /* ⽂件指针 */int count=0;l=(BBnode*)malloc(sizeof(BBnode));l->next=NULL;r=l;fp=fopen(bfile,"rb");if(fp==NULL){fp=fopen(bfile,"wb");}while(!feof(fp)){p=(BBnode*)malloc(sizeof(BBnode));if(fread(p,sizeof(BBnode),1,fp)) /* 将⽂件的内容放⼊接点中 */ {p->next=NULL;r->next=p;r=p; /* 将该接点挂⼊连中 */count++;}borrowcount=count;}while(1){textbackground(179);clrscr();textcolor(YELLOW);box(1,1,80,24);h_line(2,3,78);gotoxy(3,2);textcolor(RED);cputs("B");textcolor(BLUE);cputs("orrow book ");textcolor(RED);cputs("R");textcolor(BLUE);cputs("eturn book ");textcolor(RED);cputs("S");textcolor(BLUE);cputs("earch borrow ");textcolor(YELLOW);printf("count: (borrow=%d)",borrowcount);textcolor(RED);gotoxy(50,50);flag=getch();switch(flag){case'b':Add_borrow(l);break; /*************添加⽤户**********/case'r':57585960616263646566676869707172Del_borrow(l);Save_borrow(l);break; case 's': Qur_borrow(l); break;case 27:return;}} }}信息储存函数图书信息的储存123456789101112131415161718192021222324252627282930313233343536*******借书信息保存*******/void Save_borrow(BBlink l){FILE* fp;BBnode *p; int flag=1,count=0; fp=fopen(bfile,"wb"); if(fp==NULL) {gotoxy(35,12);textcolor(RED); cputs("open error!"); exit(1); }p=l->next;while(p){ if(fwrite(p,sizeof(BBnode),1,fp)==1) {p=p->next;count++;} else {flag=0;break;}}if(flag){textcolor(RED);gotoxy(30,24); /*** printf("save success.(saved%d.)",count);**调试的时候⽤的*/}fclose(fp);}还书函数123456789101112 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56/* 还书的操作 */void Del_borrow(BBlink l){int sel;BBnode *p,*r;Bnode *L;char findmess[20];FILE*fp; /* ⽂件指针 */Bnode *P,*R,*Q;L=(Bnode*)malloc(sizeof(Bnode));L->next=NULL;R=L;fp=fopen(file,"rb");if(fp==NULL){fp=fopen(file,"wb");}while(!feof(fp)){P=(Bnode*)malloc(sizeof(Bnode));if(fread(P,sizeof(Bnode),1,fp)) /* 将⽂件的内容放⼊接点中 */ {P->next=NULL;R->next=P;R=P; /* 将该接点挂⼊连中 */}}fclose(fp); /* 关闭⽂件 */if(!l->next){gotoxy(30,4);textcolor(RED);cputs("not Book could Return!\n");getch();return;}textcolor(RED);gotoxy(25,4);puts("Please Select Return Type !");gotoxy(10,8);textcolor(WHITE);cputs("1.Return by Borrow ID");gotoxy(10,10);cputs("2.Return by book name");gotoxy(10,12);cputs("Please Select 1 or 2:");scanf("%d",&sel);if(sel==1){gotoxy(36,8);textcolor(YELLOW);cputs("Input the Borrow ID:");57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 scanf("%s",findmess);p=Locate_borrow(l,findmess,"num"); if(p){Q=locate(L,findmess,"num");if(Q){Q->data.sum=Q->data.sum-1; save(L);}r=l;while(r->next!=p)r=r->next;r->next=p->next;free(p);gotoxy(30,22);textcolor(RED);cputs("Return success!\n");borrowcount--;getch();textcolor(YELLOW);}else{gotoxy(30,22);textcolor(RED);cputs("Note find !!");getch();}}else if(sel==2){gotoxy(36,8);textcolor(YELLOW);cputs("Input the Book name:");scanf("%s",findmess);p=Locate_borrow(l,findmess,"book"); if(p){Q=locate(L,findmess,"name"); if(Q){Q->data.sum=Q->data.sum-1; save(L);}r=l;while(r->next!=p)r=r->next;r->next=p->next;free(p);gotoxy(30,22);textcolor(RED);cputs("Borrow success!\n");borrowcount--;getch();textcolor(YELLOW);}else{gotoxy(30,18);textcolor(RED);cputs("Not find!!");getch();}}else{gotoxy(30,22);textcolor(RED);cputs("Not finde !!");119120121122123124125126127128129130131132getch();}textcolor(YELLOW);}修改函数也分为⽤户和管理员两种情况123456789101112131415161718192021222324252627282930313233343536373839/* ****⽤于管理员修改⽤户资料 ***/void Modify(Ulink l){Unode *p; char findmess[20]; if(!l->next) {gotoxy(30,4);textcolor(RED);cputs("not thing could modify!"); getch(); return;}gotoxy(30,4);textcolor(RED); cputs("Modify User Message"); gotoxy(25,8); textcolor(YELLOW);cputs("input the User Id:");scanf("%s",findmess); p=Locate(l,findmess,"num"); if(p) {textcolor(YELLOW);gotoxy(25,10); printf("Inpute The New ID(old:%s):",p->data.num); scanf("%s",p->data.num); gotoxy(25,12);printf("Input The New Password(old:%s):",p->data.pass); scanf("%s",p->data.pass);gotoxy(25,14); printf("Input The New Name(old:%s):",p->); scanf("%s",p->);gotoxy(25,16);printf("Input The New Sex(old:%s):",p->data.sex); scanf("%s",p->data.sex); gotoxy(30,20);40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 textcolor(RED);cputs("Modify Success ");getch();textcolor(YELLOW);}else{gotoxy(30,16);textcolor(RED);cputs("Not Finde ");getch();}}/****供⽤户修改⽤户⾃⼰资料 */void Modify_user(Ulink l){Unode *p;char findmess[20];if(!l->next){gotoxy(30,4);textcolor(RED);cputs("not thing could modify!");getch();return;}gotoxy(30,4);textcolor(RED);cputs("Modify User Message");gotoxy(33,8);textcolor(YELLOW);strcpy(findmess,os->data.num);printf("your id:%s",findmess);p=Locate(l,findmess,"num");if(p){textcolor(YELLOW);gotoxy(24,10);printf("Input The New Password(old:%s):",p->data.pass); scanf("%s",p->data.pass);gotoxy(24,12);printf("Input The New Name(old:%s):",p->);scanf("%s",p->);gotoxy(24,14);printf("Input The New Sex(old:%s):",p->data.sex);scanf("%s",p->data.sex);gotoxy(31,18);textcolor(RED);cputs("Modify Success ");getch();textcolor(YELLOW);}else{gotoxy(30,16);textcolor(RED);cputs("Not Finde ");getch();}}添加借书函数1234567891011 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56/*******添加借书*******/void Add_borrow(BBlink l){Ulink H;/* 连表 */FILE*Fp; /* ⽂件指针 */Unode *Q,*T;blink L;/* 连表 */FILE*FP; /* ⽂件指针 */int ttl;Bnode *P,*R;char bookid[20];char bookname[20];char userid[20];BBnode *p,*r,*s;char num[10];r=l;s=l->next;while(r->next!=NULL)r=r->next;L=(Bnode*)malloc(sizeof(Bnode));L->next=NULL;R=L;FP=fopen(file,"rb");if(FP==NULL){FP=fopen(file,"wb");}while(!feof(FP)){P=(Bnode*)malloc(sizeof(Bnode));if(fread(P,sizeof(Bnode),1,FP)) /* 将⽂件的内容放⼊接点中 */ {P->next=NULL;bookcount=bookcount+P->data.count;R->next=P;R=P; /* 将该接点挂⼊连中 */}}fclose(FP); /* 关闭⽂件 */H=(Unode*)malloc(sizeof(Unode));H->next=NULL;T=H;Fp=fopen(ufile,"rb");if(Fp==NULL){Fp=fopen(ufile,"wb");}while(!feof(Fp)){Q=(Unode*)malloc(sizeof(Unode));60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 T->next=Q;T=Q; /* 将该接点挂⼊连中 */}}fclose(Fp);textcolor(RED);gotoxy(25,4);cputs("Please input thease message");gotoxy(30,10);textcolor(YELLOW);cputs("Input Borrow ID:");scanf("%d",&ttl);itoa(ttl,num,10) ;p=(BBnode *)malloc(sizeof(BBnode));while(s){if(strcmp(s->id,num)==0){gotoxy(30,15);cputs("Borrow ID:");printf("'%s'",num);cputs("is exist!");gotoxy(26,22);textcolor(RED);cputs("please Press any key to continue...");gotoxy(255,252);getch();return;}s=s->next;}strcpy(p->id,num);gotoxy(31,12);textcolor(YELLOW);cputs("Input book id:");scanf("%s",bookid);gotoxy(31,14);textcolor(YELLOW);cputs("Input book name:");scanf("%s",bookname);/***************************************图书判断在否***************************************/ if(cmpbook(L,bookid,bookname)){strcpy(p->bookid,bookid);strcpy(p->book,bookname);gotoxy(31,16);cputs("input your ID:");scanf("%s",userid); /**************************************⽤户判断在否********************************/if(cmpuser(H,userid)){strcpy(p->user,userid);p->next=NULL;r->next=p;r=p;if(changeb(L,bookid)){gotoxy(30,22);cputs("Borrow Success ");Save_borrow(l);borrowcount++;getch();}}}textcolor(YELLOW);}。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

c语言图书管理系统主要功能:1. 新进图书基本信息的输入。

2. 显示全部记录3. 按图书名称查询图书基本信息。

4. 根据图书名称对撤消的图书信息进行删除。

5. 按图书名称从小到大排序。

6. 统计某价格以上的图书数量。

7. 列出所有未借出去的图书信息。

基本信息:图书编号、图书名称、单价、作者、存在状态、借书人姓名、性别、学号等#include <stdio.h>#include <stdlib.h>#include <time.h>#include <string.h>typedef int BOOL;typedef struct bookinfo{char number[15];/*产品编号*/char name[30];/*产品名称*/float price;/*单价*/char auther[20];/*作者*/BOOL isExit;/*存在状态*/char lendername[20];/*借书人姓名*/char lendersex[2];/*借书人性别*/char lendernum[15];/*借书人学号*/}BOOKINFO;void menu(){printf("\n\n\n\n\n\n\n");printf("\t\t\t图书管理系统\n");printf("\t\t\t1:新进图书基本信息的输入\n");printf("\t\t\t2:显示全部记录\n");printf("\t\t\t3:根据图书名称查询图书基本信息\n");printf("\t\t\t4:根据图书名称对撤销的图书信息进行删除\n");printf("\t\t\t5:按照图书名称从小大到排序\n");printf("\t\t\t6:统计某价格以上的图书数量\n");printf("\t\t\t7:列出所有未借出去的图书信息\n");printf("\t\t\t8:退出\n");}void choice_1_input_new()/*输入新进的图书信息*/{char choice;FILE *p;BOOKINFO newbook;system("cls");while(1){printf("输入图书编号:");gets(newbook.number);printf("输入图书名称:");gets();printf("输入图书单价:");scanf("%f",&newbook.price);while(getchar()!='\n');printf("输入图书的作者:");gets(newbook.auther);printf("输入借书人姓名:");gets(newbook.lendername);printf("输入借书人性别:");gets(newbook.lendersex);printf("输入借书人学号:");gets(newbook.lendernum);printf("是否保存该条书目?(Y/N)\n");choice=getch();while(choice!='Y'&&choice!='y'&&choice!='N'&&choice!='n')choice=getch();if(choice=='Y'||choice=='y'){newbook.isExit=1;/*将图书状态设置成1,表示没有借出*/p=fopen("c:\\bookinfo.data","ab");fwrite(&newbook,sizeof(BOOKINFO),1,p);fclose(p);printf("\n该条书目已添加到c:\\bookinfo.data文件中!\n");}else{printf("\n本条书目未保存!\n");}printf("\n是否继续添加书目?(Y/N)\n");choice=getch();while(choice!='Y'&&choice!='y'&&choice!='N'&&choice!='n')choice=getch();if(choice=='Y'||choice=='y')continue;elsebreak;}}void choice_2_display_all()/*显示全部图书信息*/{FILE *p;int n;BOOKINFO bookinfo[100];int booknumber=0;system("cls");p=fopen("c:\\bookinfo.data","rb");while(!feof(p)){fread(&bookinfo[booknumber],sizeof(BOOKINFO),1,p);booknumber++;}/*booknumber--;使用feof()函数会多读一行,因此需要booknumber自减一次,使书目的数量正确*/fclose(p);booknumber--;if(booknumber==0){printf("没有任何图书信息!\n\n");}else{n=0;printf(" 图书信息如下\n");printf(" 图书信息| 借书人信息\n");printf("编号名称单价作者图书状态| 姓名性别学号\n");while(n<booknumber){printf("%-6s%-12s%-8.1f%-8s%-9d| %-12s%-8s%-8s\n",bookinfo[n].number,bookinfo[n].name,bookinfo[n].price,bookinfo[n].auther,bookinfo[n].isExit,bookinfo[n].lendername,bookinfo[n].lendersex,bookinfo[n].lendernum);n++;}}printf("\n\n按任意键回到主菜单!\n");getch();}void choice_3_search_according_name()/*根据图书名称显示图书的信息*/ {char search[20]="";/*search用来存放要查询的书名*/int n;FILE *p;char choice;BOOKINFO bookinfo[100];int booknumber=0;system("cls");p=fopen("c:\\bookinfo.data","rb");while(!feof(p)){fread(&bookinfo[booknumber],sizeof(BOOKINFO),1,p);booknumber++;}booknumber--;/*使用feof()函数会多读一行,因此需要booknumber自减一次,使书目的数量正确*/fclose(p);while(1){printf("输入要查询的书本名称:");gets(search);if(booknumber==0){printf("书库中没有任何信息!\n\n");printf("按任意键回到主菜单!\n\n");getch();break;}/*if结束*/else{for(n=0;n<booknumber;n++)if(strcmp(bookinfo[n].name,search)==0){printf("该书的详细信息如下:\n");printf(" 图书信息|借书人信息\n");printf("编号名称单价作者图书状态| 姓名性别学号\n");printf("%-6s%-12s%-8.1f%-8s%-9d| %-12s%-8s%-8s\n", bookinfo[n].number,bookinfo[n].name,bookinfo[n].price,bookinfo[n].auther,bookinfo[n].isExit,bookinfo[n].lendername,bookinfo[n].lendersex,bookinfo[n].lendernum);break;}if(n>=booknumber)printf("没有查找该书的任何信息!\n");printf("\n\n是否继续查询?(Y/N)\n");choice=getch();while(choice!='Y'&&choice!='y'&&choice!='N'&&choice!='n')choice=getch();if(choice=='Y'||choice=='y')continue;elsebreak;}/*else结束*/}/*while(1)结束*/}void choice_4_delete_according_name()/*根据图书名称对图书信息进行删除*/ {char search[20]="";/*search用来存放要删除的书名*/int n,i;FILE *p;char choice;BOOKINFO bookinfo[100];int booknumber;system("cls");while(1){printf("输入要删除的书本名称:");gets(search);p=fopen("c:\\bookinfo.data","rb");booknumber=0;while(!feof(p)){fread(&bookinfo[booknumber],sizeof(BOOKINFO),1,p);booknumber++;}booknumber--;/*使用feof()函数会多读一行,因此需要booknumber自减一次,使书目的数量正确*/fclose(p);if(booknumber==0){printf("书库中没有任何信息!\n\n");printf("按任意键回到主菜单!\n\n");getch();break;}/*if结束*/else{for(n=0;n<booknumber;n++)if(strcmp(bookinfo[n].name,search)==0){break;}if(n>=booknumber)printf("没有查找该书的任何信息!\n");else{printf("是否确认需要删除该条书目?(Y/N)");choice=getch();while(choice!='Y'&&choice!='y'&&choice!='N'&&choice!='n')choice=getch();if(choice=='Y'||choice=='y'){for(i=n;i<booknumber-1;i++)bookinfo[i]=bookinfo[i+1];booknumber--;p=fopen("c:\\bookinfo.data","wb");for(n=0;n<booknumber;n++)fwrite(&bookinfo[n],sizeof(BOOKINFO),1,p);fclose(p);printf("删除成功!\n");}elseprintf("\n\n该条书目没有被删除!");}printf("\n\n是否继续进行删除操作?(Y/N)\n");choice=getch();while(choice!='Y'&&choice!='y'&&choice!='N'&&choice!='n')choice=getch();if(choice=='Y'||choice=='y')continue;elsebreak;}/*else结束*/}/*while(1)结束*/}void choice_5_sort_according_name()/*根据图书名称排序*/{FILE *p;int m,n;BOOKINFO temp;BOOKINFO bookinfo[100];int booknumber;p=fopen("c:\\bookinfo.data","rb");booknumber=0;system("cls");while(!feof(p)){fread(&bookinfo[booknumber],sizeof(BOOKINFO),1,p);booknumber++;}booknumber--;/*使用feof()函数会多读一行,因此需要booknumber自减一次,使书目的数量正确*/fclose(p);if(booknumber==0){printf("没有任何图书信息!\n\n");}else{for(m=0;m<booknumber-1;m++)for(n=m+1;n<booknumber;n++)if(strcmp(bookinfo[m].name,bookinfo[n].name)>0){temp=bookinfo[m];bookinfo[m]=bookinfo[n];bookinfo[n]=temp;}p=fopen("c:\\bookinfo.data","wb");for(m=0;m<booknumber;m++)fwrite(&bookinfo[m],sizeof(BOOKINFO),1,p);fclose(p);printf("\n\n完成排序!\n\n");}printf("按任意键回到主菜单!\n");getch();}void choice_6_display_high_price()/*根据价格列出图书信息*/ {float price;FILE *p;int n;int count=0;BOOKINFO bookinfo[100];int booknumber;system("cls");printf("请输入价格:");scanf("%f",&price);p=fopen("c:\\bookinfo.data","rb");booknumber=0;while(!feof(p)){fread(&bookinfo[booknumber],sizeof(BOOKINFO),1,p);booknumber++;}booknumber--;/*使用feof()函数会多读一行,因此需要booknumber自减一次,使书目的数量正确*/fclose(p);if(booknumber==0){printf("没有任何图书信息!\n\n");}else{for(n=0;n<booknumber;n++){if(bookinfo[n].price>=price)count++;}if(count==0)printf("书库中没有比%.1f$价格高的图书!",price);else{printf(" 价格高于%.1f$的图书信息如下\n",price);printf(" 图书信息| 借书人信息\n");printf("编号名称单价作者图书状态| 姓名性别学号\n");for(n=0;n<booknumber;n++){if(bookinfo[n].price>=price)printf("%-6s%-12s%-8.1f%-8s%-9d| %-12s%-8s%-8s\n", bookinfo[n].number,bookinfo[n].name,bookinfo[n].price,bookinfo[n].auther,bookinfo[n].isExit,bookinfo[n].lendername,bookinfo[n].lendersex,bookinfo[n].lendernum);}}}printf("\n\n按任意键回到主菜单!\n");getch();}void choice_7_display_according_exitflag()/*根据存在状态列出图书信息*/ {FILE *p;int n;int count=0;BOOKINFO bookinfo[100];int booknumber;system("cls");booknumber=0;p=fopen("c:\\bookinfo.data","rb");while(!feof(p)){fread(&bookinfo[booknumber],sizeof(BOOKINFO),1,p);booknumber++;}booknumber--;fclose(p);if(booknumber==0){printf("书库中没有任何书目存在!\n");}else{for(n=0;n<booknumber;n++)if(bookinfo[n].isExit==1)count++;if(count==0)printf("书库中的书籍全部借出!\n");else{printf("书库中未被借出的图书信息如下:\n\n");printf(" 图书信息| 借书人信息\n");printf("编号名称单价作者图书状态| 姓名性别学号\n");for(n=0;n<booknumber;n++)if(bookinfo[n].isExit==1){printf("%-6s%-12s%-8.1f%-8s%-9d| %-12s%-8s%-8s\n", bookinfo[n].number,bookinfo[n].name,bookinfo[n].price,bookinfo[n].auther,bookinfo[n].isExit,bookinfo[n].lendername,bookinfo[n].lendersex,bookinfo[n].lendernum);}}}printf("\n按任意键返回主菜单!\n");getch();}void main(){char choice;clock_t tm;FILE *p;if((p=fopen("c:\\bookinfo.data","rb"))==NULL){p=fopen("c:\\bookinfo.data","wb");fclose(p);}while(1){system("cls");menu();choice=getch();switch(choice){case '1':choice_1_input_new();break;/*输入新进的图书信息*/case '2':choice_2_display_all();break;/*显示全部图书信息*/case '3':choice_3_search_according_name();break;/*根据图书名称显示图书的信息*/case '4':choice_4_delete_according_name();break;/*根据图书名称对图书信息进行删除*/case '5':choice_5_sort_according_name();break;/*根据图书名称排序*/case '6':choice_6_display_high_price();break;/*根据价格列出图书信息*/case '7':choice_7_display_according_exitflag();break;/*根据存在状态列出图书信息*/case '8':printf("\n\n\t\t\t谢谢使用,再见!\n\t\t\t按任意键退出!\n");getch();return;default:printf("\n\n\t\t\t请输入菜单中的数字!(1~8)");tm=clock();while(clock()<tm+1800);break;}}}。

相关文档
最新文档