




已阅读5页,还剩14页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
程序设计方法课程设计 问题提出:设计一个图书馆的图书管理,具体要求如下:1录入新采购的图书信息,做成文件book.in,要求有良好的输入界面;2查询各种图书的基本信息,设计出良好的查询界面;3按图书编号进行排序,将排好序的图书信息输出到文件 book.out中。4统计各类图书册数、图书馆的图书总册数。5统计图书的借阅情况。1. 需求分析对于图书馆的管理系统,应该满足以下的用户需求:用户能够增加和删除一些图书。用户根据一些基本信息查询相应的图书,系统可以准确输出所有符合条件的图书信息。用户可以借阅和归还图书馆中的图书。系统可以对图书做出统计,包括图书总数,各类图书数目,图书的借阅情况。2. 设计分析定义图书结构体,其成员包括书名、作者、类型、出版社、价格、是否借阅(整型,1为借出,0为未借)、编号。输入新书时,利用结构体储存书的信息,同时将新书信息以二进制写入book.in文件中,录入结束后,将新书按输入顺序写入book.out中,并且以原来存书的最大编号为基准对新书进行编号,这样可以保证book.out文件存储的图书都是按编号进行排序的。查找图书时,获得所查书目基本信息后,以二进制依次读取文件中的每一本图书信息,并与输入信息相比较,输出符合信息的图书。删除图书时,通过输入的图书编号(编号可通过查找图书获得)查找相应图书,删除相应数据并保存。借阅或归还图书时,通过图书编号(编号可通过查找图书获得)查找相应图书,修改图书的属性(是否借阅)并保存。实现统计功能时,以二进制依次读取文件中的每一本图书信息,设置变量统计图书类型、借阅情况和图书总数,到文件结尾时,输出各个变量的值。3. 系统设计(流程图表示)开始欢迎界面打印主菜单输入选择nn=1是输入新书信息否将新书保存至book.in将book.in中图书按编号保存至book.outn=2是选择查找方式输入查找图书信息否在book.out中能找到相应图书否是输出图书信息出错提示n=3是输入删除图书信息(编号)否是否在book.out中能找到相应图书出错提示删除相应图书否是n=4选择借书或还书操作输入图书信息(编号)否是否在book.out中能找到相应图书出错提示对图书相应属性进行修改n=5是统计book.out中总书数并输出统计各类型书数并输出否统计图书借阅情况并输出是n=0结束4. 程序代码主函数main()int i,a; Struct book standard=a,a,000000000,0,0,a,others; FILE *fp; if(fp=fopen(book.out,r)=NULL) if(fp=fopen(book.out,wb)=NULL) printf(wrong!); exit(0); fwrite(&standard,sizeof(struct book),1,fp); fclose(fp); for(i=0;i=0;i-) if(ssi=58) ssi=0;ssi-1+; void minusone(char ss) /*图书编号减一*/int i;if(ss8=0)ss8=9; ss7=ss7-1; else ss8=ss8-1; for(i=7;i=0;i-) if(ssi=47) ssi=9;ssi-1-; 函数save_books()将book.in的数据写入book.out中void save_books() /*保存图书*/FILE *fp1,*fp2;struct book oldbook,newbook;char ssl10;int n,i;if(fp2=fopen(book.out,rb+)=NULL)printf(wrong!);exit(0);if(fp1=fopen(book.in,rb)=NULL)printf(wrong!);exit(0);fseek(fp2,-100L,2);fread(&oldbook,sizeof(struct book),1,fp2); /*获得目前图书最大编号*/strcpy(ssl,oldbook.number);fclose(fp2);fseek(fp1,-1L,2);fscanf(fp1,%d,&n);rewind(fp1);if(fp2=fopen(book.out,ab)=NULL)printf(wrong!);exit(0);for(i=1;i=n;i+)fread(&newbook,sizeof(struct book),1,fp1);addone(ssl);strcpy(newbook.number,ssl); /*为新图书编号*/fwrite(&newbook,sizeof(struct book),1,fp2);fclose(fp1);fclose(fp2);函数input_book将新书的信息读入book.in中void input_books() /*从键盘输入图书函数*/FILE *fp;struct book newbook;int a=121,n=0;if(fp=fopen(book.in,wb)=NULL) printf(wrong!); exit(0); while(a=121)clrscr(); n+; printf(New book %d:n,n); printf(Name:); scanf(%s,); printf(Author:); scanf(%s,newbook.author); printf(Price:); scanf(%f,&newbook.price); printf(Type:); scanf(%s,newbook.type); printf(Press:); scanf(%s,newbook.press); newbook.isborrowed=0; strcpy(newbook.number,000000000); fwrite(&newbook,sizeof(struct book),1,fp); /*将图书保存到book.in中*/ printf(continue ? (y/n); a=getch(); clrscr(); fprintf(fp,%d,n); printf(Successfully saved!nPress any key to back); fclose(fp); save_books(); getch();函数delete_book实现对图书的删除操作void delete_book() /*删除图书函数*/long int totalbook,i;int done=0;char a=y,ss10;FILE *fp1,*fp2;struct book sbook;clrscr();if(fp1=fopen(book.out,rb)=NULL)printf(wrong!);exit(0);if(fp2=fopen(book1.out,wb)=NULL)printf(wrong!); exit(0); fseek(fp1,-100L,2);fread(&sbook,sizeof(struct book),1,fp1);totalbook=atol(sbook.number); /*获得图书数目*/rewind(fp1);while(a=121)clrscr();printf(Please input the number of the book:);scanf(%s,ss);clrscr();fread(&sbook,sizeof(struct book),1,fp1);fwrite(&sbook,sizeof(struct book),1,fp2);for(i=1;i=totalbook;i+=1)fread(&sbook,sizeof(struct book),1,fp1); /*删除操作*/ if(strcmp(sbook.number,ss)=0) /*将删除过相应图书的数据写入 book1.out*/ done=1; printf(The information of the book:n); printf(Name:%sn,); printf(Author:%sn,sbook.author); printf(Number:%sn,sbook.number); printf(Price:%-9.2fn,sbook.price); printf(Press:%sn,sbook.press); printf(Are you sure to delete the book?(y/n) ; a=getch(); if(a!=121) break; else if(done=0) fwrite(&sbook,sizeof(struct book),1,fp2); else minusone(sbook.number);fwrite(&sbook,sizeof(struct book),1,fp2);fclose(fp1);fclose(fp2);if(done=0) printf(Wrong number!);if(done=1 & a=121) exchange(i,totalbook); clrscr(); printf(Successfully deleted!n);getch();clrscr();printf(Continue ? (y/n);a=getch();remove(book1.out);void exchange(long int i,long int totalbook) /*将book1.out的数据写入book.out中*/FILE *fp1,*fp2;struct book sbook;if(fp1=fopen(book1.out,rb)=NULL)printf(wrong!);exit(0);fp2=fopen(book.out,wb);for(i=1;i=totalbook;i+=1)fread(&sbook,sizeof(struct book),1,fp1); fwrite(&sbook,sizeof(struct book),1,fp2); fclose(fp1); fclose(fp2);函数search_books实现对图书的查找void search_books() /*查找图书函数*/int n,total=0;long int totalbook,i;char item20;char ss=y;FILE *fp;struct book sbook;if(fp=fopen(book.out,rb)=NULL)printf(wrong!);exit(0);fseek(fp,-100L,2);fread(&sbook,sizeof(struct book),1,fp);totalbook=atol(sbook.number);fseek(fp,100L,0);while(ss=121)clrscr();printf(Please select a way to search:n); /*查找方式设置*/printf(1:namen2:authorn3:numbern);n=getch();switch(n)case 49:clrscr();printf(Please input the name of the book:n);scanf(%s,item);clrscr();printf(n);for(i=1;i=totalbook;i+=1)fread(&sbook,sizeof(struct book),1,fp); if(strcmp(,item)=0) /*打印图书信息*/ printf(Book %dn,total+1); printf(Name:%sn,); printf(Author:%sn,sbook.author); printf(Number:%sn,sbook.number); printf(Price:%-9.2fn,sbook.price); printf(Press:%sn,sbook.press); printf(Type:%sn,sbook.type); printf(Isborrowed:%dnn,sbook.isborrowed); total+; continue; gotoxy(1,1);if(total=0) printf(No such book!); /*没有对应图书*/else printf(We find %d books totally:,total);getch();break;case 50:clrscr();printf(Please input the author of the book:n);scanf(%s,item);clrscr();printf(n);for(i=1;i=totalbook;i+=1)fread(&sbook,sizeof(struct book),1,fp); if(strcmp(sbook.author,item)=0) printf(Book %dn,total+1); printf(Name:%sn,); printf(Author:%sn,sbook.author); printf(Number:%sn,sbook.number); printf(Price:%-9.2fn,sbook.price); printf(Press:%sn,sbook.press); printf(Isborrowed:%dnn,sbook.isborrowed); total+; continue; gotoxy(1,1);if(total=0) printf(No such book!);else printf(We find %d books totally:,total);getch();break;case 51:clrscr();printf(Please input the number of the book:n);scanf(%s,item);clrscr();printf(n);for(i=1;i=totalbook;i+=1)fread(&sbook,sizeof(struct book),1,fp); if(strcmp(sbook.number,item)=0) printf(Book %dn,total+1); printf(Name:%sn,); printf(Author:%sn,sbook.author); printf(Number:%sn,sbook.number); printf(Price:%-9.2fn,sbook.price); printf(Press:%sn,sbook.press); printf(Isborrowed:%dnn,sbook.isborrowed); total+; continue; gotoxy(1,1);if(total=0) printf(No such book!);else printf(We find %d books totally:,total);getch();break;total=0;clrscr();printf(continue ? (y/n):n);ss=getch(); fclose(fp);函数br_books实现对图书的借阅和归还void br_books() /*借阅或归还图书函数*/int done=0;char a=y,number10;FILE *fp;long int i,totalbook;struct book sbook;if(fp=fopen(book.out,rb+)=NULL)printf(wrong!);exit(0);fseek(fp,-100L,2);fread(&sbook,sizeof(struct book),1,fp);totalbook=atol(sbook.number);fseek(fp,100L,0);while(a=121)clrscr(); printf(Please input a kind of service:n); printf(1:Borrow a bookn2:Return a bookn); /*选择相应服务*/ a=getch(); if(a=49) clrscr(); printf(Please input the number of the book:); scanf(%s,number); clrscr(); for(i=0;i=totalbook;i+=1) fread(&sbook,sizeof(struct book),1,fp); if(strcmp(sbook.number,number)=0) if(sbook.isborrowed=0) printf(The information of the book:n); printf(Name:%sn,); printf(Author:%sn,sbook.author); printf(Number:%sn,sbook.number); printf(Price:%-9.2fn,sbook.price); printf(Press:%sn,sbook.press); printf(Are you sure to borrow the book?(y/n) ; /*确认操作*/ a=getch(); if(a=121) sbook.isborrowed=1; fseek(fp,-100L,1); fwrite(&sbook,sizeof(struct book),1,fp); fclose(fp); clrscr(); printf(Successfully borrowed!); else printf(This book has been borrowed!); fclose(fp); done=1; break; if(done=0) printf(Wrong number!);fclose(fp); if(a=50) clrscr(); printf(Please input the number of the book:); scanf(%s,number); clrscr(); for(i=0;i=totalbook;i+=1) fread(&sbook,sizeof(struct book),1,fp); if(strcmp(sbook.number,number)=0) if(sbook.isborrowed=1) printf(The information of the book:n); printf(Name:%sn,); printf(Author:%sn,sbook.author); printf(Number:%sn,sbook.number); printf(Price:%-9.2fn,sbook.price); printf(Press:%sn,sbook.press); printf(Are you sure to return the book?(y/n) ; a=getch(); if(a=121) sbook.isborrowed=0; fseek(fp,-100L,1); fwrite(&sbook,sizeof(struct book),1,fp); fclose(fp); clrscr(); printf(Successfully returned!); else printf(This book has not been borrowed!); fclose(fp); done=1; break; if(done=0) printf(Wrong number!);fclose(fp); getch(); clrscr(); printf(ncontinue ?(y/n) n); a=getch(); 函数total_numbers实现图书统计操作void total_numbers()FILE *fp;long int totalbook;long int hasb=0,typs=0,typl=0,i;struct book sbook;clrscr();if(fp=fopen(book.out,rb)=NULL)printf(wrong!);exit(0);fseek(fp,-100L,2);fread(&sbook,sizeof(struct book),1,fp);totalbook=atol(sbook.number);printf(The total number of all books is:%ldn,totalbook);rewind(fp);for(i=1;i=totalbook;i+=1) /*统计图书类型*/fread(&sbook,sizeof(struct book),1,fp); if(strc
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年文教用品行业当前发展趋势与投资机遇洞察报告
- 2025年财务公司行业当前市场规模及未来五到十年发展趋势报告
- 生鲜新零售2025年供应链优化策略与冷链物流成本效益分析与提升实践报告
- 深度研究2025年互联网广告精准投放算法优化与效果提升路径报告
- 2025年四柱单动液压机行业当前发展现状及增长策略研究报告
- 2025年RFID行业当前发展现状及增长策略研究报告
- 2025年民爆行业当前发展趋势与投资机遇洞察报告
- 土建知识培训班课件
- 2025年油气管道工程建设行业当前发展现状及增长策略研究报告
- 民族风人物画课件
- 2023施工技术交底编制与管理标准培训
- 物业管理考核细则-
- GB/T 3683-2023橡胶软管及软管组合件油基或水基流体适用的钢丝编织增强液压型规范
- 义教课程标准(2022年版)解读·徐蓝
- GA/T 954-2011法庭科学工具痕迹中凹陷痕迹的检验规范
- DB1331T004-2022雄安新区数据安全建设导则
- 环水保工程监理细则
- DB11-T1834-2021 城市道路工程施工技术规程高清最新版
- 手工电弧焊焊接头基本形式与尺寸
- 开拓进取:零碳汽车的材料脱碳之路
- (完整版)自我护理能力量表ESCA
评论
0/150
提交评论