用c语言设计⼀个计算机管理系统完成图书管理基本业务。 【基本要求】 1)每种书的登记内容包括书号、书名、著作者、现存量和库存量; 2)对书号建⽴索引表(线性表)以提⾼查找效率; 3)系统主要功能如下: *采编⼊库:新购⼀种书,确定书号后,登记到图书帐⽬表中,如果表中已有,则只将库存量增加; *借阅:如果⼀种书的现存量⼤于0,则借出⼀本,登记借阅者的书证号和归还期限,改变现存量; *归还:注销对借阅者的登记,改变该书的现存量。
时间: 2024-03-22 13:39:49 浏览: 57
C语言实现图书管理系统,功能包含:添加图书、展示图书、寻找图书、借阅图书、归还图书、查找借阅记录、更改读者信息、查找读者信息等
以下是一个简单的图书管理系统的C语言设计,实现了基本的业务要求:
```c
#include <stdio.h>
#include <string.h>
#define MAX_BOOKS 1000
#define MAX_NAME_LEN 50
#define MAX_AUTHOR_LEN 30
typedef struct {
char book_id[10];
char book_name[MAX_NAME_LEN];
char author[MAX_AUTHOR_LEN];
int current_stock;
int total_stock;
} Book;
Book books[MAX_BOOKS];
int num_books = 0;
int find_book_index(char book_id[]) {
for (int i = 0; i < num_books; i++) {
if (strcmp(books[i].book_id, book_id) == 0) {
return i;
}
}
return -1;
}
void add_book() {
char book_id[10];
printf("Enter book ID: ");
scanf("%s", book_id);
int book_index = find_book_index(book_id);
if (book_index != -1) {
printf("Book already exists. Updating stock.\n");
printf("Enter additional stock: ");
int additional_stock;
scanf("%d", &additional_stock);
books[book_index].current_stock += additional_stock;
books[book_index].total_stock += additional_stock;
} else {
if (num_books >= MAX_BOOKS) {
printf("Maximum number of books reached.\n");
return;
}
printf("Enter book name: ");
scanf("%s", books[num_books].book_name);
printf("Enter book author: ");
scanf("%s", books[num_books].author);
printf("Enter total stock: ");
scanf("%d", &books[num_books].total_stock);
books[num_books].current_stock = books[num_books].total_stock;
strcpy(books[num_books].book_id, book_id);
num_books++;
}
}
void borrow_book() {
char book_id[10];
printf("Enter book ID: ");
scanf("%s", book_id);
int book_index = find_book_index(book_id);
if (book_index == -1) {
printf("Book not found.\n");
return;
}
if (books[book_index].current_stock <= 0) {
printf("Book not available.\n");
return;
}
printf("Enter borrower ID: ");
char borrower_id[10];
scanf("%s", borrower_id);
printf("Enter return date (DD/MM/YYYY): ");
char return_date[11];
scanf("%s", return_date);
books[book_index].current_stock--;
printf("Book borrowed successfully.\n");
}
void return_book() {
char book_id[10];
printf("Enter book ID: ");
scanf("%s", book_id);
int book_index = find_book_index(book_id);
if (book_index == -1) {
printf("Book not found.\n");
return;
}
printf("Enter borrower ID: ");
char borrower_id[10];
scanf("%s", borrower_id);
books[book_index].current_stock++;
printf("Book returned successfully.\n");
}
void print_books() {
printf("Book ID\tBook name\tAuthor\tCurrent stock\tTotal stock\n");
for (int i = 0; i < num_books; i++) {
printf("%s\t%s\t%s\t%d\t%d\n",
books[i].book_id,
books[i].book_name,
books[i].author,
books[i].current_stock,
books[i].total_stock);
}
}
int main() {
int choice;
do {
printf("Menu:\n");
printf("1. Add book\n");
printf("2. Borrow book\n");
printf("3. Return book\n");
printf("4. Print books\n");
printf("5. Exit\n");
printf("Enter choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
add_book();
break;
case 2:
borrow_book();
break;
case 3:
return_book();
break;
case 4:
print_books();
break;
case 5:
printf("Exiting...\n");
break;
default:
printf("Invalid choice. Please try again.\n");
}
} while (choice != 5);
return 0;
}
```
这个系统使用一个结构体数组来存储所有图书的信息。`find_book_index`函数可以找到给定书号的图书在数组中的索引。`add_book`函数用于添加新图书或增加某个图书的库存。`borrow_book`函数用于借出图书,`return_book`函数用于归还图书。`print_books`函数用于打印所有图书的信息。在主函数中,使用一个循环来不断显示菜单并读取用户的选择,直到用户选择退出系统。
阅读全文