用C语言写。 整个图书管理系统采用结构体作为基本数据结构,最终数据一定要保存到数据文件中。主函数通过switch 语句来根据用户的需求跳转到各个模块,以实现用户的需要。系统要求能进行图书信息的浏览、添加、查询、修改、删除和排序功能。基本要求: 1.图书信息的浏览:可打开数据文件,查看每本图书的图书条形码、书名、作者名、出版社、出版时间、定价、馆藏数量等。2.图书信息的添加:能够通过键盘录入图书条形码、书名、作者名、出版社、出版时间、定价、馆藏数量等,并将数据添加到数据文件中。3.图书信息的查询:(⑴)根据图书条形码查询2)根据书名查询(3)根据作者名查询(4)根据出版社查询,每种查询均列出查找到的所有条记录信息,且最下面需要显示出汇总信息,即共有多少条符合条件的记录。4.图书信息的修改:可根据图书条形码或书名查找出图书信息,输入是否要修改,若确认修改,则输入新的信息,再次确认后将修改后信息存储到文件中。5.图书信息的删除: (⑴)能够根据图书条形码除指定图书的记录(2)能够根据书名删除指定图书的记录,并将最终数据存储到文件中。6.图书信息的排序:(1)根据图书条形码排序(⑵)根据馆藏数量排序(3)根据出版时间排序,屏幕上显示排序后的所有图书信息。7.图书统计:(1)统计馆藏数量小于某个值的图书信息(2)统计出版日期早于某个值的图书信息。

时间: 2023-06-16 15:04:51 浏览: 80
很好,这是一个非常实用的项目。以下是一个简单的C语言代码示例,可以作为你的参考: ```c #include <stdio.h> #include <stdlib.h> #include <string.h> #define MAX_BOOKS 1000 // 图书信息结构体 typedef struct { char barcode[20]; char name[50]; char author[50]; char publisher[50]; char publish_date[20]; float price; int amount; } Book; // 图书管理系统结构体 typedef struct { Book books[MAX_BOOKS]; int count; } BookManagementSystem; // 初始化图书管理系统 void init(BookManagementSystem* system) { system->count = 0; } // 读取图书信息文件 void load_file(BookManagementSystem* system) { FILE* fp = fopen("book.dat", "rb"); if (fp != NULL) { fread(&system->count, sizeof(int), 1, fp); fread(system->books, sizeof(Book), system->count, fp); fclose(fp); } } // 保存图书信息文件 void save_file(BookManagementSystem* system) { FILE* fp = fopen("book.dat", "wb"); if (fp != NULL) { fwrite(&system->count, sizeof(int), 1, fp); fwrite(system->books, sizeof(Book), system->count, fp); fclose(fp); } } // 添加图书信息 void add_book(BookManagementSystem* system) { if (system->count >= MAX_BOOKS) { printf("Error: the book list is full!\n"); return; } Book book; printf("Barcode: "); scanf("%s", book.barcode); printf("Name: "); scanf("%s", book.name); printf("Author: "); scanf("%s", book.author); printf("Publisher: "); scanf("%s", book.publisher); printf("Publish date: "); scanf("%s", book.publish_date); printf("Price: "); scanf("%f", &book.price); printf("Amount: "); scanf("%d", &book.amount); system->books[system->count++] = book; printf("Success: the book has been added!\n"); } // 查询图书信息 void query_book(BookManagementSystem* system) { int type; char keyword[50]; printf("Query type (1: Barcode, 2: Name, 3: Author, 4: Publisher): "); scanf("%d", &type); printf("Keyword: "); scanf("%s", keyword); int count = 0; for (int i = 0; i < system->count; i++) { Book book = system->books[i]; char* str = NULL; switch (type) { case 1: str = book.barcode; break; case 2: str = book.name; break; case 3: str = book.author; break; case 4: str = book.publisher; break; default: printf("Error: invalid query type!\n"); return; } if (strstr(str, keyword) != NULL) { printf("Barcode: %s\n", book.barcode); printf("Name: %s\n", book.name); printf("Author: %s\n", book.author); printf("Publisher: %s\n", book.publisher); printf("Publish date: %s\n", book.publish_date); printf("Price: %.2f\n", book.price); printf("Amount: %d\n", book.amount); printf("----------------------------\n"); count++; } } printf("Total: %d\n", count); } // 修改图书信息 void modify_book(BookManagementSystem* system) { int type; char keyword[50]; printf("Query type (1: Barcode, 2: Name): "); scanf("%d", &type); printf("Keyword: "); scanf("%s", keyword); int index = -1; for (int i = 0; i < system->count; i++) { Book book = system->books[i]; char* str = NULL; switch (type) { case 1: str = book.barcode; break; case 2: str = book.name; break; default: printf("Error: invalid query type!\n"); return; } if (strcmp(str, keyword) == 0) { index = i; break; } } if (index < 0) { printf("Error: no book found!\n"); return; } Book book = system->books[index]; printf("Barcode: %s\n", book.barcode); printf("Name: %s\n", book.name); printf("Author: %s\n", book.author); printf("Publisher: %s\n", book.publisher); printf("Publish date: %s\n", book.publish_date); printf("Price: %.2f\n", book.price); printf("Amount: %d\n", book.amount); printf("----------------------------\n"); char confirm[10]; printf("Do you want to modify this book? (yes or no): "); scanf("%s", confirm); if (strcmp(confirm, "yes") == 0) { printf("Barcode: "); scanf("%s", book.barcode); printf("Name: "); scanf("%s", book.name); printf("Author: "); scanf("%s", book.author); printf("Publisher: "); scanf("%s", book.publisher); printf("Publish date: "); scanf("%s", book.publish_date); printf("Price: "); scanf("%f", &book.price); printf("Amount: "); scanf("%d", &book.amount); system->books[index] = book; printf("Success: the book has been modified!\n"); } } // 删除图书信息 void delete_book(BookManagementSystem* system) { int type; char keyword[50]; printf("Query type (1: Barcode, 2: Name): "); scanf("%d", &type); printf("Keyword: "); scanf("%s", keyword); int count = 0; for (int i = 0; i < system->count; i++) { Book book = system->books[i]; char* str = NULL; switch (type) { case 1: str = book.barcode; break; case 2: str = book.name; break; default: printf("Error: invalid query type!\n"); return; } if (strcmp(str, keyword) == 0) { count++; } } if (count == 0) { printf("Error: no book found!\n"); return; } Book* books = (Book*)malloc(count * sizeof(Book)); int j = 0; for (int i = 0; i < system->count; i++) { Book book = system->books[i]; char* str = NULL; switch (type) { case 1: str = book.barcode; break; case 2: str = book.name; break; default: printf("Error: invalid query type!\n"); return; } if (strcmp(str, keyword) != 0) { books[j++] = book; } } system->count = j; memcpy(system->books, books, j * sizeof(Book)); free(books); printf("Success: %d books have been deleted!\n", count); } // 排序图书信息 void sort_book(BookManagementSystem* system) { int type; printf("Sort type (1: Barcode, 2: Amount, 3: Publish date): "); scanf("%d", &type); for (int i = 0; i < system->count - 1; i++) { for (int j = i + 1; j < system->count; j++) { Book* a = &system->books[i]; Book* b = &system->books[j]; switch (type) { case 1: if (strcmp(a->barcode, b->barcode) > 0) { Book temp = *a; *a = *b; *b = temp; } break; case 2: if (a->amount < b->amount) { Book temp = *a; *a = *b; *b = temp; } break; case 3: if (strcmp(a->publish_date, b->publish_date) > 0) { Book temp = *a; *a = *b; *b = temp; } break; default: printf("Error: invalid sort type!\n"); return; } } } printf("Success: the book list has been sorted!\n"); } // 统计图书信息 void statistics_book(BookManagementSystem* system) { int type; printf("Statistics type (1: Amount, 2: Publish date): "); scanf("%d", &type); int count = 0; switch (type) { case 1: { int amount; printf("Amount: "); scanf("%d", &amount); for (int i = 0; i < system->count; i++) { if (system->books[i].amount < amount) { count++; } } printf("Total: %d\n", count); break; } case 2: { char date[20]; printf("Publish date: "); scanf("%s", date); for (int i = 0; i < system->count; i++) { if (strcmp(system->books[i].publish_date, date) < 0) { count++; } } printf("Total: %d\n", count); break; } default: printf("Error: invalid statistics type!\n"); return; } } // 显示菜单 void show_menu() { printf("Book Management System\n"); printf("-----------------------\n"); printf("1. Add book\n"); printf("2. Query book\n"); printf("3. Modify book\n"); printf("4. Delete book\n"); printf("5. Sort book\n"); printf("6. Statistics book\n"); printf("7. Exit\n"); printf("-----------------------\n"); printf("Please input your choice: "); } int main() { BookManagementSystem system; init(&system); load_file(&system); while (1) { show_menu(); int choice; scanf("%d", &choice); switch (choice) { case 1: add_book(&system); save_file(&system); break; case 2: query_book(&system); break; case 3: modify_book(&system); save_file(&system); break; case 4: delete_book(&system); save_file(&system); break; case 5: sort_book(&system); save_file(&system); break; case 6: statistics_book(&system); break; case 7: save_file(&system); exit(0); default: printf("Error: invalid choice!\n"); } } return 0; } ``` 这个代码示例实现了基本的图书管理系统功能,包括添加、查询、修改、删除、排序和统计。你可以在此基础上进行扩展和优化。注意,这个示例代码并没有考虑并发和异常处理等情况,你需要进行额外的处理来保证程序的健壮性和可靠性。

相关推荐

最新推荐

recommend-type

C语言实现简单航班管理系统

* 判断语句:我们在系统中使用了多个判断语句,例如使用if语句来判断用户的选择,使用switch语句来判断用户的操作。 * 循环语句:我们在系统中使用了多个循环语句,例如使用do-while循环来实现菜单的循环显示。 六...
recommend-type

C语言数组实现学生信息管理系统设计

系统的主函数使用switch语句来实现菜单驱动的交互式界面,用户可以选择不同的操作来实现不同的功能。 五、结论 本文介绍了使用C语言数组实现学生信息管理系统的设计,涵盖了学生信息的录入、输出、查找、排序和...
recommend-type

C语言编写教务管理系统

系统的主函数使用switch语句来选择不同的功能模块,包括录入学员信息、显示学员信息、成绩排序信息、添加学员信息、删除学员信息和退出系统。 录入模块 录入模块使用do-while循环来录入学生的基本信息,包括学号、...
recommend-type

软件工程993 数据结构与C语言程序设计考试大纲(2010版)

软件工程993 数据结构与C语言程序设计考试大纲(2010版)主要涵盖了两个核心主题:数据结构和C语言程序设计,这两部分各占考试的50%,总分为150分。以下是这两个主题的主要知识点: **数据结构部分**: 1. **概述*...
recommend-type

彩票购买系统-C语言源代码

这个系统旨在帮助学习者理解和实践C语言的基本语法和控制结构,同时涉及到文件操作、用户交互以及数据管理等概念。 1. 文件操作: - `u_loud()`、`l_loud()`和`p_loud()`函数分别用于读取用户信息文件、彩票信息...
recommend-type

BSC关键绩效财务与客户指标详解

BSC(Balanced Scorecard,平衡计分卡)是一种战略绩效管理系统,它将企业的绩效评估从传统的财务维度扩展到非财务领域,以提供更全面、深入的业绩衡量。在提供的文档中,BSC绩效考核指标主要分为两大类:财务类和客户类。 1. 财务类指标: - 部门费用的实际与预算比较:如项目研究开发费用、课题费用、招聘费用、培训费用和新产品研发费用,均通过实际支出与计划预算的百分比来衡量,这反映了部门在成本控制上的效率。 - 经营利润指标:如承保利润、赔付率和理赔统计,这些涉及保险公司的核心盈利能力和风险管理水平。 - 人力成本和保费收益:如人力成本与计划的比例,以及标准保费、附加佣金、续期推动费用等与预算的对比,评估业务运营和盈利能力。 - 财务效率:包括管理费用、销售费用和投资回报率,如净投资收益率、销售目标达成率等,反映公司的财务健康状况和经营效率。 2. 客户类指标: - 客户满意度:通过包装水平客户满意度调研,了解产品和服务的质量和客户体验。 - 市场表现:通过市场销售月报和市场份额,衡量公司在市场中的竞争地位和销售业绩。 - 服务指标:如新契约标保完成度、续保率和出租率,体现客户服务质量和客户忠诚度。 - 品牌和市场知名度:通过问卷调查、公众媒体反馈和总公司级评价来评估品牌影响力和市场认知度。 BSC绩效考核指标旨在确保企业的战略目标与财务和非财务目标的平衡,通过量化这些关键指标,帮助管理层做出决策,优化资源配置,并驱动组织的整体业绩提升。同时,这份指标汇总文档强调了财务稳健性和客户满意度的重要性,体现了现代企业对多维度绩效管理的重视。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

【实战演练】俄罗斯方块:实现经典的俄罗斯方块游戏,学习方块生成和行消除逻辑。

![【实战演练】俄罗斯方块:实现经典的俄罗斯方块游戏,学习方块生成和行消除逻辑。](https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/70a49cc62dcc46a491b9f63542110765~tplv-k3u1fbpfcp-zoom-in-crop-mark:1512:0:0:0.awebp) # 1. 俄罗斯方块游戏概述** 俄罗斯方块是一款经典的益智游戏,由阿列克谢·帕基特诺夫于1984年发明。游戏目标是通过控制不断下落的方块,排列成水平线,消除它们并获得分数。俄罗斯方块风靡全球,成为有史以来最受欢迎的视频游戏之一。 # 2.
recommend-type

卷积神经网络实现手势识别程序

卷积神经网络(Convolutional Neural Network, CNN)在手势识别中是一种非常有效的机器学习模型。CNN特别适用于处理图像数据,因为它能够自动提取和学习局部特征,这对于像手势这样的空间模式识别非常重要。以下是使用CNN实现手势识别的基本步骤: 1. **输入数据准备**:首先,你需要收集或获取一组带有标签的手势图像,作为训练和测试数据集。 2. **数据预处理**:对图像进行标准化、裁剪、大小调整等操作,以便于网络输入。 3. **卷积层(Convolutional Layer)**:这是CNN的核心部分,通过一系列可学习的滤波器(卷积核)对输入图像进行卷积,以
recommend-type

绘制企业战略地图:从财务到客户价值的六步法

"BSC资料.pdf" 战略地图是一种战略管理工具,它帮助企业将战略目标可视化,确保所有部门和员工的工作都与公司的整体战略方向保持一致。战略地图的核心内容包括四个相互关联的视角:财务、客户、内部流程和学习与成长。 1. **财务视角**:这是战略地图的最终目标,通常表现为股东价值的提升。例如,股东期望五年后的销售收入达到五亿元,而目前只有一亿元,那么四亿元的差距就是企业的总体目标。 2. **客户视角**:为了实现财务目标,需要明确客户价值主张。企业可以通过提供最低总成本、产品创新、全面解决方案或系统锁定等方式吸引和保留客户,以实现销售额的增长。 3. **内部流程视角**:确定关键流程以支持客户价值主张和财务目标的实现。主要流程可能包括运营管理、客户管理、创新和社会责任等,每个流程都需要有明确的短期、中期和长期目标。 4. **学习与成长视角**:评估和提升企业的人力资本、信息资本和组织资本,确保这些无形资产能够支持内部流程的优化和战略目标的达成。 绘制战略地图的六个步骤: 1. **确定股东价值差距**:识别与股东期望之间的差距。 2. **调整客户价值主张**:分析客户并调整策略以满足他们的需求。 3. **设定价值提升时间表**:规划各阶段的目标以逐步缩小差距。 4. **确定战略主题**:识别关键内部流程并设定目标。 5. **提升战略准备度**:评估并提升无形资产的战略准备度。 6. **制定行动方案**:根据战略地图制定具体行动计划,分配资源和预算。 战略地图的有效性主要取决于两个要素: 1. **KPI的数量及分布比例**:一个有效的战略地图通常包含20个左右的指标,且在四个视角之间有均衡的分布,如财务20%,客户20%,内部流程40%。 2. **KPI的性质比例**:指标应涵盖财务、客户、内部流程和学习与成长等各个方面,以全面反映组织的绩效。 战略地图不仅帮助管理层清晰传达战略意图,也使员工能更好地理解自己的工作如何对公司整体目标产生贡献,从而提高执行力和组织协同性。