栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

C语言实现图书管理系统

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

C语言实现图书管理系统

本文实例为大家分享了C语言实现图书管理系统的具体代码,供大家参考,具体内容如下

一、分析过程

首先此程序需要实现输入、增加、删除、查询、输出的五大功能,则首先需要设置一个菜单键,让用户可以选择不同的功能,完成不同的操作,然后编写不同的函数实现不同的功能,在这个过程中注意要人性化,让用户方便,直观的进行操作。

二、算法

三、函数模块介绍

 1录入模块:本模块主要执行信息的录入功能

 2浏览模块:本模块主要是执行把已有信息输出浏览功能

 3查询模块:本模块主要是按照图书名查找图书的相关信息

 4删除模块:主要是执行删除图书信息的功能

 5退出模块:方便用户离开

四、源程序

#include 
#include 
#include 
#include 
 
 
struct books_list 
{ 
 
 char author[20];  
 char bookname[20];  
 char publisher[20];  
 char pbtime[15];  
 char loginnum[10];  
 float price;   
 char classfy[10];  
 struct books_list * next;  
}; 
 
struct books_list * Create_Books_Doc();  
void InsertDoc(struct books_list * head);  
void DeleteDoc(struct books_list * head , int num); 
void Print_Book_Doc(struct books_list * head); 
void search_book(struct books_list * head);  
void save(struct books_list * head); 
 
 
struct books_list * Create_Books_Doc() 
{ 
 struct books_list * head; 
 head=(struct books_list *)malloc(sizeof(struct books_list));  
 head->next=NULL;  
 return head; 
} 
 
 
void save(struct books_list * head) 
{ 
 struct books_list *p; 
 FILE *fp; 
 p=head; 
 fp=fopen("data.txt","w+");  
 fprintf(fp,"┏━━━┳━━━━━┳━━━━━┳━━━━━┳━━━━━━┳━━━┳━━━━┓n");  
 fprintf(fp,"┃登录号┃ 书 名 ┃ 作 者┃ 出版单位 ┃ 出版时间 ┃分类号┃ 价格 ┃n"); 
 fprintf(fp,"┣━━━╋━━━━━╋━━━━━╋━━━━━╋━━━━━━╋━━━╋━━━━┫n"); 
  
 while(p->next!= NULL) 
 { 
 p=p->next; 
 fprintf(fp,"┃%-6.6s┃%-10.10s┃%-10.10s┃%-10.10s┃%-12.12s┃%-6.6s┃%.2f ┃n",p->loginnum,p->bookname,p->author,p->publisher,p->pbtime,p->classfy,p->price); 
 } 
 fprintf(fp,"┗━━━┻━━━━━┻━━━━━┻━━━━━┻━━━━━━┻━━━┻━━━━┛n"); 
 fclose(fp); 
 printf("  已将图书数据保存到 data.txt 文件n"); 
} 
 
 
void InsertDoc(struct books_list *head) 
{ 
  
 struct books_list *s, *p; 
 char flag='Y';  
 p=head; 
  
 while(p->next!= NULL) 
 { 
 p=p->next; 
 } 
  
 while(flag=='Y'||flag=='y') 
 { 
 s=(struct books_list *)malloc(sizeof(struct books_list)); 
 printf("n  请输入图书登陆号:"); 
 fflush(stdin); 
 scanf("%s",s->loginnum); 
 printf("n  请输入图书书名:"); 
 fflush(stdin); 
 scanf("%s",s->bookname); 
 printf("n  请输入图书作者名:"); 
 fflush(stdin); 
 scanf("%s",s->author); 
 printf("n  请输入图书出版社:"); 
 fflush(stdin); 
 scanf("%s",s->publisher); 
 printf("n  请输入图书出版时间:"); 
 fflush(stdin); 
 scanf("%s",s->pbtime); 
 printf("n  请输入图书分类号:"); 
 fflush(stdin); 
 scanf("%s",s->classfy); 
 printf("n  请输入图书价格:"); 
 fflush(stdin); 
 scanf("%f",&s->price); 
 printf("n"); 
 p->next=s;  
 p=s;  
 s->next=NULL; 
 printf("  ━━━━ 添加成功!━━━━"); 
 printf("n  继续添加?(Y/N):"); 
 fflush(stdin); 
 scanf("%c",&flag); 
 printf("n"); 
 if(flag=='N'||flag=='n') 
 {break;} 
 else if(flag=='Y'||flag=='y') 
 {continue;} 
 } 
 save(head);  
 return; 
} 
 
 
 
void search_book(struct books_list *head) 
{ 
 struct books_list * p; 
 char temp[20]; 
 p=head; 
 if(head==NULL || head->next==NULL)  
 { 
 printf(" ━━━━ 图书库为空!━━━━n"); 
 } 
 else 
 { 
 printf("请输入您要查找的书名: "); 
 fflush(stdin); 
 scanf("%s",temp); 
  
 while(p->next!= NULL) 
 { 
 p=p->next; 
 if(strcmp(p->bookname,temp)==0) 
 { 
 printf("n图书已找到!n"); 
 printf("n"); 
 printf("登录号: %stn",p->loginnum); 
 printf("书名: %stn",p->bookname); 
 printf("作者名: %stn",p->author); 
 printf("出版单位: %stn",p->publisher); 
 printf("出版时间: %stn",p->pbtime); 
 printf("分类号: %stn",p->classfy); 
 printf("价格: %.2ftn",p->price); 
 } 
 if(p->next==NULL) 
 { 
 printf("n查询完毕!n"); 
 } 
 } 
 } 
 return; 
} 
 
  
 
void Print_Book_Doc(struct books_list * head) 
{ 
 struct books_list * p; 
 if(head==NULL || head->next==NULL)  
 { 
 printf("n  ━━━━ 没有图书记录! ━━━━nn"); 
 return; 
 } 
 p=head; 
 printf("┏━━━┳━━━━━┳━━━━━┳━━━━━┳━━━━━━┳━━━┳━━━━┓n"); 
 printf("┃登录号┃ 书 名 ┃ 作 者┃ 出版单位 ┃ 出版时间 ┃分类号┃ 价格 ┃n"); 
 printf("┣━━━╋━━━━━╋━━━━━╋━━━━━╋━━━━━━╋━━━╋━━━━┫n"); 
  
 while(p->next!= NULL) 
 { 
 p=p->next; 
 printf("┃%-6.6s┃%-10.10s┃%-10.10s┃%-10.10s┃%-12.12s┃%-6.6s┃%.2f ┃n",p->loginnum,p->bookname,p->author,p->publisher,p->pbtime,p->classfy,p->price);  
 } 
 printf("┗━━━┻━━━━━┻━━━━━┻━━━━━┻━━━━━━┻━━━┻━━━━┛n"); 
 printf("n"); 
} 
 
 
void DeleteDoc(struct books_list * head) 
{ 
 struct books_list *s,*p;  
 char temp[20]; 
 int panduan;  
 panduan=0; 
 p=s=head; 
 printf("  [请输入您要删除的书名]:"); 
 scanf("%s",temp); 
  
 while(p!= NULL) 
 { 
 if(strcmp(p->bookname,temp)==0) 
 { 
 panduan++; 
 break; 
 } 
 p=p->next; 
 } 
 if(panduan==1) 
 { 
 for(;s->next!=p;)  
 { 
 s=s->next; 
 } 
 s->next=p->next;  
 free(p); 
 printf("n  ━━━━ 删除成功! ━━━━n"); 
 } 
 else  
 { 
 printf("  您输入的书目不存在,请确认后输入!n"); 
 } 
 return; 
} 
 
int main() 
{ 
 struct books_list * head; 
 char choice; 
 head=NULL; 
 for(;;)  
 { 
 printf(" ┏━┓━━━━━━━━━━━━━━━━━━━┏━┓n"); 
 printf(" ┃ ┃ tony 图书馆管理系统 ┃ ┃n"); 
 printf(" ┃ ┗━━━━━━━━━━━━━━━━━━━┛ ┃n"); 
 printf(" ┃ [1]图书信息录入 ┃n"); 
 printf(" ┃   ┃n"); 
 printf(" ┃ [2]图书信息浏览 ┃n"); 
 printf(" ┃   ┃n"); 
 printf(" ┃ [3]图书信息查询 ┃n"); 
 printf(" ┃   ┃n"); 
 printf(" ┃ [4]图书信息删除 ┃n"); 
 printf(" ┃   ┃n"); 
 printf(" ┃ [5]退出系统  ┃n"); 
 printf(" ┃   ┃n"); 
 printf(" ┃   ┃n"); 
 printf(" ┗━━━━━━━━━━━━━━━━━━━━━━━┛n"); 
 printf("  请选择:"); 
 fflush(stdin); 
 scanf("%c",&choice); 
 if(choice=='1') 
 { 
 if(head==NULL) 
 { 
 head=Create_Books_Doc(); 
 } 
 InsertDoc(head); 
 
 } 
 else if(choice=='2') 
 { 
 Print_Book_Doc(head); 
 } 
 else if(choice=='3') 
 { 
 search_book(head); 
 } 
 else if(choice=='4') 
 { 
 DeleteDoc(head); 
 } 
 
 else if(choice=='5') 
 { 
 printf("n"); 
 printf(" ━━━━━━━━ 感谢使用图书管理系统 ━━━━━━━━n"); 
 break; 
 } 
 else 
 { 
 printf("  ━━━━ 输入错误,请重新输入!━━━━n"); 
 
 } 
 } 
 
 return 0; 
} 

五、课程设计总结

通过这一周的课程设计,我感受到做程序一定要有自己的清晰计划,否则会无处用力,感觉会很乱,当高屋建瓴的有计划后,然后开始认真严谨的设计每一个模块,要知道用户的一切输入都是不可信的,必须想得要全面,要仔细的对待每一个细节,任何一个差错都有可能让程序崩溃,这其中有许多的困难,刚开始感觉到束手无策,但是放一放,换个角度想就会豁然开朗,我觉得从这个中感觉到了充实,满足感,也提醒我以后要多多练练,多上机,积累经验,争取设计出更多的好的程序。

更多学习资料请关注专题《管理系统开发》。

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持考高分网。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/63026.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号