From 3edd7f021b4f6c95fc3dc9618c0dcc74d1bedaf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E8=89=BA=E5=93=B2?= <446062334@qq.com> Date: Sat, 22 Apr 2023 16:07:13 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E5=AE=8C=E5=96=84=E7=B3=BB=E7=BB=9F?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 图书管理系统.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/图书管理系统.c b/图书管理系统.c index bd89246..87f155c 100644 --- a/图书管理系统.c +++ b/图书管理系统.c @@ -273,3 +273,27 @@ Book* DealoldBook(Book* book1) return book1; } +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; +} From 31c3c2cacde5e537355accbc585b75eaa3283641 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=83=AD=E4=BD=B3=E6=85=A7?= <1608111480@qq.com> Date: Sat, 22 Apr 2023 16:10:25 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E5=AE=8C=E5=96=84=E7=B3=BB=E7=BB=9F?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 图书管理系统.c | 183 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 183 insertions(+) diff --git a/图书管理系统.c b/图书管理系统.c index 87f155c..9c6fb95 100644 --- a/图书管理系统.c +++ b/图书管理系统.c @@ -297,3 +297,186 @@ void foundBook(Book* book1) getchar(); return; } +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; +} +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; +} + +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("输入读者职位:"); + 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; + } + } + + +} \ No newline at end of file From 785ccab291606ef246c509f322c7244e96dfc495 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E8=89=BA=E5=93=B2?= <446062334@qq.com> Date: Sat, 22 Apr 2023 16:13:30 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E5=AE=8C=E5=96=84=E7=B3=BB=E7=BB=9F?= =?UTF-8?q?=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 图书管理系统.c | 113 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) diff --git a/图书管理系统.c b/图书管理系统.c index 9c6fb95..1efac6c 100644 --- a/图书管理系统.c +++ b/图书管理系统.c @@ -479,4 +479,117 @@ Reader* LendBook(Reader* reader1, Book* book1) } +} +void returnBook(Reader* reader1, Book* book1) +{ + Reader* reader = reader1; + Book* book = book1; + printf("请输入读者的id:"); + int id; + scanf("%d", &id); + getchar(); + + if (reader != NULL) + { + while (reader != NULL) + { + if (id == reader->iNum) + { + printf("请输入要还的书的编号:"); + int id_book; + scanf("%d", &id_book); + getchar(); + for (int i = 0; i < reader->iMax; i++) + { + if (reader->aiBookId[i] == id_book) + { + reader->aiBookId[i] = 0; + while (book) + { + if (id_book == book->iNum) + { + book->iAmount++; + printf("还书成功!\n"); + printf("按任意键返回\n"); + getchar(); + return reader1; + } + book = book->next; + } + } + } + printf("没有找到该图书,检查图书的Id\n"); + + printf("按任意键返回\n"); + getchar(); + return reader1; + } + reader = reader->next; + } + printf("没有找到该读者,检查读者id是否输入有误\n"); + printf("按任意键返回\n"); + getchar(); + return reader1; + } +} + + + +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() +{ + 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; } \ No newline at end of file