经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » 程序设计 » C 语言 » 查看文章
C语言大作业之图书管理系统的实现详程
来源:jb51  时间:2022/1/24 10:09:24  对本文有异议

时间在流去,我们在长大。

嗨,这里是狐狸~~

今天是2022年的一月四日了,元旦小长假也过去了,新年新气象,新年新目标,我们要向前看,不要执意过去了,感谢过去,把握现在,展望未来,这是我们现在应该做的。好了,废话不多说,今天我们分享一个系统,确实也有许久没有分享过系统了,今天就给大家详细讲一下这个图书管理系统吧。

主要内容

        开发一个图书信息管理系统,图书信息包括:图书编号、书名、作者、出版社、类别、出版时间、价格等基本信息(也可以根据自己情况进行扩充,比如是否借出、库存量等)。使之能提供以下基本功能:

(1)图书信息录入功能(图书信息用文件保存)--输入

(2)图书信息浏览功能--输出

(3)查询功能(至少一种查询方式)、排序功能(至少一种排序方式):

            ①按书名查询

            ②按作者名查询 按照价钱排序 按出版时间排序等等

(4)图书信息的删除与修改

          扩展功能:可以按照自己的程度进行扩展。比如

                          (1)简单的权限处理

                          (2)报表打印功能

                          (3)甚至根据自己情况,可以加上学生信息,并扩充为图书借阅系统。

                          (4)模糊查询

                          (5)综合查询

                          (6)统计功能 比如统计处某一类别的图书信息 或 筛选出小于指定数量库存的图书信息等等。

概要设计

1 图书录入可以录入图书名,作者,出版社,出版日期,价格!录入图书编号时函数就会判断此        编 号是否存在,若存在不能成功录入!

2 图书浏览可以浏览全部图书!

3 图书查询提供按图书编号模糊查询,按图书名关键字查询,按图书编号精确查询,按图书名精确      查询!模糊查询和关键字查询事通过比价字符串的相似度而实现的!

4 修改删除图书可以通过图书查询来查询操作的图书编号,通过编号操作!函数会提示用户是否调      用图书查询来找到自己想要操作的图书的编号。如果某一本图书已经被借阅那么用户就不能删        除 该图书!

5 借阅图书通过学号和图书编号进行借阅!如果该学号是第一次借阅那么会提示用户输入自己的姓      名,并存入student.txt,方便以后借阅与归还!

6 归还图书先提供学号,然后程序会输出该学号借阅的所有图书,然后再通过编号归还!

7 借阅查询可查询某个学生已借但未归还的图书!

项目源码

结构体

先建立结构体,定义结构体成员

  1. typedef struct book/*图书结构体*/
  2. {
  3. char num[10]; /*书号*/
  4. char name[10]; /*书名*/
  5. char auth[10]; /*作者*/
  6. int count;
  7. int sum;
  8. }Book;
  9. typedef struct borrow/*借书结构体*/
  10. {
  11. char id[20];
  12. char user[20];
  13. char book[20];
  14. char bookid[20];
  15. struct borrow *next;
  16. }BBnode,*BBlink;
  17. struct user
  18. {
  19. char num[10];/* 学号 */
  20. char pass[15];
  21. char name[15];
  22. char sex[10];
  23. };
  24. typedef struct unode
  25. {
  26. struct user data;
  27. struct unode *next;
  28. }Unode,*Ulink;
  29. Unode *os;

登录界面函数

  1. int login(Ulink l)
  2. {
  3. /*****************登陆窗口初始化****************************/
  4. while(!flag)
  5. {
  6. char User_id[10],password[10],tmp;
  7. int i=0;
  8. User_id[0]='\0';
  9. password[0]='\0';
  10. textbackground(179);
  11. clrscr();
  12. gotoxy(33,23);
  13. textcolor(YELLOW);
  14. cputs("ESC = EXIT");
  15. textcolor(WHITE);
  16. textbackground(179);
  17. box(1,1,80,24);
  18. h_line(2,3,78);
  19. gotoxy(15,2);
  20. cputs("Login now please input the User__ID and Password");
  21. bar_(30,10,23,5,5);
  22. /******************账号过滤*********************/
  23. while(User_id[0]=='\0')
  24. {
  25. gotoxy(31,11);
  26. textcolor(YELLOW);
  27. textbackground(5);
  28. cputs("User__ID:");
  29. gotoxy(31,13);
  30. cputs("Password:");
  31. textbackground(179);
  32. textcolor(WHITE);
  33. gotoxy(28,7);
  34. cputs("please input the User__ID!");
  35. textbackground(179);
  36. textcolor(YELLOW);
  37. gotoxy(27,11);
  38. putch(272);
  39. gotoxy(27,13);
  40. putch(' ');
  41. gotoxy(40,11);
  42. tmp=getch();
  43. if(tmp==27)
  44. {
  45. flg=27;
  46. return 0;
  47. }
  48. while(tmp!='\r'&&i<=9&&(tmp>=64&&tmp<=90)||(tmp>=97&&tmp<=122||(tmp>=48&&tmp<=57)))
  49. {
  50. textcolor(YELLOW);
  51. textbackground(5);
  52. putch(tmp);
  53. User_id[i]=tmp;
  54. i++;
  55. tmp=getch();
  56. if(tmp==27)
  57. {
  58. flg=27;
  59. return 0;
  60. }
  61. }
  62. User_id[i]='\0';
  63. }
  64. /**********************密码过滤****************************/
  65. while(password[0]=='\0')
  66. {
  67. gotoxy(28,7);
  68. textbackground(179);
  69. textcolor(WHITE);
  70. cputs(" input the password now ");
  71. textbackground(179);
  72. textcolor(YELLOW);
  73. gotoxy(27,13);
  74. putch(272);
  75. gotoxy(27,11);
  76. putch(' ');
  77. gotoxy(40,13);
  78. i=0;
  79. tmp=getch();
  80. if(tmp==27)
  81. {
  82. flg=27;
  83. return 0;
  84. }
  85. while(tmp!='\r'&&i<=10&&(tmp>=64&&tmp<=90)||(tmp>=97&&tmp<=122||(tmp>=48&&tmp<=57)))
  86. {
  87. textbackground(5);
  88. putch('*');
  89. password[i]=tmp;
  90. i++;
  91. tmp=getch();
  92. if(tmp==27)
  93. {
  94. flg=27;
  95. return 0;
  96. }
  97. }
  98. password[i]='\0';
  99. }
  100. /*************把账号和密码进行对比验证**************/
  101. if(!strcmp(User_id,"admin")&&!strcmp(password,"admin"))
  102. {
  103. return 2;
  104. }
  105. if(cmps(l,User_id,password))
  106. {
  107. return 1;
  108. }
  109. }
  110. }

选择界面函数

  1. void choose()
  2. {
  3. while(1)
  4. {
  5. textbackground(179);
  6. clrscr();
  7. gotoxy(33,2);
  8. textcolor(WHITE);
  9. cputs("Administrastor");
  10. textcolor(YELLOW);
  11. box(1,1,80,24);
  12. h_line(2,3,78);
  13. gotoxy(3,6);
  14. cputs(">>>-------------------------1.User Management----------------------------<<<");
  15. gotoxy(3,10);
  16. cputs(">>>-------------------------2.Book Management----------------------------<<<");
  17. gotoxy(3,14);
  18. cputs(">>>-------------------------3.Borrow Books-------------------------------<<<");
  19. gotoxy(30,22);
  20. textcolor(RED);
  21. cputs("Please Select!!!");
  22. flg=getch();
  23. if(flg=='2')
  24. bookss();
  25. if(flg=='1')
  26. users();
  27. if(flg=='3')
  28. borrow();
  29. if(flg==27)
  30. {
  31. flg=-1;
  32. return;
  33. }
  34. }
  35. }
  36. void admin()
  37. {
  38. while(1)
  39. {
  40. choose();
  41. if(flg=='1')
  42. bookss();
  43. if(flg=='2')
  44. users();
  45. if(flg=='3')
  46. borrow();
  47. if(flg==27)
  48. {
  49. return;
  50. }
  51. }
  52. }

操作界面函数

  1. void user(Ulink h)
  2. {
  3. int flag;
  4. BBlink l,p,r;/* 连表 */
  5. FILE *fp; /* 文件指针 */
  6. int count=0;
  7. l=(BBnode*)malloc(sizeof(BBnode));
  8. l->next=NULL;
  9. r=l;
  10. fp=fopen(bfile,"rb");
  11. if(fp==NULL)
  12. {
  13. fp=fopen(bfile,"wb");
  14. }
  15. while(!feof(fp))
  16. {
  17. p=(BBnode*)malloc(sizeof(BBnode));
  18. if(fread(p,sizeof(BBnode),1,fp)) /* 将文件的内容放入接点中 */
  19. {
  20. p->next=NULL;
  21. r->next=p;
  22. r=p; /* 将该接点挂入连中 */
  23. count++;
  24. }
  25. }
  26. while(1)
  27. {
  28. textbackground(179);
  29. clrscr();
  30. textcolor(YELLOW);
  31. box(1,1,80,24);
  32. h_line(2,3,78);
  33. gotoxy(3,2);
  34. textcolor(RED);
  35. cputs("A.");
  36. textcolor(BLUE);
  37. cputs("my message ");
  38. textcolor(RED);
  39. cputs("B.");
  40. textcolor(BLUE);
  41. cputs("modyfy my message ");
  42. textcolor(RED);
  43. cputs("C.");
  44. textcolor(BLUE);
  45. cputs("my borrow ");
  46. textcolor(RED);
  47. cputs("D.");
  48. textcolor(BLUE);
  49. cputs("search book");
  50. textcolor(YELLOW);
  51. gotoxy(50,50);
  52. flag=getch();
  53. switch(flag)
  54. {
  55. case 'a':
  56. show(os);
  57. break; /*************添加用户**********/
  58. case 'b':
  59. Modify_user(h);
  60. Save(h);
  61. break;/*************删除用户**********/
  62. case 'c':
  63. Myborrow();
  64. break;
  65. case 'd':
  66. usersearch();
  67. break;
  68. case 27:
  69. return;
  70. }
  71. }
  72. }

添加函数

图书的添加,包括用户添加以及管理员添加

  1. void add(blink l)
  2. {
  3. Bnode *p,*r,*s;
  4. char num[10];
  5. r=l;
  6. s=l->next;
  7. while(r->next!=NULL)
  8. r=r->next;
  9. textcolor(RED);
  10. gotoxy(25,4);
  11. cputs("INPUT THE MESSAGE ABOUT BOOK");
  12. gotoxy(31,10);
  13. textcolor(YELLOW);
  14. cputs("Book ID:");
  15. scanf("%s",num);
  16. p=(Bnode *)malloc(sizeof(Bnode));
  17. while(s)
  18. {
  19. if(strcmp(s->data.num,num)==0)
  20. {
  21. textcolor(WHITE);
  22. gotoxy(25,15);
  23. cputs("This ID:");
  24. printf("'%s'",num);
  25. cputs("is exist!");
  26. gotoxy(25,22);
  27. cputs("please Press any key to continue...");
  28. gotoxy(255,252);
  29. getch();
  30. return;
  31. }
  32. s=s->next;
  33. }
  34. strcpy(p->data.num,num);
  35. gotoxy(31,12);
  36. textcolor(YELLOW);
  37. cputs("Input Book name:");
  38. scanf("%s",p->data.name);
  39. gotoxy(31,14);
  40. cputs("input your Book auth:");
  41. scanf("%s",p->data.auth);
  42. gotoxy(31,16);
  43. cputs("input your Book count:");
  44. scanf("%d",&p->data.count);
  45. bookcount=p->data.count+bookcount;
  46. p->data.sum=0;
  47. p->next=NULL;
  48. r->next=p;
  49. r=p;
  50. gotoxy(30,22);
  51. textcolor(RED);
  52. cputs("Add Book Success !!!");
  53. getch();
  54. textcolor(YELLOW);
  55. }
  56. /*******管理员添加用户*******/
  57. void Add(Ulink l)
  58. {
  59. Unode *p,*r,*s;
  60. char num[10];
  61. r=l;
  62. s=l->next;
  63. while(r->next!=NULL)
  64. r=r->next;
  65. textcolor(RED);
  66. gotoxy(25,4);
  67. cputs("INPUT THE MESSAGE ABOUT BOOK");
  68. gotoxy(31,10);
  69. textcolor(YELLOW);
  70. cputs("User ID:");
  71. scanf("%s",num);
  72. p=(Unode *)malloc(sizeof(Unode));
  73. while(s)
  74. {
  75. if(strcmp(s->data.num,num)==0)
  76. {
  77. gotoxy(25,15);
  78. cputs("This ID:");
  79. printf("'%s'",num);
  80. cputs("is exist!");
  81. gotoxy(25,22);
  82. textcolor(RED);
  83. cputs("please Press any key to continue...");
  84. gotoxy(255,252);
  85. getch();
  86. return;
  87. }
  88. s=s->next;
  89. }
  90. strcpy(p->data.num,num);
  91. gotoxy(31,12);
  92. textcolor(YELLOW);
  93. cputs("Input Password:");
  94. scanf("%s",p->data.pass);
  95. gotoxy(31,14);
  96. cputs("input your name:");
  97. scanf("%s",p->data.name);
  98. gotoxy(31,16);
  99. cputs("input the sex:");
  100. scanf("%s",p->data.sex);
  101. p->next=NULL;
  102. r->next=p;
  103. r=p;
  104. gotoxy(30,22);
  105. cputs("Add User Success !!!");
  106. usercount++;
  107. getch();
  108. textcolor(YELLOW);
  109. }

查找函数

用户查找以及管理员查找

  1. /*******管理员查找图书*******/
  2. void qur(blink l)
  3. {
  4. int sel;
  5. char findmess[20];
  6. Bnode *p;
  7. if(!l->next)
  8. {
  9. gotoxy(30,4);
  10. textcolor(WHITE);
  11. cputs("Not Find Bookdata!!!");
  12. getch();
  13. return;
  14. }
  15. textcolor(RED);
  16. gotoxy(25,4);
  17. cputs("Please Select Search Type !");
  18. gotoxy(10,8);
  19. textcolor(WHITE);
  20. cputs("1.Search by ID");
  21. gotoxy(10,10);
  22. cputs("2.Search by Name");
  23. gotoxy(10,12);
  24. cputs("Please Select 1 or 2:");
  25. scanf("%d",&sel);
  26. if(sel==1)
  27. {
  28. gotoxy(36,8);
  29. textcolor(YELLOW);
  30. cputs("Input the search ID:");
  31. scanf("%s",findmess);
  32. p=locate(l,findmess,"num");
  33. if(p)
  34. {
  35. gotoxy(36,12);
  36. textcolor(WHITE);
  37. cputs("Book ID:");
  38. printf("%s",p->data.num);
  39. gotoxy(36,14);
  40. textcolor(WHITE);
  41. cputs("Book Name:");
  42. printf("%s",p->data.name);
  43. gotoxy(36,16);
  44. textcolor(WHITE);
  45. cputs("Book author:");
  46. printf("%s",p->data.auth);
  47. gotoxy(36,18);
  48. textcolor(WHITE);
  49. cputs("Book count:");
  50. printf("%d",p->data.count);
  51. getch();
  52. textcolor(YELLOW);
  53. gotoxy(30,21);
  54. cputs("Search Success !!");
  55. }
  56. else
  57. {
  58. gotoxy(30,22);
  59. textcolor(RED);
  60. cputs("Not finde !!!");
  61. getch();
  62. }
  63. }
  64. else if(sel==2) /* 姓名 */
  65. {
  66. gotoxy(36,8);
  67. textcolor(YELLOW);
  68. cputs("Input the search name:");
  69. scanf("%s",findmess);
  70. p=locate(l,findmess,"name");
  71. if(p)
  72. {
  73. gotoxy(36,12);
  74. textcolor(WHITE);
  75. cputs("Book ID:");
  76. printf("%s",p->data.num);
  77. gotoxy(36,14);
  78. textcolor(WHITE);
  79. cputs("Book Name:");
  80. printf("%s",p->data.name);
  81. gotoxy(36,16);
  82. textcolor(WHITE);
  83. cputs("Book author:");
  84. printf("%s",p->data.auth);
  85. gotoxy(36,18);
  86. textcolor(WHITE);
  87. cputs("Book count:");
  88. printf("%d",p->data.count);
  89. getch();
  90. textcolor(YELLOW);
  91. }
  92. else
  93. {
  94. textcolor(RED);
  95. gotoxy(30,22);
  96. cputs("Not finde !!!");
  97. }
  98. }
  99. else
  100. {
  101. textcolor(RED);
  102. gotoxy(30,22);
  103. cputs("Error !!");
  104. getch();
  105. }
  106. }
  107. /*******用户查找图书*******/
  108. void usersearch()
  109. {
  110. int sel;
  111. char findmess[20];
  112. Bnode *p;
  113. blink l;/* 连表 */
  114. FILE *fp; /* 文件指针 */
  115. int count=0;
  116. Bnode *P,*r;
  117. l=(Bnode*)malloc(sizeof(Bnode));
  118. l->next=NULL;
  119. r=l;
  120. fp=fopen(file,"rb");
  121. if(fp==NULL)
  122. {
  123. fp=fopen(file,"wb");
  124. }
  125. while(!feof(fp))
  126. {
  127. P=(Bnode*)malloc(sizeof(Bnode));
  128. if(fread(P,sizeof(Bnode),1,fp)) /* 将文件的内容放入接点中 */
  129. {
  130. P->next=NULL;
  131. bookcount=bookcount+P->data.count;
  132. booksum=booksum+P->data.sum;
  133. r->next=P;
  134. r=P; /* 将该接点挂入连中 */
  135. count++;
  136. }
  137. }
  138. fclose(fp); /* 关闭文件 */
  139. if(!l->next)
  140. {
  141. gotoxy(30,4);
  142. textcolor(WHITE);
  143. cputs("Not Find Bookdata!!!");
  144. getch();
  145. return;
  146. }
  147. textcolor(RED);
  148. gotoxy(25,4);
  149. cputs("Please Select Delete Type !");
  150. gotoxy(10,8);
  151. textcolor(WHITE);
  152. cputs("1.Search by ID");
  153. gotoxy(10,10);
  154. cputs("2.Search by Name");
  155. gotoxy(10,12);
  156. cputs("Please Select 1 or 2:");
  157. scanf("%d",&sel);
  158. if(sel==1)
  159. {
  160. gotoxy(36,8);
  161. textcolor(YELLOW);
  162. cputs("Input the search ID:");
  163. scanf("%s",findmess);
  164. p=locate(l,findmess,"num");
  165. if(p)
  166. {
  167. gotoxy(36,12);
  168. textcolor(WHITE);
  169. cputs("Book ID:");
  170. printf("%s",p->data.num);
  171. gotoxy(36,14);
  172. textcolor(WHITE);
  173. cputs("Book Name:");
  174. printf("%s",p->data.name);
  175. gotoxy(36,16);
  176. textcolor(WHITE);
  177. cputs("Book author:");
  178. printf("%s",p->data.auth);
  179. gotoxy(36,18);
  180. textcolor(WHITE);
  181. cputs("Book count:");
  182. printf("%d",p->data.count-p->data.sum);
  183. getch();
  184. textcolor(YELLOW);
  185. }
  186. else
  187. {
  188. gotoxy(30,22);
  189. textcolor(RED);
  190. cputs("Not finde !!!");
  191. getch();
  192. }
  193. }
  194. else if(sel==2)
  195. {
  196. gotoxy(36,8);
  197. textcolor(YELLOW);
  198. cputs("Input the search name:");
  199. scanf("%s",findmess);
  200. p=locate(l,findmess,"name");
  201. if(p)
  202. {
  203. gotoxy(36,12);
  204. textcolor(WHITE);
  205. cputs("Book ID:");
  206. printf("%s",p->data.num);
  207. gotoxy(36,14);
  208. textcolor(WHITE);
  209. cputs("Book Name:");
  210. printf("%s",p->data.name);
  211. gotoxy(36,16);
  212. textcolor(WHITE);
  213. cputs("Book author:");
  214. printf("%s",p->data.auth);
  215. gotoxy(36,18);
  216. textcolor(WHITE);
  217. cputs("Book count:");
  218. printf("%d",(p->data.count-p->data.sum));
  219. getch();
  220. textcolor(YELLOW);
  221. }
  222. else
  223. {
  224. textcolor(RED);
  225. gotoxy(30,22);
  226. cputs("Not finde !!!");
  227. }
  228. }
  229. else
  230. {
  231. textcolor(RED);
  232. gotoxy(30,22);
  233. cputs("Error !!");
  234. getch();
  235. }
  236. }
  237. /*******图书查找*******/
  238. int cmpbook(blink l,char id[],char na[])
  239. {
  240. char findm[20];
  241. Bnode *p;
  242. if(!l->next)
  243. {
  244. gotoxy(25,4);
  245. textcolor(RED);
  246. cputs("Not Find Book!!!");
  247. getch();
  248. return 0;
  249. }
  250. strcpy(findm,id);
  251. p=locate(l,findm,"num");
  252. if(p)
  253. {
  254. strcpy(findm,na);
  255. p=locate(l,findm,"name");
  256. if(p)
  257. {
  258. return 1;
  259. }
  260. else
  261. {
  262. textcolor(RED);
  263. gotoxy(30,22);
  264. cputs("Book name is NULL !!!");
  265. getch();
  266. return 0;
  267. }
  268. }
  269. else
  270. {
  271. gotoxy(30,22);
  272. textcolor(RED);
  273. cputs("Book id is NULL !!!");
  274. getch();
  275. return 0;
  276. }
  277. }

删除函数

图书的删除

  1. void del(blink l)
  2. {
  3. int sel;
  4. Bnode *p,*r;
  5. char findmess[20];
  6. if(!l->next)
  7. {
  8. gotoxy(25,4);
  9. textcolor(RED);
  10. cputs("=====>not thing could delete!\n");
  11. getch();
  12. return;
  13. }
  14. textcolor(RED);
  15. gotoxy(25,4);
  16. puts("Please Select Delete Type !");
  17. gotoxy(10,8);
  18. textcolor(WHITE);
  19. cputs("1.Delete by Book ID");
  20. gotoxy(10,10);
  21. cputs("2.Delete by Book Name");
  22. gotoxy(10,12);
  23. cputs("Please Select 1 or 2:");
  24. scanf("%d",&sel);
  25. if(sel==1)
  26. {
  27. gotoxy(36,8);
  28. textcolor(YELLOW);
  29. cputs("Input the delete ID:");
  30. scanf("%s",findmess);
  31. p=locate(l,findmess,"num");
  32. if(p)
  33. {
  34. bookcount=bookcount-p->data.count;
  35. r=l;
  36. while(r->next!=p)
  37. r=r->next;
  38. r->next=p->next;
  39. free(p);
  40. gotoxy(30,22);
  41. textcolor(RED);
  42. cputs("Delete success!\n");
  43. textcolor(YELLOW);
  44. }
  45. else
  46. {
  47. textcolor(RED);
  48. gotoxy(30,22);
  49. cputs("Error !!");
  50. }
  51. }
  52. else if(sel==2)
  53. {
  54. gotoxy(36,8);
  55. textcolor(YELLOW);
  56. cputs("Input the delete name:");
  57. scanf("%s",findmess);
  58. p=locate(l,findmess,"name");
  59. if(p)
  60. {
  61. r=l;
  62. while(r->next!=p)
  63. r=r->next;
  64. r->next=p->next;
  65. free(p);
  66. gotoxy(30,22);
  67. textcolor(RED);
  68. cputs("Delete success!\n");
  69. bookcount--;
  70. textcolor(YELLOW);
  71. }
  72. else
  73. {
  74. gotoxy(25,18);
  75. cputs("Not find!!");
  76. }
  77. }
  78. else
  79. {
  80. textcolor(RED);
  81. gotoxy(30,22);
  82. cputs("Error !!");
  83. }
  84. getch();
  85. textcolor(YELLOW);
  86. }

借书管理函数

  1. void borrow()
  2. {
  3. while(1)
  4. {
  5. int flag;
  6. BBlink l,p,r;/* 连表 */
  7. FILE *fp; /* 文件指针 */
  8. int count=0;
  9. l=(BBnode*)malloc(sizeof(BBnode));
  10. l->next=NULL;
  11. r=l;
  12. fp=fopen(bfile,"rb");
  13. if(fp==NULL)
  14. {
  15. fp=fopen(bfile,"wb");
  16. }
  17. while(!feof(fp))
  18. {
  19. p=(BBnode*)malloc(sizeof(BBnode));
  20. if(fread(p,sizeof(BBnode),1,fp)) /* 将文件的内容放入接点中 */
  21. {
  22. p->next=NULL;
  23. r->next=p;
  24. r=p; /* 将该接点挂入连中 */
  25. count++;
  26. }
  27. borrowcount=count;
  28. }
  29. while(1)
  30. {
  31. textbackground(179);
  32. clrscr();
  33. textcolor(YELLOW);
  34. box(1,1,80,24);
  35. h_line(2,3,78);
  36. gotoxy(3,2);
  37. textcolor(RED);
  38. cputs("B");
  39. textcolor(BLUE);
  40. cputs("orrow book ");
  41. textcolor(RED);
  42. cputs("R");
  43. textcolor(BLUE);
  44. cputs("eturn book ");
  45. textcolor(RED);
  46. cputs("S");
  47. textcolor(BLUE);
  48. cputs("earch borrow ");
  49. textcolor(YELLOW);
  50. printf("count: (borrow=%d)",borrowcount);
  51. textcolor(RED);
  52. gotoxy(50,50);
  53. flag=getch();
  54. switch(flag)
  55. {
  56. case 'b':
  57. Add_borrow(l);
  58. break; /*************添加用户**********/
  59. case 'r':
  60. Del_borrow(l);
  61. Save_borrow(l);
  62. break;
  63. case 's':
  64. Qur_borrow(l);
  65. break;
  66. case 27:
  67. return;
  68. }
  69. }
  70. }
  71. }

信息储存函数

图书信息的储存

  1. *******借书信息保存*******/
  2. void Save_borrow(BBlink l)
  3. {
  4. FILE* fp;
  5. BBnode *p;
  6. int flag=1,count=0;
  7. fp=fopen(bfile,"wb");
  8. if(fp==NULL)
  9. {
  10. gotoxy(35,12);
  11. textcolor(RED);
  12. cputs("open error!");
  13. exit(1);
  14. }
  15. p=l->next;
  16. while(p)
  17. {
  18. if(fwrite(p,sizeof(BBnode),1,fp)==1)
  19. {
  20. p=p->next;
  21. count++;
  22. }
  23. else
  24. {
  25. flag=0;
  26. break;
  27. }
  28. }
  29. if(flag)
  30. {
  31. textcolor(RED);
  32. gotoxy(30,24);
  33. /*** printf("save success.(saved%d.)",count);**调试的时候用的*/
  34. }
  35. fclose(fp);
  36. }

还书函数

  1. /* 还书的操作 */
  2. void Del_borrow(BBlink l)
  3. {
  4. int sel;
  5. BBnode *p,*r;
  6. Bnode *L;
  7. char findmess[20];
  8. FILE *fp; /* 文件指针 */
  9. Bnode *P,*R,*Q;
  10. L=(Bnode*)malloc(sizeof(Bnode));
  11. L->next=NULL;
  12. R=L;
  13. fp=fopen(file,"rb");
  14. if(fp==NULL)
  15. {
  16. fp=fopen(file,"wb");
  17. }
  18. while(!feof(fp))
  19. {
  20. P=(Bnode*)malloc(sizeof(Bnode));
  21. if(fread(P,sizeof(Bnode),1,fp)) /* 将文件的内容放入接点中 */
  22. {
  23. P->next=NULL;
  24. R->next=P;
  25. R=P; /* 将该接点挂入连中 */
  26. }
  27. }
  28. fclose(fp); /* 关闭文件 */
  29. if(!l->next)
  30. {
  31. gotoxy(30,4);
  32. textcolor(RED);
  33. cputs("not Book could Return!\n");
  34. getch();
  35. return;
  36. }
  37. textcolor(RED);
  38. gotoxy(25,4);
  39. puts("Please Select Return Type !");
  40. gotoxy(10,8);
  41. textcolor(WHITE);
  42. cputs("1.Return by Borrow ID");
  43. gotoxy(10,10);
  44. cputs("2.Return by book name");
  45. gotoxy(10,12);
  46. cputs("Please Select 1 or 2:");
  47. scanf("%d",&sel);
  48. if(sel==1)
  49. {
  50. gotoxy(36,8);
  51. textcolor(YELLOW);
  52. cputs("Input the Borrow ID:");
  53. scanf("%s",findmess);
  54. p=Locate_borrow(l,findmess,"num");
  55. if(p)
  56. {
  57. Q=locate(L,findmess,"num");
  58. if(Q)
  59. {
  60. Q->data.sum=Q->data.sum-1;
  61. save(L);
  62. }
  63. r=l;
  64. while(r->next!=p)
  65. r=r->next;
  66. r->next=p->next;
  67. free(p);
  68. gotoxy(30,22);
  69. textcolor(RED);
  70. cputs("Return success!\n");
  71. borrowcount--;
  72. getch();
  73. textcolor(YELLOW);
  74. }
  75. else
  76. {
  77. gotoxy(30,22);
  78. textcolor(RED);
  79. cputs("Note find !!");
  80. getch();
  81. }
  82. }
  83. else if(sel==2)
  84. {
  85. gotoxy(36,8);
  86. textcolor(YELLOW);
  87. cputs("Input the Book name:");
  88. scanf("%s",findmess);
  89. p=Locate_borrow(l,findmess,"book");
  90. if(p)
  91. {
  92. Q=locate(L,findmess,"name");
  93. if(Q)
  94. {
  95. Q->data.sum=Q->data.sum-1;
  96. save(L);
  97. }
  98. r=l;
  99. while(r->next!=p)
  100. r=r->next;
  101. r->next=p->next;
  102. free(p);
  103. gotoxy(30,22);
  104. textcolor(RED);
  105. cputs("Borrow success!\n");
  106. borrowcount--;
  107. getch();
  108. textcolor(YELLOW);
  109. }
  110. else
  111. {
  112. gotoxy(30,18);
  113. textcolor(RED);
  114. cputs("Not find!!");
  115. getch();
  116. }
  117. }
  118. else
  119. {
  120. gotoxy(30,22);
  121. textcolor(RED);
  122. cputs("Not finde !!");
  123. getch();
  124. }
  125. textcolor(YELLOW);
  126. }

修改函数

也分为用户和管理员两种情况 

  1. /* ****用于管理员修改用户资料 ***/
  2. void Modify(Ulink l)
  3. {
  4. Unode *p;
  5. char findmess[20];
  6. if(!l->next)
  7. {
  8. gotoxy(30,4);
  9. textcolor(RED);
  10. cputs("not thing could modify!");
  11. getch();
  12. return;
  13. }
  14. gotoxy(30,4);
  15. textcolor(RED);
  16. cputs("Modify User Message");
  17. gotoxy(25,8);
  18. textcolor(YELLOW);
  19. cputs("input the User Id:");
  20. scanf("%s",findmess);
  21. p=Locate(l,findmess,"num");
  22. if(p)
  23. {
  24. textcolor(YELLOW);
  25. gotoxy(25,10);
  26. printf("Inpute The New ID(old:%s):",p->data.num);
  27. scanf("%s",p->data.num);
  28. gotoxy(25,12);
  29. printf("Input The New Password(old:%s):",p->data.pass);
  30. scanf("%s",p->data.pass);
  31. gotoxy(25,14);
  32. printf("Input The New Name(old:%s):",p->data.name);
  33. scanf("%s",p->data.name);
  34. gotoxy(25,16);
  35. printf("Input The New Sex(old:%s):",p->data.sex);
  36. scanf("%s",p->data.sex);
  37. gotoxy(30,20);
  38. textcolor(RED);
  39. cputs("Modify Success !!!");
  40. getch();
  41. textcolor(YELLOW);
  42. }
  43. else
  44. {
  45. gotoxy(30,16);
  46. textcolor(RED);
  47. cputs("Not Finde !!!");
  48. getch();
  49. }
  50. }
  51. /****供用户修改用户自己资料 */
  52. void Modify_user(Ulink l)
  53. {
  54. Unode *p;
  55. char findmess[20];
  56. if(!l->next)
  57. {
  58. gotoxy(30,4);
  59. textcolor(RED);
  60. cputs("not thing could modify!");
  61. getch();
  62. return;
  63. }
  64. gotoxy(30,4);
  65. textcolor(RED);
  66. cputs("Modify User Message");
  67. gotoxy(33,8);
  68. textcolor(YELLOW);
  69. strcpy(findmess,os->data.num);
  70. printf("your id:%s",findmess);
  71. p=Locate(l,findmess,"num");
  72. if(p)
  73. {
  74. textcolor(YELLOW);
  75. gotoxy(24,10);
  76. printf("Input The New Password(old:%s):",p->data.pass);
  77. scanf("%s",p->data.pass);
  78. gotoxy(24,12);
  79. printf("Input The New Name(old:%s):",p->data.name);
  80. scanf("%s",p->data.name);
  81. gotoxy(24,14);
  82. printf("Input The New Sex(old:%s):",p->data.sex);
  83. scanf("%s",p->data.sex);
  84. gotoxy(31,18);
  85. textcolor(RED);
  86. cputs("Modify Success !!!");
  87. getch();
  88. textcolor(YELLOW);
  89. }
  90. else
  91. {
  92. gotoxy(30,16);
  93. textcolor(RED);
  94. cputs("Not Finde !!!");
  95. getch();
  96. }
  97. }

添加借书函数

  1. /*******添加借书*******/
  2. void Add_borrow(BBlink l)
  3. {
  4. Ulink H;/* 连表 */
  5. FILE *Fp; /* 文件指针 */
  6. Unode *Q,*T;
  7. blink L;/* 连表 */
  8. FILE *FP; /* 文件指针 */
  9. int ttl;
  10. Bnode *P,*R;
  11. char bookid[20];
  12. char bookname[20];
  13. char userid[20];
  14. BBnode *p,*r,*s;
  15. char num[10];
  16. r=l;
  17. s=l->next;
  18. while(r->next!=NULL)
  19. r=r->next;
  20. L=(Bnode*)malloc(sizeof(Bnode));
  21. L->next=NULL;
  22. R=L;
  23. FP=fopen(file,"rb");
  24. if(FP==NULL)
  25. {
  26. FP=fopen(file,"wb");
  27. }
  28. while(!feof(FP))
  29. {
  30. P=(Bnode*)malloc(sizeof(Bnode));
  31. if(fread(P,sizeof(Bnode),1,FP)) /* 将文件的内容放入接点中 */
  32. {
  33. P->next=NULL;
  34. bookcount=bookcount+P->data.count;
  35. R->next=P;
  36. R=P; /* 将该接点挂入连中 */
  37. }
  38. }
  39. fclose(FP); /* 关闭文件 */
  40. H=(Unode*)malloc(sizeof(Unode));
  41. H->next=NULL;
  42. T=H;
  43. Fp=fopen(ufile,"rb");
  44. if(Fp==NULL)
  45. {
  46. Fp=fopen(ufile,"wb");
  47. }
  48. while(!feof(Fp))
  49. {
  50. Q=(Unode*)malloc(sizeof(Unode));
  51. if(fread(Q,sizeof(Unode),1,Fp)) /* 将文件的内容放入接点中 */
  52. {
  53. Q->next=NULL;
  54. T->next=Q;
  55. T=Q; /* 将该接点挂入连中 */
  56. }
  57. }
  58. fclose(Fp);
  59. textcolor(RED);
  60. gotoxy(25,4);
  61. cputs("Please input thease message");
  62. gotoxy(30,10);
  63. textcolor(YELLOW);
  64. cputs("Input Borrow ID:");
  65. scanf("%d",&ttl);
  66. itoa(ttl,num,10) ;
  67. p=(BBnode *)malloc(sizeof(BBnode));
  68. while(s)
  69. {
  70. if(strcmp(s->id,num)==0)
  71. {
  72. gotoxy(30,15);
  73. cputs("Borrow ID:");
  74. printf("'%s'",num);
  75. cputs("is exist!");
  76. gotoxy(26,22);
  77. textcolor(RED);
  78. cputs("please Press any key to continue...");
  79. gotoxy(255,252);
  80. getch();
  81. return;
  82. }
  83. s=s->next;
  84. }
  85. strcpy(p->id,num);
  86. gotoxy(31,12);
  87. textcolor(YELLOW);
  88. cputs("Input book id:");
  89. scanf("%s",bookid);
  90. gotoxy(31,14);
  91. textcolor(YELLOW);
  92. cputs("Input book name:");
  93. scanf("%s",bookname);/***************************************图书判断在否***************************************/
  94. if(cmpbook(L,bookid,bookname))
  95. {
  96. strcpy(p->bookid,bookid);
  97. strcpy(p->book,bookname);
  98. gotoxy(31,16);
  99. cputs("input your ID:");
  100. scanf("%s",userid); /**************************************用户判断在否********************************/
  101. if(cmpuser(H,userid))
  102. {
  103. strcpy(p->user,userid);
  104. p->next=NULL;
  105. r->next=p;
  106. r=p;
  107. if(changeb(L,bookid))
  108. {
  109. gotoxy(30,22);
  110. cputs("Borrow Success !!!");
  111. Save_borrow(l);
  112. borrowcount++;
  113. getch();
  114. }
  115. }
  116. }
  117. textcolor(YELLOW);
  118. }

查找借书函数

查找自己借了哪些书

  1. void Myborrow()
  2. {
  3. int i;
  4. BBlink l,p,r;/* 连表 */
  5. FILE *fp; /* 文件指针 */
  6. int count=0;
  7. l=(BBnode*)malloc(sizeof(BBnode));
  8. l->next=NULL;
  9. r=l;
  10. fp=fopen(bfile,"rb");
  11. if(fp==NULL)
  12. {
  13. fp=fopen(bfile,"wb");
  14. }
  15. i=6;
  16. while(!feof(fp))
  17. {
  18. p=(BBnode*)malloc(sizeof(BBnode));
  19. if(fread(p,sizeof(BBnode),1,fp)) /* 将文件的内容放入接点中 */
  20. {
  21. textcolor(WHITE);
  22. gotoxy(30,4);
  23. cputs("Your borrow book");
  24. if(strcmp(p->user,os->data.num)==0)
  25. {
  26. textcolor(YELLOW);
  27. gotoxy(20,i);
  28. printf("Borrow ID:%s\tBook id:%s\tBook name:%s",p->id,p->bookid,p->book);
  29. i++;
  30. p->next=NULL;
  31. r->next=p;
  32. r=p; /* 将该接点挂入连中 */
  33. count++;
  34. }
  35. }
  36. myborrow=count;
  37. if(myborrow==0)
  38. {
  39. textcolor(YELLOW);
  40. gotoxy(30,13);
  41. cputs("You no borrow !!");
  42. }
  43. }
  44. fclose(fp);
  45. textcolor(YELLOW);
  46. gotoxy(65,2);
  47. printf("(borrow=%d)",myborrow);
  48. getch();
  49. }

借书管理函数

  1. void borrow()
  2. {
  3. while(1)
  4. {
  5. int flag;
  6. BBlink l,p,r;/* 连表 */
  7. FILE *fp; /* 文件指针 */
  8. int count=0;
  9. l=(BBnode*)malloc(sizeof(BBnode));
  10. l->next=NULL;
  11. r=l;
  12. fp=fopen(bfile,"rb");
  13. if(fp==NULL)
  14. {
  15. fp=fopen(bfile,"wb");
  16. }
  17. while(!feof(fp))
  18. {
  19. p=(BBnode*)malloc(sizeof(BBnode));
  20. if(fread(p,sizeof(BBnode),1,fp)) /* 将文件的内容放入接点中 */
  21. {
  22. p->next=NULL;
  23. r->next=p;
  24. r=p; /* 将该接点挂入连中 */
  25. count++;
  26. }
  27. borrowcount=count;
  28. }
  29. while(1)
  30. {
  31. textbackground(179);
  32. clrscr();
  33. textcolor(YELLOW);
  34. box(1,1,80,24);
  35. h_line(2,3,78);
  36. gotoxy(3,2);
  37. textcolor(RED);
  38. cputs("B");
  39. textcolor(BLUE);
  40. cputs("orrow book ");
  41. textcolor(RED);
  42. cputs("R");
  43. textcolor(BLUE);
  44. cputs("eturn book ");
  45. textcolor(RED);
  46. cputs("S");
  47. textcolor(BLUE);
  48. cputs("earch borrow ");
  49. textcolor(YELLOW);
  50. printf("count: (borrow=%d)",borrowcount);
  51. textcolor(RED);
  52. gotoxy(50,50);
  53. flag=getch();
  54. switch(flag)
  55. {
  56. case 'b':
  57. Add_borrow(l);
  58. break; /*************添加用户**********/
  59. case 'r':
  60. Del_borrow(l);
  61. Save_borrow(l);
  62. break;
  63. case 's':
  64. Qur_borrow(l);
  65. break;
  66. case 27:
  67. return;
  68. }
  69. }
  70. }
  71. }

主函数

  1. main()
  2. {
  3. Ulink h,os;/* 连表 */
  4. FILE *fp; /* 文件指针 */
  5. Unode *p,*r;
  6. h=(Unode*)malloc(sizeof(Unode));
  7. h->next=NULL;
  8. r=h;
  9. fp=fopen(ufile,"rb");
  10. if(fp==NULL)
  11. {
  12. fp=fopen(ufile,"wb");
  13. }
  14. while(!feof(fp))
  15. {
  16. p=(Unode*)malloc(sizeof(Unode));
  17. if(fread(p,sizeof(Unode),1,fp)) /* 将文件的内容放入接点中 */
  18. {
  19. p->next=NULL;
  20. r->next=p;
  21. r=p; /* 将该接点挂入连中 */
  22. }
  23. }
  24. fclose(fp);
  25. system("wellcome");
  26. if(flg==27)
  27. {
  28. flg=-1;
  29. return;
  30. }
  31. while(1)
  32. {
  33. flag=login(h);
  34. if(flg==27)
  35. {
  36. flg=-1;
  37. break;
  38. }
  39. if(flag==2)
  40. {
  41. choose();
  42. flag=0;
  43. }
  44. if(flag==1)
  45. {
  46. user(h);
  47. flag=0;
  48. }
  49. }
  50. }

总结

     今天的代码量有点小多,难度也不小,用了大量的链表来储存数据,还有一些功能因为篇幅的问题没有放上来,总的来说,这个图书管理系统的功能是很全面的,无论从哪个角度来看。当然啦。有兴趣的同学可以进群领取完整的源码看看,绝对是一个不错的机会,可以说,你要是学会了这个系统,你的C语言在我看来就完全没有问题了,而且在数据结构一块,你也算是小成了,所以希望大家可以认真学习,争取早日掌握。

     这也是2022年的第一篇文章了,希望2022继续加油,向大家分享更多有趣的、有用的知识,十分感谢大家的一路支持,后续我还会发布更多的项目源或者学习资料,希望大家可以持续关注。

念七可爱卡通情侣头像 可做表情包的卡通情侣头像

到此这篇关于C语言大作业之图书管理系统的实现详程的文章就介绍到这了,更多相关C语言 图书管理系统内容请搜索w3xue以前的文章或继续浏览下面的相关文章希望大家以后多多支持w3xue!

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号