From 755f91c8f14adf452d8bdee3995e73e196d00e3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=B1=9F=E6=A5=A0?= <87896121@qq.com> Date: Tue, 25 Apr 2023 15:42:45 +0800 Subject: [PATCH] C2C3C4C5 --- 图书管理.c | 148 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 144 insertions(+), 4 deletions(-) diff --git a/图书管理.c b/图书管理.c index 9cab977..78e12c5 100644 --- a/图书管理.c +++ b/图书管理.c @@ -77,23 +77,163 @@ void ShowMainMenu() 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; }