数据结构课程设计图书馆管理系统(图书馆管理系统 数据结构课程设计 c语言)

2024-04-09 11:10:07 :56

数据结构课程设计图书馆管理系统(图书馆管理系统 数据结构课程设计 c语言)

大家好,如果您还对数据结构课程设计图书馆管理系统不太了解,没有关系,今天就由本站为大家分享数据结构课程设计图书馆管理系统的知识,包括图书馆管理系统 数据结构课程设计 c语言的问题都会给大家分析到,还望可以解决大家的问题,下面我们就开始吧!

本文目录

图书馆管理系统 数据结构课程设计 c语言

#include《stdio.h》#include《math.h》#include《string.h》#include《stdlib.h》struct books_list{ char author; /*作者名*/ char bookname; /*书名*/ char publisher; /*出版单位*/ char pbtime; /*出版时间*/ char loginnum; /*登陆号*/ float price; /*价格*/ char classfy; /*分类号*/ 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 info_change(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+"); /*以写方式新建并打开 data.txt文件*/ 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){ /*定义结构体指针变量 s指向开辟的新结点首地址 p为中间变量*/ struct books_list *s, *p; char flag=’Y’; /*定义flag,方便用户选择重复输入*/ p=head; /*遍历到尾结点,p指向尾结点*/ 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; /*p指向尾节点,向后移*/ 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; 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("登录号: %s\t\n",p-》loginnum); printf("书名: %s\t\n",p-》bookname); printf("作者名: %s\t\n",p-》author); printf("出版单位: %s\t\n",p-》publisher); printf("出版时间: %s\t\n",p-》pbtime); printf("分类号: %s\t\n",p-》classfy); printf("价格: %.2f\t\n",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 ━━━━ 没有图书记录! ━━━━\n\n"); 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 info_change(struct books_list * head){ struct books_list * p; int panduan=0; /*此变量用于判断是否找到书目*/ char temp; p=head; printf("请输入要修改的书名:"); scanf("%s",temp); while(p-》next!= NULL) { p=p-》next; if(strcmp(p-》bookname,temp)==0) { printf("\n 请输入图书登陆卡号:"); fflush(stdin); scanf("%s",p-》loginnum); printf("\n 请输入图书书名:"); fflush(stdin); scanf("%s",p-》bookname); printf("\n 请输入图书作者名:"); fflush(stdin); scanf("%s",p-》author); printf("\n 请输入图书出版社:"); fflush(stdin); scanf("%s",p-》publisher); printf("\n 请输入图书出版时间:"); fflush(stdin); scanf("%s",p-》pbtime); printf("\n 请输入图书分类号:"); fflush(stdin); scanf("%s",p-》classfy); printf("\n 请输入图书价格:"); fflush(stdin); scanf("%f",&p-》price); printf("\n"); panduan=1; } } if(panduan==0) { printf("\n ━━━━ 没有图书记录! ━━━━\n\n"); } return;}/*删除操作*/void DeleteDoc(struct books_list * head){ struct books_list *s,*p; /*s为中间变量,p为遍历时使用的指针*/ char temp; 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(void){ struct books_list * head; char choice; head=NULL; for(;;) /*实现反复输入选择*/ { printf(" ┏━┓━━━━━━━━━━━━━━━━━━━┏━┓\n"); printf(" ┃ ┃ socat 图书管理系统 ┃ ┃\n"); printf(" ┃ ┗━━━━━━━━━━━━━━━━━━━┛ ┃\n"); printf(" ┃ ●图书信息录入 ┃\n"); printf(" ┃ ┃\n"); printf(" ┃ ●图书信息浏览 ┃\n"); printf(" ┃ ┃\n"); printf(" ┃ ●图书信息查询 ┃\n"); printf(" ┃ ┃\n"); printf(" ┃ ●图书信息修改 ┃\n"); printf(" ┃ ┃\n"); printf(" ┃ ●图书信息删除 ┃\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’) { info_change(head); } else if(choice==’5’) { DeleteDoc(head); } else if(choice==’6’) { printf("\n"); printf(" ━━━━━━━━ 感谢使用图书管理系统 ━━━━━━━━\n"); break; } else { printf(" ━━━━ 输入错误,请重新输入!━━━━"); break; } } return 0; }

用C语言写个图书馆系统

下面可以参考参考!完整的C语言图书管理系统#include 《stdlib.h》#include 《stdio.h》#include 《conio.h》#include "graphics.h"#include "math.h"#define m 1 struct data { int year; int month; int day; };struct ReaderNode { char num; struct data bro; struct data back; };struct BookNode { char title; char writer; int currentnum; int totalnum; char brief; struct ReaderNode reader; };struct TreeNode { int n; struct TreeNode *prt; int key; struct BookNode *rec; struct TreeNode *link; };struct BookNode *InputNode();struct TreeNode *mbsearch(struct TreeNode *bth,int x,int *k,int *flag);struct TreeNode *mbinsert(struct TreeNode *bth);struct TreeNode *mbdel(struct TreeNode *bth);void OutputNode(struct TreeNode *bth);void borrow(struct TreeNode *bth);void payback(struct TreeNode *bth);char menu(void);struct TreeNode *mbsearch(struct TreeNode *bth,int x,int *k,int *flag){ struct TreeNode *p,*q; p=bth; *flag=0; q=p; while( (p!=NULL) && (*flag==0) ) { *k=1;q=p; while( (*k 《 q-》n) && ( q-》key 《 x) ) *k=*k+1; if( q-》key==x) *flag=1; else if( ( *k==q-》n ) && ( q-》key;p-》prt=q;} else { p=q-》link; p-》prt=q;*k=*k-1;} } return(q);}struct TreeNode *mbinsert(struct TreeNode *bth){ int flag,j,k,t; int y,x,z; struct TreeNode *p,*q,*u,*s; struct BookNode *r,*l; clrscr(); printf("\n\tPlease input the book you want to insert: "); scanf("%d",&x); q=mbsearch(bth,x,&k,&flag); if(flag==1) { printf("\n\tHas %d this kind of book,do you want to add another?(y/n)\n",(q-》rec)-》totalnum); z=getch(); if(z==’y’||z==’Y’) { (q-》rec)-》currentnum++; printf("\n\tNow total has %d this kind of book,",(q-》rec)-》totalnum); printf("\n\tand current has %d in the library.",(q-》rec)-》currentnum); } return(bth); } r=InputNode(bth); if(bth==NULL) { bth=p=(struct TreeNode *)malloc(sizeof(struct TreeNode)); p-》n=1; p-》key=r;p-》prt=NULL; for(j=1;j《=2*m+1;j++) p-》link=NULL; return(p); } p=NULL; t=0; while(t==0) { if(k==q-》n) {y=x;l=r;u=p;} else { y=q-》key; for(j=(q-》n)-1; j》=k+1; j--) { q-》key; } q-》key=p; if(p!=NULL) p-》prt=q; } if(q-》n《2*m) { q-》n=(q-》n)+1; t=1; q-》key=u; if(u!=NULL) u-》prt=q; } else { p=(struct TreeNode *)malloc(sizeof(struct TreeNode)); p-》n=m; q-》n=m; p-》prt=q-》prt; x=q-》key; for(j=1;j《=m-1;j++) { p-》key; if(q-》link)-》prt=p; } p-》link; p-》link=u; p-》key=y; p-》rec=l; if(u!=NULL) u-》prt=p; for(j=m+2;j《=2*m+1;j++) { q-》link=NULL; } if(q-》prt==NULL) { s=(struct TreeNode *)malloc(sizeof(struct TreeNode)); s-》key=r; s-》link=p; s-》n=1; s-》prt=NULL; q-》prt=s; p-》prt=s; for(j=3;j《=2*m+1;j++) s-》link=NULL; bth=s; t=1; } else { q=q-》prt; k=1; while((k《=q-》n)&&(q-》key《x)) k=k+1; k=k-1; } } } return(bth); }struct TreeNode *mbdel(struct TreeNode *bth){ int flag,j,k,t; int x,y; struct TreeNode *u,*s,*p,*q; struct BookNode *r,*l; clrscr(); printf("\n\tPlease input the book you want to delete: "); scanf("%d",&x); q=mbsearch(bth,x,&k,&flag); if(flag==0) { printf("\n\tThe book is not exist!\n"); return(bth);} p=q-》link; if(p!=NULL) { while(p-》link; q-》key; q-》rec; k=1;q=p; } for(j=k;j《=q-》n-1;j++) { q-》key; q-》rec; } q-》n=q-》n-1; while ((q!=bth)&&(q-》n《m)) { p=q-》prt;j=1; while(p-》link!=q) j=j+1; if((j《=p-》n)&&((p-》link)-》n》m)) { s=p-》link; y=s-》key; l=s-》rec; u=s-》link; for(k=1;k《=s-》n-1;k++) { s-》key; s-》rec; s-》link; } s-》link; s-》link=NULL; s-》n=s-》n-1; q-》n=q-》n+1; q-》key; q-》rec; q-》link=u; p-》key=y; p-》rec=l; if(u!=NULL) u-》prt=q; } else if((j》1)&&((p-》link)-》n》m)) { s=p-》link; q-》n=q-》n+1; q-》link; for(k=q-》n-1;k》=1;k--) { q-》key; q-》rec; q-》link; } q-》key; q-》rec; u=s-》link; q-》link=u; if(u!=NULL) u-》prt=q; p-》key; p-》rec; s-》link=NULL; s-》n=s-》n-1; } else { if(j==p-》n+1) { q=p-》link; j=j-1;} else s=p-》link; q-》key; q-》rec; t=q-》n+1; for(k=1;k《=s-》n;k++) { q-》key; q-》rec; u=s-》link; q-》link=u; if(u!=NULL) u-》prt=q; } u=s-》link=u; if(u!=NULL) u-》prt=q; q-》n=2*m; free(s); for(k=j;k《=p-》n-1;k++) { p-》key; p-》rec; p-》link; } p-》n=p-》n-1; s=q; q=p; } } if((q==bth)&&(q-》n==0)) { free(bth); bth=s; bth-》prt=NULL; if(s-》n==0) {bth=NULL; free(s); } } printf("\n\tThe book has been delete !"); return(bth);}struct BookNode *InputNode(){ struct BookNode *p; int i; p=(struct BookNode *)malloc(sizeof(struct BookNode)); clrscr(); fflush(stdin); printf("\n\tInput the title: "); gets(p-》title); printf("\n\tInput the writer: "); gets(p-》writer); printf("\n\tInput the book current amount: "); scanf("%d",&p-》currentnum); printf("\n\tInput the book total amount: "); scanf("%d",&p-》totalnum); fflush(stdin); printf("\n\tInput the book brief instruction: "); gets(p-》brief); for(i=0;i《20;i++) (p-》reader=’\0’; return(p); }void OutputNode(struct TreeNode *bth){ struct TreeNode *q; struct BookNode *p; int k; int x; int flag; clrscr(); printf("\n\tPlease input the book you want to search: "); scanf("%d",&x); q=mbsearch(bth,x,&k,&flag); if(flag==1) { p=q-》rec; printf("\n\tTitle: %s",p-》title); printf("\n\tWriter: %s",p-》writer); printf("\n\tCurrentAmount: %d",p-》currentnum); printf("\n\tTotalAmount: %d",p-》totalnum); printf("\n\tBriefIntroduction: %s\n",p-》brief); } else printf("\n\tThis book is not exist!");}void borrow(struct TreeNode *bth){ struct TreeNode *q; struct BookNode *p; struct ReaderNode *r; int i,k, x, flag,t; clrscr(); printf("\n\tPlease input the book you want to borrow: "); scanf("%d",&x); q=mbsearch(bth,x,&k,&flag); if(flag==1) { p=q-》rec; printf("\n\tDo you want this book ?(y/n)"); printf("\n\tTitle: %s",p-》title); printf("\n\tWriter: %s",p-》writer); printf("\n\tCurrentAmount: %d",p-》currentnum); printf("\n\tTotalAmount: %d",p-》totalnum); printf("\n\tBriefIntroduction: %s",p-》brief); t=getch(); if(t==’y’||t==’Y’) { if( (p-》currentnum)==0) printf("\n\tSorry,this book has all borrow out..."); else { clrscr(); for(i=0;i《20;i++) if( (p-》reader==’\0’) break; printf("\n\tPlease input your certificate number: "); scanf("%s",(p-》reader).num); printf("\n\tPlease input the borrow data: "); printf("\n\tYear: "); scanf("%d",&((p-》reader).bro.year)); printf("\tMonth: "); scanf("%d",&((p-》reader).bro.month)); printf("\tDay: "); scanf("%d",&((p-》reader).bro.day)); printf("\n\tPlease input the payback data: "); printf("\n\tYear: "); scanf("%d",&((p-》reader).back.year)); printf("\tMonth: "); scanf("%d",&((p-》reader).back.month)); printf("\tDay: "); scanf("%d",&((p-》reader).back.day)); p-》currentnum--; printf("\n\tYou have borrow the book.");} } } else printf("\n\tThis book is not exist!"); }void payback(struct TreeNode *bth){ struct TreeNode *q; struct BookNode *p; int i,k, x, flag,t,j; int year,month,day,d; float pay; char temp; clrscr(); printf("\n\tPlease input the book you want to payback: "); scanf("%d",&x); q=mbsearch(bth,x,&k,&flag); if(flag==1) { p=q-》rec; printf("\n\tDo you want to payback this book ?(y/n)"); printf("\n\tTitle: %s",p-》title); printf("\n\tWriter: %s",p-》writer); printf("\n\tCurrentAmount: %d",p-》currentnum); printf("\n\tTotalAmount: %d",p-》totalnum); printf("\n\tBriefIntroduction: %s",p-》brief); t=getch(); if(t==’y’||t==’Y’) { if( (p-》currentnum) 》=(p-》totalnum) ) printf("\n\tYou want to offer a more book ??\n"); else { clrscr(); printf("\n\tPlease input your certificate number: "); scanf("%s",temp); j=0; for(i=0;i《20;i++) { if(! (strcmp(temp,(p-》reader).num))) {j=1;break;} } if(j==0) {printf("\n\tYou haven’t borrow this book.");return;} printf("\n\tToday is:"); printf("\n\tYear: "); scanf("%d",&year); printf("\tMonth: "); scanf("%d",&month); printf("\tDay: "); scanf("%d",&day);d=0; if(year《(p-》reader).back.year) d=1; if(year《=(p-》reader).back.month) d=1; if(year《=(p-》reader).back.day) d=1; if(d==0) { clrscr(); pay=(year-(p-》reader).back.day); printf("\n\tYou borrow this book is in %d-%d-%d",(p-》reader).bro.day); printf("\n\tYou should pay it back in %d-%d-%d",(p-》reader).back.day); printf("\n\tToday is %d-%d-%d",year,month,day); printf("\n\n\tSo you have go out the payback day"); printf("\n\tYou have to pay %2.1f Yuan.",0.1*pay); } (p-》reader=’\0’; p-》currentnum++; printf("\n\tYou have payback the book."); } } } else printf("\n\tYou want to payback an inexistence book ???"); }donghua(){int graphdriver=VGA;int graphmode=VGAHI;int i,j;registerbgidriver(EGAVGA_driver);initgraph(&graphdriver,&graphmode,"");clrscr();for(i=0;i《=150;i+=5) {setcolor(i); textbackground(RED); settextstyle(0,0,2); outtextxy(100,i+140,"Liberary management System"); delay(10000000); clrscr(); }setcolor(RED);outtextxy(50,200,"Loading");delay(100000000000);outtextxy(50,200,"Loading.");delay(100000000000);outtextxy(50,200,"Loading..");delay(100000000000);outtextxy(50,200,"Loading...");delay(100000000000);outtextxy(50,200,"Loading....");delay(100000000000);outtextxy(50,200,"Loading.....");delay(100000000000);outtextxy(50,200,"Loading......");delay(100000000000);outtextxy(50,200,"Loading.......");delay(100000000000);outtextxy(50,200,"Loading........");delay(100000000000);outtextxy(50,200,"Loading.........");delay(100000000000);outtextxy(50,200,"Loading..........");delay(100000000000);outtextxy(50,200,"Loading...........");outtextxy(50,200,"Loading............");delay(100000000000);for(i=0;i《=10;i++)delay(100000000000);clrscr();}char menu(void){ clrscr(); window(1,1,80,25); textmode(MONO); textbackground(BLACK); textcolor(5); printf("\n\t ****************************************************"); printf("\n\t ***** Welcome to Liberary management System *****"); printf("\n\t ****************************************************"); printf("\n\t ****************************************************"); printf("\n\t *1.Add a book *"); printf("\n\t ****************************************************"); printf("\n\t *2.Delete a book *"); printf("\n\t ****************************************************"); printf("\n\t *3.Search a book *"); printf("\n\t ****************************************************"); printf("\n\t *4.Borrow a book *"); printf("\n\t ****************************************************"); printf("\n\t *5.Payback a book *"); printf("\n\t ****************************************************"); printf("\n\t *0.exit *"); printf("\n\t ****************************************************"); printf("\n\t please select: "); return getch();}bofangdonghua(){int graphdriver=VGA;int graphmode=VGAHI;int i,j;char c;registerbgidriver(EGAVGA_driver);initgraph(&graphdriver,&graphmode,"");/*************shi fou bo fang dong hua?**************/printf:{setcolor(RED); settextstyle(3,0,5); outtextxy(100,30,"bo fang dong hua?"); outtextxy(150,80,"Yes"); outtextxy(300,80,"No");c=getch(); if(c==’Y’||c==’y’) {donghua(); menu(); } elseif(c==’N’||c==’n’) menu();else {setcolor(GREEN); settextstyle(3,0,8); outtextxy(200,240,"Error!"); delay(10000000000); clrscr(); goto printf; }}/**************************************/}void main(){ char c,t; int x; int k,flag,p=1; struct TreeNode *bth=NULL; bofangdonghua();while(1) { c=menu(); putch(c); getch(); switch(c) { case ’1’: bth=mbinsert(bth); break; case ’2’: bth=mbdel(bth); break; case ’3’: OutputNode(bth); break; case ’4’: borrow(bth); break; case ’5’: payback(bth); break; case ’0’: clrscr(); printf("\n\tDo you want to return ?(y/n)"); t=getch(); if(t==’y’||t==’Y’) exit(0); break; defult :break; } printf("\n\tPress any key to the main menu...."); getch();}}

用数据结构编一个图书管理系统

#include《stdio.h》 #include《string.h》 #include《conio.h》 #include《stdlib.h》 #define N sizeof(struct book)#define PT "%-5d %10s %6s %6s %8s %3d \n",p-》num,p-》name,p-》where,p-》author,p-》pub,p-》countstruct book /*图书信息*/{ int num; /*书号*/ char name; /*书名*/ char where; /*所在书库*/ char author; /*作者*/ char pub; /*出版社*/ int count; /*数量*/ struct book *next;};/*输出模块*/void print(struct book *p0){ struct book *p; p=p0-》next; printf("\n\n\t\t^^^^^^^^^^^^^^图书信息表^^^^^^^^^^^^^^"); printf("\n\n图书编号---图书名称---所在书库----作者----出版社---数量\n"); while(p!=NULL) { printf(PT); p=p-》next; } getch();}/*输入模块*/struct book *creat() { struct book *head,*p1,*p2; int i=0; head=p2=(struct book *)malloc(N); head-》next=NULL; printf("\n\n\t\t录入图书信息"); printf("\n\t---------------------------------------"); while(1) { p1=(struct book *)malloc(N); printf("\n 请输入图书编号(书号为0结束): "); scanf("%d",&p1-》num); if(p1-》num!=0) { printf("\n\n书名 所在书库 作者 出版社 图书数量\n"); scanf("%s%s%s%s%d",p1-》name,p1-》where,p1-》author,p1-》pub,&p1-》count); p2-》next=p1; p2=p1; i++; } else break; } p2-》next=NULL; free(p1); printf("\n\t\t----------------------------------------"); printf("\n\t\t %d 种书录入完毕",i); getch(); return head;}/*查找模块*/void find(struct book *p0){ char name; int flag=1; struct book *p; p=p0-》next; printf("请输入要查找的书名:\n"); scanf("%s",name); for(p=p0;p;p=p-》next) if(strcmp(p-》name,name)==0) { printf("\n\n图书编号---图书名称---所在书库----作者----出版社---数量\n"); printf(PT); flag=0; break; } if(flag) printf("\n 暂无此图书信息\n"); getch();}/*删除模块*/void del(struct book *p0){ char name; int flag=1; struct book *p; p=p0; printf("请输入要删除的书名:\n"); scanf("%s",name); while(p!=NULL) { if(strcmp(p-》name,name)==0) { p0-》next=p-》next; /*后续节点连接到前驱节点之后*/ free(p); printf("\t该书资料已删除."); flag=0; break; } p0=p; p=p-》next; } if(flag) printf("\n\t无此图书信息。"); getch();}/*增加模块*/void insert(struct book *p0){ struct book *p; p=(struct book *)malloc(N); while(1) { printf("\n 请输入要增加的图书编号(书号为0 退出): "); scanf("%d",&p-》num); if(p-》num!=0) { if(p0-》next!=NULL&&p0-》next-》num==p-》num) /*找到重号*/ { p=p-》next; free(p); printf("\t该书已存在"); } else {printf("\n\n书名 所在书库 作者 出版社 图书数量\n"); scanf("%s%s%s%s%d",p-》name,p-》where,p-》author,p-》pub,&p-》count); p-》next=p0-》next; p0-》next=p; printf("\t已成功插入."); } } else break; } getch();}/*修改模块*/void modify(struct book *p0){ char name; int flag=1; int choice; struct book *p; p=p0-》next; printf("请输入要修改的书名:\n"); scanf("%s",name); while(p!=NULL&&flag==1) { if(strcmp(p-》name,name)==0) { printf("\n\t请选择要修改的项:"); printf("\n\t 1.修改图书编号\n"); printf("\n\t 2.修改图书所在书库\n"); printf("\n\t 3.修改图书作者\n"); printf("\n\t 4.修改图书出版社\n"); printf("\n\t 5.修改图书库存量\n"); scanf("%d",&choice); switch(choice) { case 1: { printf("\n 请输入新的图书编号:"); scanf("%d",p-》num); break; } case 2: { printf("\n 请输入新的图书书库:"); scanf("%s",p-》where); break; } case 3: { printf("\n 请输入新的图书作者:"); scanf("%s",p-》author); break; } case 4: {printf("\n 请输入新的图书出版社:"); scanf("%s",p-》pub); break; } case 5: {printf("\n 请输入新的图书库存量:"); scanf("%d",p-》count); break; } } printf("\n\t该项已成功修改。\n\t 新的图书信息:"); printf("\n\n图书编号---图书名称---所在书库----作者----出版社---数量\n"); printf(PT); flag=0; } p0=p; p=p0-》next; } if(flag) printf("\n\t暂无此图书信息。"); getch();}/*读文件*/struct book *read_file() { int i=0; struct book *p,*p1,*head=NULL; FILE *fp; if((fp=fopen("library.txt","rb"))==NULL) {printf("\n\n\n\n\n \t********库文件不存在,请创建!**********"); getch(); return NULL; } head=(struct book *)malloc(N); p1=head; head-》next=NULL; printf("\n 已有图书信息:"); printf("\n\n图书编号---图书名称---所在书库----作者----出版社---数量\n"); while(!feof(fp)) { p=(struct book *)malloc(N); /*开辟空间以存放的取得信息*/ while(fscanf(fp,"%d%s%s%s%s%d",&p-》num,p-》name,p-》where,p-》author,p-》pub,&p-》count)!=EOF) { printf(PT); i++; } p1-》next=p; p1=p; } p1-》next=NULL; fclose(fp); printf("\n 共种%d 图书信息",i); printf("\n\n\n 文件中的信息以正确读出。按任意键进入主菜单。"); getch(); return (head); }/*保存文件*/void save(struct book *head) { FILE *fp; struct book *p; fp=fopen("library.txt","wb"); /*以只写方式打开二进制文件*/ if(fp==NULL) /*打开文件失败*/ { printf("\n=====》打开文件失败!\n"); getch(); return ; } else for(p=head-》next;p!=NULL;p=p-》next) fprintf(fp,"%d %s %s %s %s %d\n",p-》num,p-》name,p-》where,p-》author,p-》pub,p-》count); fclose(fp); printf("\n\t保存文件成功!\n");}void main(){ struct book *head=NULL; int choice=1; head=read_file(); if(head==NULL) { printf("\n\t\t**********"); getch(); head=creat(); } do { system("cls"); printf("\t\t----------Welcome---------\n"); printf("\n\n\t欢迎您,图书管理员.\n"); printf("\n\n\n\n\n"); printf("\n\t 请选择:"); printf("\n\t 1.查询图书信息\n"); printf("\n\t 2.修改图书信息\n"); printf("\n\t 3.增加图书信息\n"); printf("\n\t 4.删除图书信息\n"); printf("\n\t 5.显示所有图书信息\n"); printf("\n\t 0.退出系统\n"); scanf("%d",&choice); switch(choice) { case 1: find(head); break; case 2: modify(head); break; case 3: insert(head); break; case 4: del(head); break; case 5: print(head); break; case 0: system("cls"); printf("\n\n\n\n\n\t^^^^^^^^^^谢谢使用,再见^^^^^^^^^^!\n\n"); break; } }while(choice!=0); save(head);}

以上就是我们为大家找到的有关“数据结构课程设计图书馆管理系统(图书馆管理系统 数据结构课程设计 c语言)”的所有内容了,希望可以帮助到你。如果对我们网站的其他内容感兴趣请持续关注本站。

数据结构课程设计图书馆管理系统(图书馆管理系统 数据结构课程设计 c语言)

本文编辑:admin
Copyright © 2022 All Rights Reserved 威海上格软件有限公司 版权所有

鲁ICP备20007704号

Thanks for visiting my site.