|
|
#define _CRT_SECURE_NO_WARNINGS
|
|
|
#include <stdio.h>
|
|
|
#include <conio.h> /*getch()函数使用的头文件*/
|
|
|
#include <windows.h> /*Sleep()函数使用的头文件*/
|
|
|
#include <string.h> /*strcmp()函数使用的头文件*/
|
|
|
#include<assert.h>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*图书结构体:图书编号,图书名,图书作者,出版社,库存量*/
|
|
|
typedef struct Book
|
|
|
{
|
|
|
int iNum;
|
|
|
char acName[15];
|
|
|
char acAuthor[15];
|
|
|
char acPress[15];
|
|
|
int iAmount;
|
|
|
struct Book* next;
|
|
|
}Book;
|
|
|
|
|
|
/*读者:读者编号,读者姓名,性别,可借书数,读者已借书的编号*/
|
|
|
typedef struct Reader
|
|
|
{
|
|
|
int iNum;
|
|
|
char acName[15];
|
|
|
char acSex[4];
|
|
|
char position[20];
|
|
|
int iMax; //Student 20本 teacher 40本
|
|
|
int iAmount;
|
|
|
int aiBookId[100];
|
|
|
int balance;
|
|
|
int day;
|
|
|
struct Reader* next;
|
|
|
}Reader;
|
|
|
|
|
|
|
|
|
void ShowLibInfo(const Book* book, const Reader* reader);
|
|
|
void ShowLibBook(Book* book);
|
|
|
Book* AddBook(Book* book);
|
|
|
Book* DealoldBook(Book* book);
|
|
|
void foundBook(Book* book);
|
|
|
void foundReader_Info(Reader* reader);
|
|
|
void foundReaderInfo(Reader* reader);
|
|
|
Reader* LendBook(Reader* reader, Book* book);
|
|
|
void returnBook(Reader* reader, Book* book);
|
|
|
void save(Book* book);
|
|
|
Book* read1();
|
|
|
|
|
|
|
|
|
void ShowMainMenu()
|
|
|
{
|
|
|
system("cls");
|
|
|
printf("\n\n\n\n\n");
|
|
|
printf("\t|----------------------欢迎进入---------------------------\n");
|
|
|
printf("\t| 读者管理系统 \n");
|
|
|
printf("\t| 1、查询图书馆的总信息 \n");
|
|
|
printf("\t| 2、查询图书馆藏书信息 \n");
|
|
|
printf("\t| 3、存入新书 \n");
|
|
|
printf("\t| 4、旧书处理 \n");
|
|
|
printf("\t| 5、根据书名检索书刊信息 \n");
|
|
|
printf("\t| 6、查询读者的借阅信息 \n");
|
|
|
printf("\t| 7、查询读者信息 \n");
|
|
|
printf("\t| 8、读者借书 \n");
|
|
|
printf("\t| 9、读者还书 \n");
|
|
|
printf("\t| 10、文件保存 \n");
|
|
|
printf("\t| 11、从文件读取 \n");
|
|
|
printf("\t| 0、退出 \n");
|
|
|
printf("\t|---------------------------------------------------------\n");
|
|
|
printf("新打开程序需先添加管理员\n");
|
|
|
printf("\n");
|
|
|
printf("\t\t请选择(0-11):");
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int main()
|
|
|
{
|
|
|
Book* book = NULL;
|
|
|
Reader* reader = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
int iItem;
|
|
|
ShowMainMenu();/*调用ShowMainMenu函数绘制界面*/
|
|
|
scanf("%d", &iItem);/*提示用户输入数字*/
|
|
|
getchar();
|
|
|
while (1)
|
|
|
{
|
|
|
switch (iItem)
|
|
|
{
|
|
|
case 0:return 0;
|
|
|
break;
|
|
|
case 1:ShowLibInfo(book, reader);
|
|
|
break;
|
|
|
case 2:ShowLibBook(book);
|
|
|
break;
|
|
|
case 3:book = AddBook(book);
|
|
|
break;
|
|
|
case 4:book = DealoldBook(book);
|
|
|
break;
|
|
|
case 5:foundBook(book);
|
|
|
break;
|
|
|
case 6:foundReader_Info(reader);
|
|
|
break;
|
|
|
case 7:foundReaderInfo(reader);
|
|
|
break;
|
|
|
case 8:reader = LendBook(reader, book);
|
|
|
break;
|
|
|
case 9:returnBook(reader, book);
|
|
|
break;
|
|
|
case 10:save(book);
|
|
|
break;
|
|
|
case 11:book = read1();
|
|
|
break;
|
|
|
default:
|
|
|
printf("\t输入有误,请重新输入!\n");
|
|
|
Sleep(2000);
|
|
|
}
|
|
|
ShowMainMenu();/*调用ShowMainMenu函数绘制界面*/
|
|
|
scanf("%d", &iItem);/*提示用户输入数字*/
|
|
|
getchar();
|
|
|
}
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
|
|
|
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;
|
|
|
}
|
|
|
|
|
|
void ShowLibBook(Book* book1)
|
|
|
{
|
|
|
Book* book = book1;
|
|
|
while (book != NULL)
|
|
|
{ // \t :制表符
|
|
|
printf("%d\t%s\t%s\t%s\t%d\n", book->iNum, book->acName, book->acAuthor, book->acPress, book->iAmount);
|
|
|
book = book->next;
|
|
|
}
|
|
|
printf("\n按任意键返回\n");
|
|
|
getchar();
|
|
|
return;
|
|
|
}
|
|
|
Book* AddBook(Book* book1)
|
|
|
{
|
|
|
Book* book = book1;
|
|
|
|
|
|
if (book == NULL)
|
|
|
{
|
|
|
|
|
|
Book* tmp = (Book*)malloc(sizeof(Book));
|
|
|
tmp->next = NULL;
|
|
|
assert(tmp);
|
|
|
printf("输入书的编号:");
|
|
|
scanf("%d", &tmp->iNum);
|
|
|
getchar();
|
|
|
printf("输入书的名称:");
|
|
|
gets(&tmp->acName);
|
|
|
printf("输入书的作者:");
|
|
|
gets(tmp->acAuthor);
|
|
|
printf("输入书的出版社:");
|
|
|
gets(tmp->acPress);
|
|
|
printf("输入书的库存量:");
|
|
|
scanf("%d", &tmp->iAmount);
|
|
|
book = tmp;
|
|
|
|
|
|
printf("按任意键返回\n");
|
|
|
getchar();
|
|
|
return book;
|
|
|
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
while (1)
|
|
|
{
|
|
|
while (book->next == NULL)
|
|
|
{
|
|
|
int flag = 1;
|
|
|
while (flag)
|
|
|
{
|
|
|
Book* tmp = (Book*)malloc(sizeof(Book));
|
|
|
|
|
|
tmp->next = NULL;
|
|
|
assert(tmp);
|
|
|
printf("输入书的编号:");
|
|
|
scanf("%d", &tmp->iNum);
|
|
|
getchar();
|
|
|
printf("输入书的名称:");
|
|
|
gets(&tmp->acName);
|
|
|
printf("输入书的作者:");
|
|
|
gets(tmp->acAuthor);
|
|
|
printf("输入书的出版社:");
|
|
|
gets(tmp->acPress);
|
|
|
printf("输入书的库存量:");
|
|
|
scanf("%d", &tmp->iAmount);
|
|
|
|
|
|
book->next = tmp;
|
|
|
|
|
|
printf("是否继续输入:1==>继续\t0==>结束\t");
|
|
|
scanf("%d", &flag);
|
|
|
getchar();
|
|
|
if (flag == 0)
|
|
|
{
|
|
|
printf("按任意键返回\n");
|
|
|
getchar();
|
|
|
return book1;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
book = book->next;
|
|
|
}
|
|
|
printf("按任意键返回\n");
|
|
|
getchar();
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Book* DealoldBook(Book* book1)
|
|
|
{
|
|
|
Book* book = book1;
|
|
|
Book* prev = book1;
|
|
|
printf("输入要处理旧书的编号:");
|
|
|
int id;
|
|
|
scanf("%d", &id);
|
|
|
getchar();
|
|
|
while (book != NULL)
|
|
|
{
|
|
|
|
|
|
if (id == book->iNum)
|
|
|
{
|
|
|
if (book1 == book)
|
|
|
{
|
|
|
book = book->next;
|
|
|
free(prev);
|
|
|
return book;
|
|
|
}
|
|
|
prev->next = book->next;
|
|
|
free(book); // free():释放资源
|
|
|
printf("已将旧书处理掉!\n");
|
|
|
printf("按任意键返回\n");
|
|
|
getchar();
|
|
|
return book1;
|
|
|
}
|
|
|
prev = book;
|
|
|
book = book->next;
|
|
|
}
|
|
|
printf("没有找到该图书\n");
|
|
|
printf("按任意键返回\n");
|
|
|
getchar();
|
|
|
return book1;
|
|
|
}
|