C语言大作业之图书管理系统的实现详程
序
时间在流去,我们在长大。
嗨,这里是狐狸~~
今天是2022年的一月四日了,元旦小长假也过去了,新年新气象,新年新目标,我们要向前看,不要执意过去了,感谢过去,把握现在,展望未来,这是我们现在应该做的。好了,废话不多说,今天我们分享一个系统,确实也有许久没有分享过系统了,今天就给大家详细讲一下这个图书管理系统吧。
主要内容
开发一个图书信息管理系统,图书信息包括:图书编号、书名、作者、出版社、类别、出版时间、价格等基本信息(也可以根据自己情况进行扩充,比如是否借出、库存量等)。使之能提供以下基本功能:
(1)图书信息录入功能(图书信息用文件保存)--输入
(2)图书信息浏览功能--输出
(3)查询功能(至少一种查询方式)、排序功能(至少一种排序方式):
①按书名查询
②按作者名查询 按照价钱排序 按出版时间排序等等
(4)图书信息的删除与修改
扩展功能:可以按照自己的程度进行扩展。比如
(1)简单的权限处理
(2)报表打印功能
(3)甚至根据自己情况,可以加上学生信息,并扩充为图书借阅系统。
(4)模糊查询
(5)综合查询
(6)统计功能 比如统计处某一类别的图书信息 或 筛选出小于指定数量库存的图书信息等等。
概要设计
1 图书录入可以录入图书名,作者,出版社,出版日期,价格!录入图书编号时函数就会判断此 编 号是否存在,若存在不能成功录入!
2 图书浏览可以浏览全部图书!
3 图书查询提供按图书编号模糊查询,按图书名关键字查询,按图书编号精确查询,按图书名精确 查询!模糊查询和关键字查询事通过比价字符串的相似度而实现的!
4 修改删除图书可以通过图书查询来查询操作的图书编号,通过编号操作!函数会提示用户是否调 用图书查询来找到自己想要操作的图书的编号。如果某一本图书已经被借阅那么用户就不能删 除 该图书!
5 借阅图书通过学号和图书编号进行借阅!如果该学号是第一次借阅那么会提示用户输入自己的姓 名,并存入student.txt,方便以后借阅与归还!
6 归还图书先提供学号,然后程序会输出该学号借阅的所有图书,然后再通过编号归还!
7 借阅查询可查询某个学生已借但未归还的图书!
项目源码
结构体
先建立结构体,定义结构体成员
typedef 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;
登录界面函数
int login(ulink l) { /*****************登陆窗口初始化****************************/ while(!flag) { char user_id[10],password[10],tmp; int i=0; user_id[0]='\0'; password[0]='\0'; textbackground(179); clrscr(); gotoxy(33,23); textcolor(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; return 0; } 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; return 0; } } 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; return 0; } while(tmp!='\r'&&i<=10&&(tmp>=64&&tmp<=90)||(tmp>=97&&tmp<=122||(tmp>=48&&tmp<=57))) { textbackground(5); putch('*'); password[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; } } }
选择界面函数
void 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(">>>-------------------------1.user management----------------------------<<<"); gotoxy(3,10); cputs(">>>-------------------------2.book management----------------------------<<<"); gotoxy(3,14); cputs(">>>-------------------------3.borrow books-------------------------------<<<"); gotoxy(30,22); textcolor(red); cputs("please select!!!"); flg=getch(); if(flg=='2') bookss(); if(flg=='1') users(); if(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; } } }
操作界面函数
void 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++; } } while(1) { textbackground(179); clrscr(); textcolor(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; } } }
添加函数
图书的添加,包括用户添加以及管理员添加
void 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->data.name); 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; textcolor(red); gotoxy(25,4); cputs("input the message about book"); gotoxy(31,10); textcolor(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->data.name); 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); }
查找函数
用户查找以及管理员查找
/*******管理员查找图书*******/ 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->data.name); 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); cputs("search success !!"); } 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); gotoxy(36,14); textcolor(white); cputs("book name:"); printf("%s",p->data.name); 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; 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->data.name); 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); gotoxy(36,14); textcolor(white); cputs("book name:"); printf("%s",p->data.name); 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(); return 0; } strcpy(findm,id); p=locate(l,findm,"num"); if(p) { strcpy(findm,na); p=locate(l,findm,"name"); if(p) { return 1; } else { textcolor(red); gotoxy(30,22); cputs("book name is null !!!"); getch(); return 0; } } else { gotoxy(30,22); textcolor(red); cputs("book id is null !!!"); getch(); return 0; } }
删除函数
图书的删除
void 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"); 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); }
借书管理函数
void 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': del_borrow(l); save_borrow(l); break; case 's': qur_borrow(l); break; case 27: return; } } } }
信息储存函数
图书信息的储存
*******借书信息保存*******/ 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); }
还书函数
/* 还书的操作 */ 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:"); 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 !!"); getch(); } textcolor(yellow); }
修改函数
也分为用户和管理员两种情况
/* ****用于管理员修改用户资料 ***/ 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->data.name); scanf("%s",p->data.name); gotoxy(25,16); printf("input the new sex(old:%s):",p->data.sex); scanf("%s",p->data.sex); gotoxy(30,20); 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->data.name); scanf("%s",p->data.name); 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(); } }
添加借书函数
/*******添加借书*******/ 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)); if(fread(q,sizeof(unode),1,fp)) /* 将文件的内容放入接点中 */ { q->next=null; 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); }
查找借书函数
查找自己借了哪些书
void myborrow() { int i; 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"); } i=6; while(!feof(fp)) { p=(bbnode*)malloc(sizeof(bbnode)); if(fread(p,sizeof(bbnode),1,fp)) /* 将文件的内容放入接点中 */ { textcolor(white); gotoxy(30,4); cputs("your borrow book"); if(strcmp(p->user,os->data.num)==0) { textcolor(yellow); gotoxy(20,i); printf("borrow id:%s\tbook id:%s\tbook name:%s",p->id,p->bookid,p->book); i++; p->next=null; r->next=p; r=p; /* 将该接点挂入连中 */ count++; } } myborrow=count; if(myborrow==0) { textcolor(yellow); gotoxy(30,13); cputs("you no borrow !!"); } } fclose(fp); textcolor(yellow); gotoxy(65,2); printf("(borrow=%d)",myborrow); getch(); }
借书管理函数
void 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': del_borrow(l); save_borrow(l); break; case 's': qur_borrow(l); break; case 27: return; } } } }
主函数
main() { ulink h,os;/* 连表 */ file *fp; /* 文件指针 */ unode *p,*r; h=(unode*)malloc(sizeof(unode)); h->next=null; r=h; fp=fopen(ufile,"rb"); if(fp==null) { fp=fopen(ufile,"wb"); } while(!feof(fp)) { p=(unode*)malloc(sizeof(unode)); if(fread(p,sizeof(unode),1,fp)) /* 将文件的内容放入接点中 */ { p->next=null; r->next=p; r=p; /* 将该接点挂入连中 */ } } fclose(fp); system("wellcome"); if(flg==27) { flg=-1; return; } while(1) { flag=login(h); if(flg==27) { flg=-1; break; } if(flag==2) { choose(); flag=0; } if(flag==1) { user(h); flag=0; } } }
总结
今天的代码量有点小多,难度也不小,用了大量的链表来储存数据,还有一些功能因为篇幅的问题没有放上来,总的来说,这个图书管理系统的功能是很全面的,无论从哪个角度来看。当然啦。有兴趣的同学可以进群领取完整的源码看看,绝对是一个不错的机会,可以说,你要是学会了这个系统,你的c语言在我看来就完全没有问题了,而且在数据结构一块,你也算是小成了,所以希望大家可以认真学习,争取早日掌握。
这也是2022年的第一篇文章了,希望2022继续加油,向大家分享更多有趣的、有用的知识,十分感谢大家的一路支持,后续我还会发布更多的项目源或者学习资料,希望大家可以持续关注。
到此这篇关于c语言大作业之图书管理系统的实现详程的文章就介绍到这了,更多相关c语言 图书管理系统内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!