|
|
@ -121,18 +121,191 @@ void foundReaderInfo(Reader* reader1)
|
|
|
|
//读者借书
|
|
|
|
//读者借书
|
|
|
|
Reader* LendBook(Reader* reader1, Book* book1)
|
|
|
|
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;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//读者还书
|
|
|
|
//读者还书
|
|
|
|
void save(Book* book1)
|
|
|
|
void save(Book* book1)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
FILE* fp;
|
|
|
|
|
|
|
|
Book* pCur = book1;
|
|
|
|
|
|
|
|
int iCount = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (pCur == NULL)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
printf("\n没有学生记录!\n");
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ((fp = fopen("book.txt", "wb")) == NULL)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
printf("创建文件失败!\n");
|
|
|
|
|
|
|
|
getchar();
|
|
|
|
|
|
|
|
exit(1);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
while (pCur)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
fwrite(pCur, sizeof(Book), 1, fp);
|
|
|
|
|
|
|
|
pCur = pCur->next;
|
|
|
|
|
|
|
|
iCount++;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
printf("保存文件的数据数目为:%d\n", iCount);
|
|
|
|
|
|
|
|
fclose(fp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//从文件读取
|
|
|
|
//从文件读取
|
|
|
|
Book* read1()
|
|
|
|
Book* read1()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
FILE* fp;
|
|
|
|
|
|
|
|
Book* pHead = NULL, * pTemp = NULL, * pCur = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ((fp = fopen("book.txt", "r")) == NULL)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
printf("\n文件打开失败!请检查文件名!\n");
|
|
|
|
|
|
|
|
exit(0);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
pTemp = (Book*)malloc(sizeof(Book));
|
|
|
|
|
|
|
|
while (fread(pTemp, sizeof(Book), 1, fp))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (!pHead)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
pHead = pCur = pTemp;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
pCur->next = pTemp;
|
|
|
|
|
|
|
|
pCur = pTemp;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
pTemp = (Book*)malloc(sizeof(Book));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose(fp);
|
|
|
|
|
|
|
|
return pHead;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|