图书管理系统c语言课程设计ISBN
时间: 2023-07-13 09:32:51 浏览: 90
好的,以下是一个简单的图书管理系统的C语言代码,可以实现添加、删除、查找和显示书籍信息等功能,同时支持按ISBN进行管理:
```
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_BOOKS 100
struct book {
char name[50];
char author[50];
char publisher[50];
char ISBN[20];
int quantity;
float price;
};
struct book books[MAX_BOOKS];
int num_books = 0;
void add_book() {
if (num_books >= MAX_BOOKS) {
printf("The library is full!\n");
return;
}
printf("Enter book name: ");
scanf("%s", books[num_books].name);
printf("Enter author name: ");
scanf("%s", books[num_books].author);
printf("Enter publisher name: ");
scanf("%s", books[num_books].publisher);
printf("Enter ISBN: ");
scanf("%s", books[num_books].ISBN);
printf("Enter quantity: ");
scanf("%d", &books[num_books].quantity);
printf("Enter price: ");
scanf("%f", &books[num_books].price);
num_books++;
printf("Book added successfully!\n");
}
void delete_book() {
char ISBN[20];
printf("Enter ISBN of the book to delete: ");
scanf("%s", ISBN);
for (int i = 0; i < num_books; i++) {
if (strcmp(books[i].ISBN, ISBN) == 0) {
for (int j = i; j < num_books - 1; j++) {
books[j] = books[j + 1];
}
num_books--;
printf("Book deleted successfully!\n");
return;
}
}
printf("Book not found!\n");
}
void search_book() {
char ISBN[20];
printf("Enter ISBN of the book to search: ");
scanf("%s", ISBN);
for (int i = 0; i < num_books; i++) {
if (strcmp(books[i].ISBN, ISBN) == 0) {
printf("Book name: %s\n", books[i].name);
printf("Author name: %s\n", books[i].author);
printf("Publisher name: %s\n", books[i].publisher);
printf("ISBN: %s\n", books[i].ISBN);
printf("Quantity: %d\n", books[i].quantity);
printf("Price: %.2f\n", books[i].price);
return;
}
}
printf("Book not found!\n");
}
void display_books() {
printf("All books:\n");
for (int i = 0; i < num_books; i++) {
printf("Book name: %s\n", books[i].name);
printf("Author name: %s\n", books[i].author);
printf("Publisher name: %s\n", books[i].publisher);
printf("ISBN: %s\n", books[i].ISBN);
printf("Quantity: %d\n", books[i].quantity);
printf("Price: %.2f\n", books[i].price);
printf("\n");
}
}
int main() {
int choice;
while (1) {
printf("1. Add book\n");
printf("2. Delete book\n");
printf("3. Search book\n");
printf("4. Display all books\n");
printf("5. Exit\n");
printf("Enter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
add_book();
break;
case 2:
delete_book();
break;
case 3:
search_book();
break;
case 4:
display_books();
break;
case 5:
printf("Goodbye!\n");
return 0;
default:
printf("Invalid choice!\n");
break;
}
}
}
```
该代码可以通过简单的命令行界面来进行操作,支持最多存储100本书籍的信息。您可以根据需要进行修改和优化,实现更加完善的图书管理系统。
相关推荐
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.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)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)