c语言实现某班级的图书信息管理,图书的基本信息包括书号、书名、作者、单价、数量和简介(50字内)等。源代码

时间: 2023-07-10 09:19:39 浏览: 52
好的,以下是一个简单的 C 语言程序,可以实现图书信息管理系统的基本功能。请注意,这只是一个基本的示例,您可以根据需要进行修改和扩展。 ```c #include <stdio.h> #include <string.h> #define MAX_BOOKS 100 #define MAX_DESCRIPTION 50 struct Book { char number[20]; char name[50]; char author[20]; float price; int quantity; char description[MAX_DESCRIPTION]; }; struct Book books[MAX_BOOKS]; int num_books = 0; void add_book() { if (num_books == MAX_BOOKS) { printf("Error: the maximum number of books has been reached.\n"); return; } struct Book new_book; printf("Enter the book number: "); scanf("%s", new_book.number); printf("Enter the book name: "); scanf("%s", new_book.name); printf("Enter the book author: "); scanf("%s", new_book.author); printf("Enter the book price: "); scanf("%f", &new_book.price); printf("Enter the book quantity: "); scanf("%d", &new_book.quantity); printf("Enter the book description (50 characters or less): "); scanf("%s", new_book.description); books[num_books] = new_book; num_books++; printf("The book has been added successfully.\n"); } void search_book() { char keyword[50]; printf("Enter the keyword to search: "); scanf("%s", keyword); int found = 0; for (int i = 0; i < num_books; i++) { if (strstr(books[i].name, keyword) != NULL || strstr(books[i].author, keyword) != NULL) { printf("Book number: %s\n", books[i].number); printf("Book name: %s\n", books[i].name); printf("Book author: %s\n", books[i].author); printf("Book price: %f\n", books[i].price); printf("Book quantity: %d\n", books[i].quantity); printf("Book description: %s\n", books[i].description); printf("\n"); found = 1; } } if (!found) { printf("No matching books found.\n"); } } void list_books() { if (num_books == 0) { printf("No books found.\n"); return; } printf("Book list:\n"); for (int i = 0; i < num_books; i++) { printf("Book number: %s\n", books[i].number); printf("Book name: %s\n", books[i].name); printf("Book author: %s\n", books[i].author); printf("Book price: %f\n", books[i].price); printf("Book quantity: %d\n", books[i].quantity); printf("Book description: %s\n", books[i].description); printf("\n"); } } int main() { int choice; do { printf("1. Add a book\n"); printf("2. Search for a book\n"); printf("3. List all books\n"); printf("4. Exit\n"); printf("Enter your choice (1-4): "); scanf("%d", &choice); switch (choice) { case 1: add_book(); break; case 2: search_book(); break; case 3: list_books(); break; case 4: printf("Exiting the program.\n"); break; default: printf("Invalid choice. Please try again.\n"); break; } } while (choice != 4); return 0; } ``` 这个程序使用结构体来表示每本书的信息。它提供了三个主要功能:添加新书、搜索书籍和列出所有书籍。您可以根据需要添加其他功能,如删除书籍和更新书籍信息。

相关推荐

最新推荐

recommend-type

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

主要为大家详细介绍了C语言数组实现学生信息管理系统设计,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
recommend-type

大一C语言课程设计图书信息管理系统.doc

大一C语言课程设计图书信息管理系统.doc
recommend-type

C语言实现班档案管理系统课程设计

主要为大家详细介绍了C语言实现班档案管理系统课程设计,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
recommend-type

C语言实现餐饮结账管理系统

主要为大家详细介绍了C语言实现餐饮结账管理系统,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
recommend-type

C语言图书管理系统简洁版

主要为大家详细介绍了C语言图书管理系统简洁版,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
recommend-type

zigbee-cluster-library-specification

最新的zigbee-cluster-library-specification说明文档。
recommend-type

管理建模和仿真的文件

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

实现实时数据湖架构:Kafka与Hive集成

![实现实时数据湖架构:Kafka与Hive集成](https://img-blog.csdnimg.cn/img_convert/10eb2e6972b3b6086286fc64c0b3ee41.jpeg) # 1. 实时数据湖架构概述** 实时数据湖是一种现代数据管理架构,它允许企业以低延迟的方式收集、存储和处理大量数据。与传统数据仓库不同,实时数据湖不依赖于预先定义的模式,而是采用灵活的架构,可以处理各种数据类型和格式。这种架构为企业提供了以下优势: - **实时洞察:**实时数据湖允许企业访问最新的数据,从而做出更明智的决策。 - **数据民主化:**实时数据湖使各种利益相关者都可
recommend-type

2. 通过python绘制y=e-xsin(2πx)图像

可以使用matplotlib库来绘制这个函数的图像。以下是一段示例代码: ```python import numpy as np import matplotlib.pyplot as plt def func(x): return np.exp(-x) * np.sin(2 * np.pi * x) x = np.linspace(0, 5, 500) y = func(x) plt.plot(x, y) plt.xlabel('x') plt.ylabel('y') plt.title('y = e^{-x} sin(2πx)') plt.show() ``` 运行这段
recommend-type

JSBSim Reference Manual

JSBSim参考手册,其中包含JSBSim简介,JSBSim配置文件xml的编写语法,编程手册以及一些应用实例等。其中有部分内容还没有写完,估计有生之年很难看到完整版了,但是内容还是很有参考价值的。