为了方便图书查询,我们编写了这个图书馆查询系统,通过将图书的信息输入进这个系统,我们便可以直到图书的相关情况。图书管理员存入图书信息,使用者可以通过选项实现查询图书借阅信息,借取图书,归还图书,查看图书热度榜等操作。

#define _CRT_SECURE_NO_WARNINGS
#include "stdio.h"
#include "string.h"
#include "windows.h"
#include "stdlib.h"
struct book
{char book_name[20];char book_num[20];char date[11]="0000/00/00"; int flag=1;int heat=0;
};
void search(struct book *a,char b[20],int n)
{int t = 0;for (int i = 0; i < n; i++){if (strcmp(b, a[i].book_name) == 0){t++;printf("\n查找结果为:(图书名称 图书编号 上次借出日期 状态)\n%s %s %s ", a[i].book_name, a[i].book_num,a[i].date);         //查找书籍数据if (a[i].flag==1){printf("该书未借出\n\n");}else{printf("该书已借出\n\n");}}}if (t==0){printf("没有该图书信息\n");}
}
void borrow(struct book *a,int n)
{printf("请输入您要借取的图书编号:\n");char name[20];scanf("%s", name);int x = 0;for (int i = 0; i < n; i++){if (strcmp(name, a[i].book_num) == 0){if (a[i].flag==1){x++;a[i].flag = 0;a[i].heat++;printf("\n请填写借出日期:(如2020/10/31)\n");scanf("%s", a[i].date);printf("\n恭喜你成功借阅!\n\n");}else{printf("\n这本书已经借出!\n\n");}}}if (x==0){printf("\n该书不存在!\n\n");}
}
void returnbook(struct book* a, int n)
{printf("请输入您要归还的图书编号:\n");char name[20];int t = 0;scanf("%s", name);for (int i = 0; i < n; i++){if (strcmp(name, a[i].book_num) == 0&&a[i].flag==0){t++;a[i].flag = 1;printf("\n恭喜你成功归还!\n\n");}}if (t==0){printf("\n该书未借出或图书编号错误!\n\n");}
}
void chart(struct book *a,int n)
{for (int i = 0; i < n; i++){for (int j = 0; j < n-1; j++){if (a[j].heat<a[j+1].heat){struct book x = a[j+1];a[j + 1] = a[j];a[j] = x;                          //冒泡排序}}}for (int i = 0; i < 5; i++){printf("NO.%d\t%s\t%d\n\n", i+1, a[i].book_name, a[i].heat);}
}
void sure()
{int x;printf("点击1和回车键返回菜单\n");scanf("%d", &x);if (x==1){system("cls");}
}
void menu()
{printf("-=======================================================================================================-\n");printf("|                                 **********1.图书库*****************                                   |\n");printf("|                                 **********2.查询图书***************                                   |\n");printf("|                                 **********3.借取图书***************                                   |\n");printf("|                                 **********4.归还图书***************                                   |\n");printf("|                                 **********5.图书热度排行榜*********                                   |\n");printf("|                                 **********6.退出系统***************                                   |\n");printf("-=======================================================================================================-\n");}
int main()
{printf("==================================欢迎光临图书管理系统==================================\n\n");int total;//文件中书籍数量printf("请输入图书总量:\n");scanf("%d", &total);printf("\n请输入图书库图书数据:(如三体 01)\n");FILE* fp;if ((fp = fopen("book.txt", "w+")) == NULL){printf("\nCan't open this file!\n");exit(0);}struct book a[50], b[50];for (int i = 0; i < total; i++){scanf("%s%s", a[i].book_name, a[i].book_num);}fwrite(a, sizeof(struct book), total, fp);rewind(fp);fread(b, sizeof(struct book), total, fp);printf("\n输入的图书数据为:(图书名称 图书编号 上次借出日期 状态 热度)\n");for (int i = 0; i < total; i++){printf("%s\t%s\t%s\t%d\t%d\n", b[i].book_name, b[i].book_num, b[i].date, b[i].flag, b[i].heat);}fclose(fp);                                               //建立文件,输入书籍数据printf("\n5秒后进入菜单界面...");Sleep(5000);system("cls");loop: int choose;menu();printf("你想进行的操作是:\n");scanf("%d", &choose);int add;                        //添加的图书量struct book c[50], d[50];char find[20];                 //要查找的数据struct book data[55];if ((fp = fopen("book.txt", "a+")) == NULL){printf("\nCan't open this file!\n");exit(0);}fread(data, sizeof(struct book), total, fp);fclose(fp);                     //将文件中的数据存入dataswitch (choose){case 1:system("cls");printf("/***图书库***/\n\n");printf("请输入要添加的图书量:\n");scanf("%d", &add);total = total + add;          //新的总量if ((fp = fopen("book.txt", "a+")) == NULL){printf("\nCan't open this file!\n");exit(0);}printf("\n请输入需要添加的图书数据:(如三体 01)\n");for (int i = 0; i < add; i++){scanf("%s%s", c[i].book_name, c[i].book_num);}fseek(fp, 0, SEEK_END);fwrite(c, sizeof(struct book), add, fp);rewind(fp);fread(d, sizeof(struct book), total, fp);printf("\n更新后的图书数据为:(图书名称 图书编号 上次借出日期 状态 热度)\n");for (int i = 0; i < total; i++){printf("%s\t%s\t%s\t%d\t%d\n", d[i].book_name, d[i].book_num, d[i].date, d[i].flag, d[i].heat);}fclose(fp);         //向文件中添加书籍数据sure();goto loop;case 2:system("cls");printf("/***查询图书***/\n\n");printf("请输入您要查找的图书名称:\n");scanf("%s", find);search(data,find,total);sure();goto loop;case 3:system("cls");printf("/***借取图书***/\n\n");borrow(data,total);if ((fp = fopen("book.txt", "w+")) == NULL){printf("\nCan't open this file!\n");exit(0);}fwrite(data, sizeof(struct book), total, fp);rewind(fp);fclose(fp);                                  //向文件中添加书籍数据sure();goto loop;case 4:system("cls");printf("/***归还图书***/\n\n");returnbook(data,total);if ((fp = fopen("book.txt", "w+")) == NULL){printf("\nCan't open this file!\n");exit(0);}fwrite(data, sizeof(struct book), total, fp);rewind(fp);fclose(fp);                                  //向文件中添加书籍数据sure();goto loop;case 5:system("cls");printf("/***图书热度排行榜***/\n\n");chart(data,total);sure();goto loop;case 6:system("cls");printf("-=======================================================================================================-\n");printf("|                                 ************************************                                  |\n");printf("|                                 ************************************                                  |\n");printf("|                                 **********感谢您的使用!************                                  |\n");printf("|                                 ************************************                                  |\n");printf("|                                 ************************************                                  |\n");printf("-=======================================================================================================-\n");break;default:system("cls");printf("请输入正确的序号!\n\n");sure();goto loop;}return 0;
}

以上代码在Visual Studio 下运行

C语言课程设计——图书馆查询系统相关推荐

  1. 考勤管理系统c语言,C语言课程设计学生考勤系统最终版(范文1)

    <C语言课程设计学生考勤系统.doc>由会员分享,可免费在线阅读全文,更多与<C语言课程设计学生考勤系统(最终版)>相关文档资源请在帮帮文库(www.woc88.com)数亿文 ...

  2. C语言课程设计:通讯录系统

    C语言课程设计:通讯录系统 [题目4]通讯录程序设计 设计一个实用的小型通讯录程序,具有添加,查询和删除功能.由姓名,籍贯,电话号码1,电话号码2,电子邮箱组成,姓名可以由字符和数字混合编码.电话号码 ...

  3. c语言程序设计论文背单词系统,C语言课程设计-背单词系统(含程序)

    C语言课程设计-背单词系统(含程序) 综合性程序设计报告 设计题目: 背单词系统 指导教师: XXX 班 级: 学 号: 设 计 者: XXX 成 绩: _______________ 设计时间: 年 ...

  4. c语言课程设计作业图书管理系统,C语言课程设计图书馆管理系统程序代码.doc

    C语言课程设计图书馆管理系统程序代码.doc includestdio.h includewindows.h includestring.h includeconio.h define M 100 s ...

  5. c语言写考勤系统,C语言课程设计学生考勤系统

    <C语言课程设计学生考勤系统.doc>由会员分享,可免费在线阅读全文,更多与<C语言课程设计学生考勤系统>相关文档资源请在帮帮文库(www.woc88.com)数亿文档库存里搜 ...

  6. c语言作业制作仓库管理系统,C语言课程设计 仓库管理系统

    <C语言课程设计 仓库管理系统>由会员分享,可在线阅读,更多相关<C语言课程设计 仓库管理系统(22页珍藏版)>请在人人文库网上搜索. 1.C语言程序设计实训报告实训题目: 仓 ...

  7. c语言程序设计学生考勤系统,C语言课程设计学生考勤系统最终版(样例3)

    <C语言课程设计学生考勤系统.doc>由会员分享,可免费在线阅读全文,更多与<C语言课程设计学生考勤系统(最终版)>相关文档资源请在帮帮文库(www.woc88.com)数亿文 ...

  8. c语言单词记忆软件源码,c语言课程设计背单词系统的程序代码

    c语言课程设计背单词系统的程序代码 1综合性程序设计报告设计题目:背单词系统指导教师:班 级:学 号:设 计 者:成 绩:设计时间:2010 年 5 月 27 日2目录1 题目描述---------- ...

  9. C语言课程设计 - 火车票预订系统

    C语言课程设计 - 火车票预订系统 文件介绍 代码 main.c(全) mymac.h(全) database.c(不全) mainWindow.c (全) user.c (不全) manager.c ...

最新文章

  1. arcgis合并tif影像_微图影像地图导出拼接大图的参数说明
  2. Oracle学习笔记(1)
  3. 评估微型计算机的主要指标,微型计算机的工作过程和主要性能指标.doc
  4. C语言 满分代码:L1-044 稳赢 (15分)(解题报告)
  5. 巴巴运动网学习笔记(16-20)
  6. mysql获取逻辑日志_Mysql 逻辑架构图及日志系统
  7. 计算机中丢失api-ms-win-crt-locale,API-MS-WIN一系列丢失DLL打包
  8. 负载均衡 一直跑一个服务器_终于把服务器负载均衡和客户端负载均衡讲清楚了...
  9. 仿秒秒测日历页面和部分功能
  10. 《别做正常的傻瓜》1——结果偏见
  11. 常用数学符号大全、关系代数符号
  12. 调用阿里云身份证识别服务识别本地图片,很详细,附工具类
  13. 【无标题】关于BC25连接电信物联网平台的问题(批量产品在广东连接不到物联网平台,在合肥测试是可以的)
  14. 如何给PDF文件添加水印?PDF免费添加水印教程来了
  15. 判断字母是元音、辅音、半元音
  16. 关于使用AccountManager的remove删除Android帐号的细节
  17. 2021各显卡满载功耗天梯图 显卡能耗比天梯图
  18. 西班牙符号Ññ 乱码的问题
  19. 启动asp.net state service服务提示1058
  20. Bellhop-复杂海底地形仿真

热门文章

  1. openGauss分区表如何实现大数据量的快速转移
  2. [导入]补脾益气--四神汤
  3. 【Windows】文件批量重命名及后缀批量修改
  4. ios android 同步的备忘录,简单iOS备忘录App实现
  5. 互联网日报 | 华为发布首款商用台式机;京东健康正式登陆港交所;苹果推出首款头戴式耳机...
  6. 51单片机最小系统的相关知识
  7. RTL8201F芯片配置(LWIP_FreeRTOS)
  8. python课程编程题汇总(中)
  9. numpy—np.isnan
  10. python大一知识点总结_python 知识点总结