|
|
|
|
# 图书管理系统
|
|
|
|
|
|
|
|
|
|
2023年5月21日
|
|
|
|
|
成员1:王昊 成员2:孙艺哲 成员3:张江楠 成员4:郭佳慧
|
|
|
|
|
|
|
|
|
|
## 项目简介
|
|
|
|
|
|
|
|
|
|
本系统是程序设计与问题求解课程设计项目,实现了图书管理 CSV 格式数据文件的读取和保存,以及数据的增删改查(CRUD)等功能。项目采用 C 语言编程实现,在 VS Code 集成开发环境(IDE)中用 GCC 进行编译。系统采用模块化设计,程序结构清晰,采用菜单驱动的命令行界面,操作便捷,能够用 CSV 格式读取和保存数据,通用性强,能够用图表展示数据,直观清楚。
|
|
|
|
|
下载地址:https://bdgit.educoder.net/mac76tib2/libray.git
|
|
|
|
|
项目开发过程中采用 Kanban(看板)进行任务管理和分工协作,并使用 Git 对程序代码和文档进行版本管理。任务分工情况如下:
|
|
|
|
|
| 任务 | 设计 | 开发 | 测试 | 文档 |
|
|
|
|
|
|------|-----|------|------|-----|
|
|
|
|
|
| C1 | 王昊 | 王昊 | 张江楠 | 郭佳慧 |
|
|
|
|
|
| C2·C3·C4·C5 | 张江楠 | 张江楠 | 郭佳慧 | 孙艺哲 |
|
|
|
|
|
| C6·C7·C8·C9 | 郭佳慧 | 郭佳慧 | 孙艺哲 | 王昊 |
|
|
|
|
|
| C10·C11·C12 | 孙艺哲 | 孙艺哲 | 王昊 | 张江楠 |
|
|
|
|
|
|
|
|
|
|
每个成员工作量(百分比):
|
|
|
|
|
| 王昊 | 张江楠 | 郭佳慧 | 孙艺哲 |
|
|
|
|
|
|----|---|----|----|
|
|
|
|
|
| 25 | 25 | 25 | 25 |
|
|
|
|
|
## 关于图书管理系统
|
|
|
|
|
|
|
|
|
|
建立一个图书馆管理系统,可以处理以下对象:
|
|
|
|
|
(1)图书馆基本信息
|
|
|
|
|
(2)图书馆的书籍
|
|
|
|
|
(3)图书馆管理员
|
|
|
|
|
(4)读者信息
|
|
|
|
|
|
|
|
|
|
### 需求分析
|
|
|
|
|
|
|
|
|
|
(1)查询图书馆的总信息
|
|
|
|
|
(2)查询图书馆藏书信息
|
|
|
|
|
(3)存入新书
|
|
|
|
|
(4)旧书处理
|
|
|
|
|
(5)根据书名检索书刊信息
|
|
|
|
|
(6)查询读者的借阅信息
|
|
|
|
|
(7)查询读者信息
|
|
|
|
|
(8)读者借书
|
|
|
|
|
(9)读者还书
|
|
|
|
|
(10)文件保存
|
|
|
|
|
(11)从文件读取
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## C1:函数模块
|
|
|
|
|
1.函数原形:int main();
|
|
|
|
|
2.功能:调用ShowMainMenu()函数,显示主界面
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
## C2:查询图书馆信息模块
|
|
|
|
|
|
|
|
|
|
函数原形:void ShowLibInfo(const Book* book, const Reader* reader);
|
|
|
|
|
功能:接受两个形参,分别是图书的链表地址,读者的链表地址,并遍历两个链表,显示出图书的数量和读者的数量
|
|
|
|
|
```
|
|
|
|
|
void ShowLibInfo(const Book* book1, const Reader* reader1)
|
|
|
|
|
{
|
|
|
|
|
Book* book = book1;
|
|
|
|
|
Reader* reader = reader1;
|
|
|
|
|
int bookNUm = 0, readerNUm = 0, mangerNUm = 0;
|
|
|
|
|
while (book != NULL)
|
|
|
|
|
{
|
|
|
|
|
bookNUm++;
|
|
|
|
|
book = book->next;
|
|
|
|
|
}
|
|
|
|
|
while (reader != NULL)
|
|
|
|
|
{
|
|
|
|
|
readerNUm++;
|
|
|
|
|
reader = reader->next;
|
|
|
|
|
}
|
|
|
|
|
printf("本图书馆共有藏书%d本,读者%d人\n", bookNUm, readerNUm);
|
|
|
|
|
printf("按任意键返回\n");
|
|
|
|
|
getchar();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## C3:查找图书馆藏书信息模块
|
|
|
|
|
|
|
|
|
|
1) 函数原形: void ShowLibBook(Book* book);
|
|
|
|
|
2) 功能: 接受一个形参:图书的链表地址,遍历该链表,显示出所有图书的信息
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## C4:存入新书信息模块
|
|
|
|
|
|
|
|
|
|
1) 函数原形: Book* AddBook(Book* book);
|
|
|
|
|
2) 功能: 接受一个形参:图书的链表地址,利用尾插对链表进行修改,添加图书
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## C5:旧书处理信息模块
|
|
|
|
|
|
|
|
|
|
1)函数原形: Book* DealoldBook(Book* book);
|
|
|
|
|
2) 功能: 接受一个形参:图书链表的地址,遍历该链表,用书的编号进行匹配,找到该图书后删除该图书,否则返回
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## C6:查找图书信息模块
|
|
|
|
|
|
|
|
|
|
1)函数原形: void foundBook(Book* book);
|
|
|
|
|
2) 功能:接受一个形参:图书链表的地址,遍历该链表,用书的编号进行匹配,找到该图书后显示该图书,否则返回
|
|
|
|
|
```
|
|
|
|
|
void foundBook(Book* book1)
|
|
|
|
|
{
|
|
|
|
|
Book* book = book1;
|
|
|
|
|
printf("输入要查找的书的id:");
|
|
|
|
|
int id;
|
|
|
|
|
scanf("%d", &id);
|
|
|
|
|
getchar();
|
|
|
|
|
while (book != NULL)
|
|
|
|
|
{
|
|
|
|
|
if (id == book->iNum)
|
|
|
|
|
{
|
|
|
|
|
printf("该书的信息如下:\n");
|
|
|
|
|
printf("%d\t%s\t%s\t%s\t%d\n", book->iNum, book->acName, book->acAuthor, book->acPress, book->iAmount);
|
|
|
|
|
printf("按任意键返回\n");
|
|
|
|
|
getchar();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
book = book->next;
|
|
|
|
|
}
|
|
|
|
|
printf("没有找到该书!\n");
|
|
|
|
|
printf("按任意键返回\n");
|
|
|
|
|
getchar();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## C7:查询读者借阅信息模块
|
|
|
|
|
|
|
|
|
|
1)函数原形: void foundReader_Info(Reader* reader);
|
|
|
|
|
2) 功能: 接受一个形参:读者链表的地址,遍历该链表,用读者的编号进行匹配,找到该读者显示该读者的信息,否则返回
|
|
|
|
|
```
|
|
|
|
|
void foundReader_Info(Reader* reader1)
|
|
|
|
|
{
|
|
|
|
|
Reader* reader = reader1; //备份
|
|
|
|
|
printf("输入读者的id:");
|
|
|
|
|
int id;
|
|
|
|
|
scanf("%d", &id);
|
|
|
|
|
getchar();
|
|
|
|
|
while (reader)
|
|
|
|
|
{
|
|
|
|
|
if (id == reader->iNum)
|
|
|
|
|
{
|
|
|
|
|
printf("借阅的书的编号如下:\n");
|
|
|
|
|
for (int i = 0; i < reader->iMax; i++) //根据读者可以借阅的数量作为循环终止条件
|
|
|
|
|
{
|
|
|
|
|
if (reader->aiBookId[i] != 0) //数组里不为0,证明有一条记录,因为:数组初始化为0,并且书的编号不可能为0
|
|
|
|
|
{
|
|
|
|
|
printf("%d\n", reader->aiBookId[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
printf("按任意键返回\n");
|
|
|
|
|
getchar();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
reader = reader->next;
|
|
|
|
|
}
|
|
|
|
|
printf("没有该读者!\n");
|
|
|
|
|
printf("按任意键返回\n");
|
|
|
|
|
getchar();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## C8:查询读者借书模块
|
|
|
|
|
|
|
|
|
|
1)函数原形: void foundReaderInfo(Reader* reader);
|
|
|
|
|
2)功能: 接受一个形参:读者链表的地址,遍历该链表,用读者的编号进行匹配,找到该读者显示该读者的借阅信息,否则返回
|
|
|
|
|
```
|
|
|
|
|
void foundReaderInfo(Reader* reader1)
|
|
|
|
|
{
|
|
|
|
|
Reader* reader = reader1;
|
|
|
|
|
printf("输入读者的id:");
|
|
|
|
|
int id;
|
|
|
|
|
scanf("%d", &id);
|
|
|
|
|
getchar();
|
|
|
|
|
while (reader)
|
|
|
|
|
{
|
|
|
|
|
if (id == reader->iNum)
|
|
|
|
|
{
|
|
|
|
|
printf("读者id:%d\n", reader->iNum);
|
|
|
|
|
printf("读者姓名:%s\n", reader->acName);
|
|
|
|
|
printf("读者性别:%s\n", reader->acSex);
|
|
|
|
|
printf("读者职位:%s\n", reader->position);
|
|
|
|
|
printf("读者已借阅书的数量:%d\n", reader->iAmount);
|
|
|
|
|
printf("按任意键返回\n");
|
|
|
|
|
getchar();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
reader = reader->next;
|
|
|
|
|
}
|
|
|
|
|
printf("没有找到该读者\n");
|
|
|
|
|
printf("按任意键返回\n");
|
|
|
|
|
getchar();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## C9:读者借书模块
|
|
|
|
|
|
|
|
|
|
1)函数原形: Reader* LendBook(Reader* reader, Book* book);
|
|
|
|
|
2)功能:接受两个形参:读者链表地址和图书链表地址,用读者的编号进行匹配,找到该读者后,用图书的编号进行匹配,进行借书,否则返回
|
|
|
|
|
```
|
|
|
|
|
Reader* LendBook(Reader* reader1, Book* book1)
|
|
|
|
|
{
|
|
|
|
|
Reader* reader = reader1;
|
|
|
|
|
Book* book = book1;
|
|
|
|
|
Reader* prev = reader1;
|
|
|
|
|
Reader* tmpp = reader1;
|
|
|
|
|
printf("输入读者id:");
|
|
|
|
|
int id;
|
|
|
|
|
scanf("%d", &id);
|
|
|
|
|
getchar();
|
|
|
|
|
if (reader == NULL)
|
|
|
|
|
{
|
|
|
|
|
Reader* tmp = (Reader*)malloc(sizeof(Reader));
|
|
|
|
|
tmp->next = NULL;
|
|
|
|
|
tmp->iAmount = 0;
|
|
|
|
|
tmp->iNum = id;
|
|
|
|
|
printf("输入读者名字:");
|
|
|
|
|
scanf("%s", &tmp->acName);
|
|
|
|
|
getchar();
|
|
|
|
|
printf("输入读者性别:");
|
|
|
|
|
scanf("%s", &tmp->acSex);
|
|
|
|
|
getchar();
|
|
|
|
|
printf("输入读者职位:<student\tor\tteacher>");
|
|
|
|
|
scanf("%s", &tmp->position);
|
|
|
|
|
getchar();
|
|
|
|
|
if (strcmp(tmp->position, "student") == 0)
|
|
|
|
|
{
|
|
|
|
|
tmp->iMax = 20;
|
|
|
|
|
tmp->day = 30;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
tmp->iMax = 40;
|
|
|
|
|
tmp->day = 60;
|
|
|
|
|
}
|
|
|
|
|
for (int i = 0; i < tmp->iMax; i++)
|
|
|
|
|
{
|
|
|
|
|
tmp->aiBookId[i] = 0;
|
|
|
|
|
}
|
|
|
|
|
printf("输入要借的书的编号:");
|
|
|
|
|
int id_book;
|
|
|
|
|
scanf("%d", &id_book);
|
|
|
|
|
getchar();
|
|
|
|
|
while (book != NULL)
|
|
|
|
|
{
|
|
|
|
|
if (id_book == book->iNum)
|
|
|
|
|
{
|
|
|
|
|
if (book->iAmount <= 1)
|
|
|
|
|
{
|
|
|
|
|
printf("借阅失败,该图书库存不足.\n");
|
|
|
|
|
printf("按任意键返回\n");
|
|
|
|
|
getchar();
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
if ((tmp->iAmount) + 1 > tmp->iMax)
|
|
|
|
|
{
|
|
|
|
|
printf("借阅失败,该读者借阅图书数量已达上线.\n");
|
|
|
|
|
printf("按任意键返回\n");
|
|
|
|
|
getchar();
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
book->iAmount--;
|
|
|
|
|
tmp->aiBookId[tmp->iAmount] = id_book;
|
|
|
|
|
tmp->iAmount;
|
|
|
|
|
reader = tmp;
|
|
|
|
|
printf("借阅成功!\n");
|
|
|
|
|
printf("按任意键返回\n");
|
|
|
|
|
getchar();
|
|
|
|
|
return reader;
|
|
|
|
|
}
|
|
|
|
|
book = book->next;
|
|
|
|
|
}
|
|
|
|
|
printf("没有找到该书!\n");
|
|
|
|
|
printf("按任意键返回\n");
|
|
|
|
|
getchar();
|
|
|
|
|
return reader1;
|
|
|
|
|
}
|
|
|
|
|
if (reader != NULL)
|
|
|
|
|
{
|
|
|
|
|
while (reader != NULL)
|
|
|
|
|
{
|
|
|
|
|
if (id == reader->iNum)
|
|
|
|
|
{
|
|
|
|
|
printf("图使馆当前的书籍册:\n");
|
|
|
|
|
ShowLibBook(book);
|
|
|
|
|
printf("输入要借的书的编号:");
|
|
|
|
|
int id_book;
|
|
|
|
|
scanf("%d", &id_book);
|
|
|
|
|
getchar();
|
|
|
|
|
while (book != NULL)
|
|
|
|
|
{
|
|
|
|
|
if (id_book == book->iNum)
|
|
|
|
|
{
|
|
|
|
|
if (book->iAmount <= 1)
|
|
|
|
|
{
|
|
|
|
|
printf("借阅失败,该图书库存不足.\n");
|
|
|
|
|
printf("按任意键返回\n");
|
|
|
|
|
getchar();
|
|
|
|
|
return reader1;
|
|
|
|
|
}
|
|
|
|
|
if (tmpp->iAmount + 1 > tmpp->iMax)
|
|
|
|
|
{
|
|
|
|
|
printf("借阅失败,该读者借阅图书数量已达上线.\n");
|
|
|
|
|
printf("按任意键返回\n");
|
|
|
|
|
getchar();
|
|
|
|
|
return reader1;
|
|
|
|
|
}
|
|
|
|
|
reader->iAmount++;
|
|
|
|
|
reader->aiBookId[tmpp->iAmount] = id_book;
|
|
|
|
|
return reader1;
|
|
|
|
|
}
|
|
|
|
|
book = book->next;
|
|
|
|
|
}
|
|
|
|
|
printf("没有找到该书!\n");
|
|
|
|
|
printf("按任意键返回\n");
|
|
|
|
|
}
|
|
|
|
|
reader = reader->next;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## C10:读者还书模块
|
|
|
|
|
|
|
|
|
|
函数原形:void returnBook(Reader* reader, Book* book);
|
|
|
|
|
功能:接受两个形参:读者链表地址和图书链表地址,用读者的编号进行匹配,找到该读者后,用图书的编号进行匹配,进行还书,否则返回
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
## C11:保存信息模块
|
|
|
|
|
|
|
|
|
|
1)函数原形: void save(Book* book);
|
|
|
|
|
2) 功能:接受一个形参:book的链表地址,新建一个文件,将链表中的信息保存到硬盘中
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## C12:读取信息模块
|
|
|
|
|
|
|
|
|
|
1)函数原形: Book* read1();
|
|
|
|
|
2) 功能:打开一个文件,将文件中的信息读取到内存中,并返回一个Book类型的指针
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## 概要设计
|
|
|
|
|
系统主要为开始界面和数据处理两大模块
|
|
|
|
|
开始界面即显示主要功能
|
|
|
|
|
数据处理包括:
|
|
|
|
|
查询图书馆的总信息
|
|
|
|
|
查询图书馆藏书信息
|
|
|
|
|
存入新书
|
|
|
|
|
旧书处理
|
|
|
|
|
根据书名检索书刊信息
|
|
|
|
|
查询读者的借阅信息
|
|
|
|
|
查询读者信息
|
|
|
|
|
读者借书
|
|
|
|
|
读者还书
|
|
|
|
|
文件保存
|
|
|
|
|
从文件读取
|
|
|
|
|
上述各模块通过主程序(main)进行调用,系统模块图如下:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## 详细设计
|
|
|
|
|
针对概要设计
|
|
|
|
|
|
|
|
|
|
C2:void ShowLibInfo(const Book* book, const Reader* reader);\\查询图书馆的总信息
|
|
|
|
|
![C2](c2.svg)
|
|
|
|
|
C3:void ShowLibBook(Book* book);\\查询图书馆藏书信息
|
|
|
|
|
|
|
|
|
|
C4:Book* AddBook(Book* book);\\存入新书
|
|
|
|
|
|
|
|
|
|
C5:Book* DealoldBook(Book* book);\\旧书处理
|
|
|
|
|
|
|
|
|
|
C6:void foundBook(Book* book);\\根据书名检索书刊信息
|
|
|
|
|
![C6](images/foundbook.svg)
|
|
|
|
|
|
|
|
|
|
C7:void foundReader_Info(Reader* reader);\\查询读者的借阅信息
|
|
|
|
|
![C7](images/foundreaderinfo.svg)
|
|
|
|
|
C8:void foundReaderInfo(Reader* reader);\\查询读者信息
|
|
|
|
|
![C8](images/ReaderInfo.svg)
|
|
|
|
|
C9:Reader* LendBook(Reader* reader, Book* book);\\读者借书
|
|
|
|
|
![C9](images/LendBook.svg)
|
|
|
|
|
C10:void returnBook(Reader* reader, Book* book);\\读者还书
|
|
|
|
|
![C10](images/returnBook.svg)
|
|
|
|
|
C11:void save(Book* book);\\文件保存
|
|
|
|
|
![C11](images/save.svg)
|
|
|
|
|
C12:Book* read1();\\从文件读取
|
|
|
|
|
|