c语言链表编译图书管理系统,系统包含入库时间、入库量、借阅量、借阅时间
时间: 2023-08-10 18:04:37 浏览: 134
C语言链表实现图书管理系统
好的,我可以为您解答关于使用C语言链表编写图书管理系统的问题。
首先,我们需要定义一个结构体来存储每一本书的相关信息,包括入库时间、入库量、借阅量、借阅时间等。例如:
```
struct Book {
char name[50]; // 书名
char author[50]; // 作者
char publisher[50]; // 出版社
int publishYear; // 出版年份
int stock; // 入库量
int borrow; // 借阅量
char borrowTime[20]; // 借阅时间
struct Book *next; // 指向下一本书的指针
};
```
然后,我们可以定义一个链表来存储所有的书籍,每个节点都是一个Book结构体。例如:
```
struct BookList {
struct Book *head; // 链表头指针
int count; // 书籍数量
};
```
接下来,我们可以实现一些常用的图书管理功能,例如:
1. 添加一本书:
```
void addBook(struct BookList *list, struct Book *book) {
book->next = list->head;
list->head = book;
list->count++;
}
```
2. 删除一本书:
```
void deleteBook(struct BookList *list, char *name) {
struct Book *prev = NULL;
struct Book *curr = list->head;
while (curr != NULL) {
if (strcmp(curr->name, name) == 0) {
if (prev == NULL) {
list->head = curr->next;
} else {
prev->next = curr->next;
}
free(curr);
list->count--;
return;
}
prev = curr;
curr = curr->next;
}
}
```
3. 借阅一本书:
```
void borrowBook(struct BookList *list, char *name, char *borrowTime) {
struct Book *curr = list->head;
while (curr != NULL) {
if (strcmp(curr->name, name) == 0) {
curr->borrow++;
strcpy(curr->borrowTime, borrowTime);
return;
}
curr = curr->next;
}
}
```
4. 归还一本书:
```
void returnBook(struct BookList *list, char *name) {
struct Book *curr = list->head;
while (curr != NULL) {
if (strcmp(curr->name, name) == 0) {
curr->borrow--;
return;
}
curr = curr->next;
}
}
```
5. 显示所有书籍:
```
void displayBooks(struct BookList *list) {
struct Book *curr = list->head;
while (curr != NULL) {
printf("书名:%s\n", curr->name);
printf("作者:%s\n", curr->author);
printf("出版社:%s\n", curr->publisher);
printf("出版年份:%d\n", curr->publishYear);
printf("入库量:%d\n", curr->stock);
printf("借阅量:%d\n", curr->borrow);
printf("借阅时间:%s\n", curr->borrowTime);
printf("\n");
curr = curr->next;
}
}
```
以上是一个简单的图书管理系统的实现,您可以根据自己的需求进行修改和扩展。
阅读全文