你来设计一个图书管理系统并包含代码
时间: 2023-04-02 15:05:10 浏览: 56
好的,我可以回答这个问题。一个图书管理系统需要包含以下功能:
1. 添加图书:管理员可以添加新的图书到系统中,包括书名、作者、出版社、ISBN 码、分类等信息。
2. 删除图书:管理员可以删除系统中的图书。
3. 修改图书信息:管理员可以修改系统中图书的信息,包括书名、作者、出版社、ISBN 码、分类等信息。
4. 查询图书:用户可以通过关键字搜索图书,也可以按照分类、作者等条件进行筛选。
5. 借阅图书:用户可以借阅图书,系统会记录借阅时间和归还时间。
6. 归还图书:用户可以归还已经借阅的图书。
以下是一个简单的图书管理系统的代码示例:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_BOOKS 100
struct Book {
char title[100];
char author[100];
char publisher[100];
char isbn[20];
char category[50];
int borrowed;
};
struct Book books[MAX_BOOKS];
int num_books = ;
void add_book() {
struct Book book;
printf("请输入书名:");
scanf("%s", book.title);
printf("请输入作者:");
scanf("%s", book.author);
printf("请输入出版社:");
scanf("%s", book.publisher);
printf("请输入 ISBN 码:");
scanf("%s", book.isbn);
printf("请输入分类:");
scanf("%s", book.category);
book.borrowed = ;
books[num_books++] = book;
printf("添加成功!\n");
}
void delete_book() {
char isbn[20];
printf("请输入要删除的图书的 ISBN 码:");
scanf("%s", isbn);
int i;
for (i = ; i < num_books; i++) {
if (strcmp(books[i].isbn, isbn) == ) {
int j;
for (j = i; j < num_books - 1; j++) {
books[j] = books[j + 1];
}
num_books--;
printf("删除成功!\n");
return;
}
}
printf("找不到该图书!\n");
}
void modify_book() {
char isbn[20];
printf("请输入要修改的图书的 ISBN 码:");
scanf("%s", isbn);
int i;
for (i = ; i < num_books; i++) {
if (strcmp(books[i].isbn, isbn) == ) {
printf("请输入新的书名:");
scanf("%s", books[i].title);
printf("请输入新的作者:");
scanf("%s", books[i].author);
printf("请输入新的出版社:");
scanf("%s", books[i].publisher);
printf("请输入新的分类:");
scanf("%s", books[i].category);
printf("修改成功!\n");
return;
}
}
printf("找不到该图书!\n");
}
void search_book() {
char keyword[100];
printf("请输入关键字:");
scanf("%s", keyword);
int i;
for (i = ; i < num_books; i++) {
if (strstr(books[i].title, keyword) != NULL ||
strstr(books[i].author, keyword) != NULL ||
strstr(books[i].publisher, keyword) != NULL ||
strstr(books[i].isbn, keyword) != NULL ||
strstr(books[i].category, keyword) != NULL) {
printf("%s\t%s\t%s\t%s\t%s\t%s\n",
books[i].title, books[i].author, books[i].publisher,
books[i].isbn, books[i].category, books[i].borrowed ? "已借出" : "未借出");
}
}
}
void borrow_book() {
char isbn[20];
printf("请输入要借阅的图书的 ISBN 码:");
scanf("%s", isbn);
int i;
for (i = ; i < num_books; i++) {
if (strcmp(books[i].isbn, isbn) == ) {
if (books[i].borrowed) {
printf("该图书已经借出!\n");
} else {
books[i].borrowed = 1;
printf("借阅成功!\n");
}
return;
}
}
printf("找不到该图书!\n");
}
void return_book() {
char isbn[20];
printf("请输入要归还的图书的 ISBN 码:");
scanf("%s", isbn);
int i;
for (i = ; i < num_books; i++) {
if (strcmp(books[i].isbn, isbn) == ) {
if (books[i].borrowed) {
books[i].borrowed = ;
printf("归还成功!\n");
} else {
printf("该图书未借出!\n");
}
return;
}
}
printf("找不到该图书!\n");
}
void print_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() {
int choice;
do {
print_menu();
printf("请选择操作:");
scanf("%d", &choice);
switch (choice) {
case 1:
add_book();
break;
case 2:
delete_book();
break;
case 3:
modify_book();
break;
case 4:
search_book();
break;
case 5:
borrow_book();
break;
case 6:
return_book();
break;
case :
printf("谢谢使用!\n");
break;
default:
printf("无效的选择!\n");
break;
}
} while (choice != );
return ;
}
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)