C语言图书管理系统课程设计--精选文档_第1页
C语言图书管理系统课程设计--精选文档_第2页
已阅读5页,还剩10页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、题目:图书管理系统要求:能录入新图书;能浏览图书信息;能自主查询图书信息;能修改图书信息;能删除图书信息。程序如下:#include<stdio.h>#include<stdlib.h>#include<string.h>typedef struct char number10;/书号char name20;/书名char author20;/作者char publish50;/出版社char time20;/出版时间float price;mbook;typedef struct int count;/书的本数mbook book100;/最大可有100本

2、书mlibrary;mlibrary library;void save()/保存图书信息。FILE *fp;if(fp=fopen("library.doc","w")=NULL)printf("n不能保存图书信息n");return;fwrite(&library.count,sizeof(int),1,fp);fwrite(library.book,sizeof(library.book0),library.count,fp);void putin() /*定义录入函数*/ int y=1;system("cl

3、s");while(y) printf("t请输入您的书籍的书号:");scanf("%s",library.booklibrary.count.number);printf("t请输入书名:");scanf("%s",);printf("t请输入作者名:");scanf("%s",library.booklibrary.count.author);printf("t请输入出版社:");

4、scanf("%s",library.booklibrary.count.publish);printf("t请输入出版时间:");scanf("%s",library.booklibrary.count.time);printf("t请输入该书的价格:");fflush(stdin);scanf("%f",&library.booklibrary.count.price);library.count+;printf("n是否继续录入(1.继续;0,退出录入):");

5、fflush(stdin);scanf("%d",&y);if (y!=1)y=0;break; save();void lookup()system("cls");printf("图书号t图书名t作者名t出版社t出版日期t图书价格n");for (int i=0;i<library.count;i+)printf("%st%st%st%st%st%6.2fn",library.booki.number,,library.booki.author,library.b

6、ooki.publish,library.booki.time,library.booki.price);fflush(stdin);getchar();void search_by_name() /*定义按书名查询*/ char s220; int flag=1;printf("n请输入要查询的书名: ");fflush(stdin);scanf("%s",s2);printf("图书号t图书名t作者名t出版社t出版日期t图书价格n");for(int i=0;i<library.count;i+ )if(strcmp(s2,

7、)=0) flag=0;printf("%st%st%st%st%st%6.2fn",library.booki.number,,library.booki.author,library.booki.publish,library.booki.time,library.booki.price); if (flag)printf("cannot found!");fflush(stdin);getchar();void search_by_author() /*定义按作者名查询*/ c

8、har s320;int flag=1;printf("请输入要查询的书的作者: ");fflush(stdin);scanf("%s",s3);printf("图书号t图书名t作者名t出版社t出版日期t图书价格n");for(int i=0;i<library.count;i+ )if(strcmp(s3,library.booki.author)=0) flag=0;printf("%st%st%st%st%st%6.2fn",library.booki.number,

9、,library.booki.author,library.booki.publish,library.booki.time,library.booki.price); if (flag)printf("cannot found!");fflush(stdin);getchar();void search() /*定义查询函数*/ int a;system("cls"); /*进行清屏*/ printf("tt*n");printf("开始查询n"); printf("ttt1-search_by_nam

10、en"); printf("ttt2-search_by_writern"); printf("ttt0-exitn"); printf("tt*n") ; printf("tt请选择你想要的查询方式:");fflush(stdin); scanf("%d",&a); switch(a) case 1:search_by_name();break; case 2:search_by_author();break;case 0:return;void del() /*定义删除函数

11、*/ char number10;system("cls"); /*清屏*/printf("n Please type in the number of the book you want to delete:");fflush(stdin);scanf("%s",number);int i;for (i=0;i<library.count;i+)if(strcmp(number,library.booki.number)=0)break;if (i!=library.count)for(;i<library.count-

12、1;i+)strcpy(,library.booki+1.name);strcpy(library.booki.number,library.booki+1.number);strcpy(library.booki.publish,library.booki+1.publish);strcpy(library.booki.author,library.booki+1.author);strcpy(library.booki.time,library.booki+1.time);library.booki.price=library.booki+1.price

13、;library.count-;elseprintf("n cannot found!n");save();fflush(stdin);getchar();void update()/修改图书信息char number10;system("cls"); /*清屏*/printf("n Please type in the number of the book you want to delete:");fflush(stdin);scanf("%s",number);int i;for (i=0;i<libr

14、ary.count;i+) if(strcmp(number,library.booki.number)=0) printf("图书号t图书名t作者名t出版社t出版日期t图书价格n"); printf("%st%st%st%st%st%6.2fn",library.booki.number,,library.booki.author,library.booki.publish,library.booki.time,library.booki.price); break; if (i!=library.count)mbo

15、ok book;printf("ntt请输入修改后此图书的信息n");printf("t请输入图书号:");scanf("%s",book.number);printf("t请输入图书名:");scanf("%s",);printf("t请输入作者名:");scanf("%s",book.author);printf("t请输入出版社:");scanf("%s",book.publish);prin

16、tf("t请输入出版时间:");scanf("%s",book.time);printf("t请输入该书的价格:");fflush(stdin);scanf("%f",&book.price);strcpy(,);strcpy(library.booki.number,book.number);strcpy(library.booki.publish,book.publish);strcpy(library.booki.author,book.autho

17、r);strcpy(library.booki.time,book.time);library.booki.price=book.price;save();elseprintf("n cannot found!n");fflush(stdin);getchar();void main()FILE *fp;if(fp=fopen("library.doc","r")=NULL)printf("n不能打开图书信息库n");fp=fopen("library.doc","w+");

18、printf("n初始化图书信息库,初始化之后要重启程序n");library.count=0;fwrite(&library.count,sizeof(int),1,fp);fclose(fp);return;fread(&library.count,sizeof(int),1,fp);fread(library.book,sizeof(library.book0),library.count,fp);fclose(fp);int a; do system("cls");printf("nnnnntttt图书信息管理系统ttttn");printf("tt*n");printf("ttt1 -图书信息录入n");printf("ttt2 -图书信息浏览n"); printf("ttt3 -图书信息查询n");printf("ttt4 -图书信息删除n");printf("ttt5 -图书信息修改n");printf("ttt0 -退出图书信息系统n");printf("tt*n");

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论