⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 例2--图书管理--代码.cpp

📁 图书馆管理系统的实现
💻 CPP
📖 第 1 页 / 共 3 页
字号:
		return;
	}
	int iCounter=0;
	for(;rnReturn->rReader.bbBook[iCounter].iBookID!=bnReturn->bBook.iID&&iCounter<rnReturn->rReader.iBookCount;++iCounter){}
	if(iCounter==rnReturn->rReader.iBookCount)
	{
		printf("   该用户没有借阅该书!\n");
		printf("   还书操作被取消!\n");
		return;
	}
	char cChoose;
	printf("   是否还书?\n");
	printf("   是(y)\\否(n):");
	scanf("%c",&cChoose);
	if(cChoose=='y')
	{
		getchar();
		while(iCounter<5)
		{
			rnReturn->rReader.bbBook[iCounter]=rnReturn->rReader.bbBook[++iCounter];
		}
		--rnReturn->rReader.iBookCount;
		++bnReturn->bBook.iNowAll;
		printf("   还书成功!\n");
	}
	else
	{
		printf("   你取消了还书操作!\n");
		if(cChoose=='\n')
		{
			return;
		}
		while(getchar()!='\n'){}
	}
}

//////////////////////////////////////////
//图书管理
//////////////////////////////////////////

/* 打印藏书清单 */
void PrintBookList(BookNode * bnFirst)
{
	BookNode* bnCurr;
	printf("   ****** 藏书清单列表 ******\n");
	if(bnFirst->bnNext==NULL)
	{
		printf("   无任何相关信息!\n");
		return;
	}
	for(bnCurr=bnFirst->bnNext;bnCurr!=NULL;bnCurr=bnCurr->bnNext)
	{
		PrintBook(bnCurr);
		printf("   ---------------------------\n");
	}
	printf("   ****** 藏书清单打印完成 ******\n");
}

/* 加入新书 */
void InsertNewBook(BookNode * bnFirst)
{
	BookNode* bnNewBook;
	bnNewBook=(BookNode *)malloc(sizeof(BookNode));
	if(!bnNewBook)
	{
		printf("   内存资源枯竭!\n");
		getchar();
		exit(0);
	}

	printf("   填写新书属性\n");
	printf("   ISBN:");
	InputString(bnNewBook->bBook.csISBN);
	printf("   书名:");
	InputString(bnNewBook->bBook.csName);
	printf("   作者:");
	InputString(bnNewBook->bBook.csAuthor);
	printf("   出版社:");
	InputString(bnNewBook->bBook.csPublisher);
	printf("   出版时间:");
	InputString(bnNewBook->bBook.csPubTime);
	printf("   页数:");
	bnNewBook->bBook.iPage=InputNumber();
	printf("   类别:");
	InputString(bnNewBook->bBook.csClassify);
	printf("   存放位置:");
	InputString(bnNewBook->bBook.csStore);
	printf("   图书总数:");
	bnNewBook->bBook.iAll=InputNumber();
	printf("   入馆时间:");
	InputString(bnNewBook->bBook.csInTime);
	printf("   图书价:");
	scanf("%f",&bnNewBook->bBook.fPrice);
	getchar();

	bnNewBook->bBook.iNowAll=bnNewBook->bBook.iAll;
	bnNewBook->bnNext=NULL;

	BookNode *bnCurr,*bnPrev;
	if(bnFirst->bnNext==NULL)
	{
		bnFirst->bnNext=bnNewBook;
		bnNewBook->bBook.iID=1;
	}
	else
	{
		for(bnCurr=bnFirst->bnNext;bnCurr!=NULL;bnCurr=bnCurr->bnNext)
		{
			bnPrev=bnCurr;
		}
		bnPrev->bnNext=bnNewBook;
		bnNewBook->bBook.iID=bnPrev->bBook.iID+1;
	}
	printf("   加入新书成功!\n");
}

/* 修改图书属性 */
void BookChargeMenu(void)
{
	printf("  ╭───────────╮\n");
	printf("  ∣    可以修改的属性    ∣\n");
	printf("  ├───────────┤\n");
	printf("  ∣ 1.ISBN               ∣\n");
	printf("  ∣ 2.书名               ∣\n");
	printf("  ∣ 3.作者               ∣\n");
	printf("  ∣ 4.出版社             ∣\n");
	printf("  ∣ 5.出版时间           ∣\n");
	printf("  ∣ 6.页数               ∣\n");
	printf("  ∣ 7.类别               ∣\n");
	printf("  ∣ 8.现存数量           ∣\n");
	printf("  ∣ 9.存放位置           ∣\n");
	printf("  ∣ 10.图书总数          ∣\n");
	printf("  ∣ 11.入馆时间          ∣\n");
	printf("  ∣ 12.图书价            ∣\n");
	printf("  ∣ 13.完成              ∣\n");
	printf(" ╰───────────╯\n");
}

void BookCharge(BookNode * bnFirst)
{			
	int iNowAllTemp;
	int iAllTemp;
	int iChoose;
	BookNode *bnCurr;
	printf("   ****** 选择图书 ******\n");
	bnCurr=BookFind(bnFirst);
	if(bnCurr==NULL)
	{
		printf("   错误操作!\n");
		return;
	}
	BookChargeMenu();
	for(;;)
	{
		iChoose=ChooseFunction();
		if(iChoose==1)
		{
			printf("   请输入新的ISBN:");
			InputString(bnCurr->bBook.csISBN);
		}
		else if(iChoose==2)
		{
			printf("   请输入新的书名:");
			InputString(bnCurr->bBook.csName);
		}
		else if(iChoose==3)
		{
			printf("   请输入新的作者:");
			InputString(bnCurr->bBook.csAuthor);
		}
		else if(iChoose==4)
		{
			printf("   请输入新的出版社:");
			InputString(bnCurr->bBook.csPublisher);
		}
		else if(iChoose==5)
		{
			printf("   请输入新的出版时间:");
			InputString(bnCurr->bBook.csPubTime);
		}
		else if(iChoose==6)
		{
			printf("   请输入新的页数:");
			bnCurr->bBook.iPage=InputNumber();
		}
		else if(iChoose==7)
		{
			printf("   请输入新的类别:");
			InputString(bnCurr->bBook.csClassify);
		}
		else if(iChoose==8)
		{
			printf("   请输入新的现存数量:");
			iNowAllTemp=bnCurr->bBook.iNowAll;
			bnCurr->bBook.iNowAll=InputNumber();
			bnCurr->bBook.iAll=bnCurr->bBook.iAll+(bnCurr->bBook.iNowAll-iNowAllTemp);
		}
		else if(iChoose==9)
		{
			printf("   请输入新的存放位置:");
			InputString(bnCurr->bBook.csStore);
		}
		else if(iChoose==10)
		{
			printf("   请输入新的图书总数:");
			iAllTemp=InputNumber();
			iNowAllTemp=bnCurr->bBook.iNowAll+(iAllTemp-bnCurr->bBook.iAll);
			if(iNowAllTemp<0)
			{
				printf("   输入新的图书总数错误!\n");
				printf("   修改图书总数被取消!\n");
			}
			else
			{
				bnCurr->bBook.iNowAll=iNowAllTemp;
				bnCurr->bBook.iAll=iAllTemp;
			}
		}
		else if(iChoose==11)
		{
			printf("   请输入新的入馆时间:");
			InputString(bnCurr->bBook.csInTime);
		}
		else if(iChoose==12)
		{
			printf("   请输入新的图书价:");
			scanf("%f",&bnCurr->bBook.fPrice);
			getchar();
		}
		else if(iChoose==13)
		{
			printf("   修改完成!\n");
			printf("   ****** 当前图书属性 ******\n");
			PrintBook(bnCurr);
			break;
		}
		else
		{
			printf("   请输入正确的选择!\n");
		}
	}
}

/* 删除图书 */
void DeleteBook(BookNode * bnFirst)
{
	BookNode *bnCurr,*bnPrev,*bnTemp;
	char cChoose;
	printf("   ****** 选择图书 ******\n");
	bnTemp=BookFind(bnFirst);
	if(bnTemp==NULL)
	{
		printf("   错误操作!\n");
		return;
	}
	bnPrev=bnFirst,bnCurr=bnFirst->bnNext;
	for(;bnCurr->bBook.iID!=bnTemp->bBook.iID;bnCurr=bnCurr->bnNext)
	{
		bnPrev=bnCurr;
	}
	printf("   是否要删除此的图书?\n");
	printf("   是(y)\\否(n):");
	scanf("%c",&cChoose);
	if(cChoose=='y')
	{
		getchar();
		if(bnCurr->bBook.iNowAll!=bnCurr->bBook.iAll)
		{
			printf("   无法删除!(可能是因为图书无全部归还)\n");
		}
		else
		{
			bnPrev->bnNext=bnCurr->bnNext;
			free(bnCurr);
			printf("   成功删除!\n");
		}
	}
	else
	{
		if(cChoose=='\n')
		{
			printf("   你取消了删除操作!\n");
			return;
		}
		while(getchar()!='\n'){}
		printf("   你取消了删除操作!\n");
	}
}

/* 图书管理功能选择 */
void BookManageMenu(void)
{
	printf("  ╭───────────╮\n");
	printf("  ∣       图书管理       ∣\n");
	printf("  ├───────────┤\n");
	printf("  ∣ 1.藏书清单           ∣\n");
	printf("  ∣ 2.加入新书           ∣\n");
	printf("  ∣ 3.修改图书属性       ∣\n");
	printf("  ∣ 4.删除图书           ∣\n");
	printf("  ∣ 5.完成               ∣\n");
	printf(" ╰───────────╯\n");
}

void BookManage(BookNode * bnFirst)
{
	int iChoose;
	for(;;)
	{
		BookManageMenu();
		iChoose=ChooseFunction();
		if(iChoose==1)
		{
			PrintBookList(bnFirst);
		}
		else if(iChoose==2)
		{
			InsertNewBook(bnFirst);
		}
		else if(iChoose==3)
		{
			BookCharge(bnFirst);
		}
		else if(iChoose==4)
		{
			DeleteBook(bnFirst);
		}
		else if(iChoose==5)
		{
			break;
		}
		else
		{
			printf("   请输入正确的选择!\n");
		}
	}
}

//////////////////////////////////////////
//查询
//////////////////////////////////////////

/* 图书查找 */
void BookFindMenu(void)
{
	printf("  ╭───────────╮\n");
	printf("  ∣       查找图书       ∣\n");
	printf("  ├───────────┤\n");
	printf("  ∣ 1.书号               ∣\n");
	printf("  ∣ 2.ISBN               ∣\n");
	printf("  ∣ 3.书名               ∣\n");
	printf("  ∣ 4.作者               ∣\n");
	printf("  ∣ 5.出版社             ∣\n");
	printf("  ∣ 6.完成               ∣\n");
	printf(" ╰───────────╯\n");
}

BookNode *BookFind(BookNode * bnFirst)
{
	BookNode *bnCurr=NULL;
	char cTemp[50];
	int iTemp=0;
	int iChoose;
	int iBookNum;

	for(;;iTemp=0)
	{
		BookFindMenu();
		iChoose=ChooseFunction();
		if(iChoose==1)
		{
			printf("   请输入书号:");
			iBookNum=InputNumber();
			for(bnCurr=bnFirst->bnNext;bnCurr!=NULL&&bnCurr->bBook.iID!=iBookNum;bnCurr=bnCurr->bnNext){}
			if(bnCurr==NULL)
			{
				printf("   没有找到包含此属性的书!\n");
			}
			else
				PrintBook(bnCurr);
			printf("   本次查找已完成!\n");
		}
		else if(iChoose==2)
		{
			printf("   请输入ISBN:");
			InputString(cTemp);
			for(bnCurr=bnFirst->bnNext;bnCurr!=NULL&&strcmp(bnCurr->bBook.csISBN,cTemp)!=0;bnCurr=bnCurr->bnNext){}
			if(bnCurr==NULL)
			{
				printf("   没有找到包含此属性的书!\n");
			}
			else
				PrintBook(bnCurr);
			printf("   本次查找已完成!\n");
		}
		else if(iChoose==3)
		{
			bnCurr=bnFirst->bnNext;
			printf("   请输入书名:");
			InputString(cTemp);
			for(;;)
			{
				for(;bnCurr!=NULL&&strcmp(bnCurr->bBook.csName,cTemp)!=0;bnCurr=bnCurr->bnNext){}
				if(bnCurr==NULL&&iTemp==0)
				{
					printf("   没有找到包含此属性的书!\n");
					break;
				}
				else if(bnCurr==NULL)
				{
					break;
				}
				else
				{
					PrintBook(bnCurr);
					bnCurr=bnCurr->bnNext;
					++iTemp;
				}
			}
			printf("   本次查找已完成!\n");
		}
		else if(iChoose==4)
		{
			bnCurr=bnFirst->bnNext;
			printf("   请输入作者:");
			InputString(cTemp);
			for(;;)
			{
				for(;bnCurr!=NULL&&strcmp(bnCurr->bBook.csAuthor,cTemp)!=0;bnCurr=bnCurr->bnNext){}
				if(bnCurr==NULL&&iTemp==0)
				{
					printf("   没有找到包含此属性的书!\n");
					break;
				}
				else if(bnCurr==NULL)
				{
					break;
				}
				else
				{
					PrintBook(bnCurr);
					bnCurr=bnCurr->bnNext;
					++iTemp;
				}
			}
			printf("   本次查找已完成!\n");
		}
		else if(iChoose==5)
		{
			bnCurr=bnFirst->bnNext;
			printf("   请输入出版社:");
			InputString(cTemp);
			for(;;)
			{
				for(;bnCurr!=NULL&&strcmp(bnCurr->bBook.csPublisher,cTemp)!=0;bnCurr=bnCurr->bnNext){}
				if(bnCurr==NULL&&iTemp==0)
				{
					printf("   没有找到包含此属性的书!\n");
					break;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -