当前位置:网站首页>2022.2.27 library management system 3 - book borrowing and returning registration module

2022.2.27 library management system 3 - book borrowing and returning registration module

2022-06-11 13:46:00 Warm old D

This is the third module of the library management system , There are some details to pay attention to

In the book borrowing registration system , Pay attention to when books exist , When books don't exist , The most important thing is to keep the information after borrowing the book , Because all the work done in the code is done in the array , In case something happens , Save it in a file , And every time I borrow a Book , Remember to subtract from the stock of books 1, The current number of readers who can borrow minus 1, In this way, the borrowing procedure will be complete . Return code similar .

// Borrow and return submenu 
void ShowBorrowReturnMenu()
{
	system("cls");
	printf("\n\n\n\n");
	printf("\t********************** Welcome to ***********************\n");
	printf("\t********************* Registration of borrowing and returning books ***********************\n");
	printf("\t********************** Sub menu *************************\n");
	printf("\t*********************1. Book borrowing registration ***********************\n");
	printf("\t*********************2. Book return registration ***********************\n");
	printf("\t*********************0. Back to main menu *********************\n");
	printf("\t******************************************************\n");
	printf("\n");
	printf("\t\t Please select (0-2)");
}

// Borrow books 
void BorrowBook()
{
	// Whether readers can borrow books 
	system("cls");
	int iBookld, iReaderld, iBorrow, i;//iBorrow The reader borrowed some books 
	// Enter the number of the reader who wants to borrow the book , Determine whether the number exists , If there is , Display the book information that readers have borrowed 
	iReaderld = SearchReader();
	if (iReaderld == -1)// non-existent 
	{
		return;
	}
	iBorrow = astReader[iReaderld].iMax - astReader[iReaderld].iAmount;
	if (iBorrow == 0)
	{
		printf(" The reader has not borrowed any books at present ");
	}
	else
	{
		printf("\t The reader is currently borrowing :");
		for (i = 0; i < iBorrow; i++)
		{
			printf("%d", astReader[iReaderld].Bookld[i]);// The corresponding subscript in the array is the number of the stored book 
		}
		printf("\n\n");
	}
	if (astReader[iReaderld].iAmount == 0)
	{
		printf(" The number of books that this reader can borrow is 0, You can't continue to borrow books \n");
	}
	// Whether books can be borrowed 
	printf("\n Press any key to enter the book information to borrow \n");
	_getch;
	iBookld = SearchBook();
	if (iBookld == -1)
	{
		return;
	}
	if (astBook[iBookld].iAmount == 0)
	{
		printf(" The stock of the book is 0! Books cannot be borrowed !\n");
		return;
	}
	// Borrow books 
	astReader[iReaderld].Bookld[iBorrow] = astBook[iBookld].iNum;
	// Inventory of books -1
	astBook[iBookld].iAmount--;
	// The number of books available to current readers -1
	astReader[iReaderld].iAmount--;
	// Operation in array , Must be saved in a file 
	SaveBookFile(iBookld);
	SaveReaderFile(iReaderld);
	printf(" Borrow books successfully !\n");
}

// Return books 
void ReturnBook()
{
	system("cls");
	int iBookld, iReaderld, iBorrow, i, j;// Whether the reader borrows the book 
	//1.  Is the reader in the system 
	iReaderld = SearchReader();
	if (iReaderld == -1)
	{
		return;
	}
	//
	iBorrow = astReader[iReaderld].iMax - astReader[iReaderld].iAmount;
	if (iBorrow == 0)
	{
		printf("\t The reader did not borrow any books , No need to return !\n");
		return;
	}
	else
	{
		printf("\t The books that the reader is currently borrowing are :");
		for (i = 0; i < iBorrow; i++)//iBorrow I borrowed some books by myself 
		{
			printf("%d", astReader[iReaderld].Bookld[i]);
		}
	}
	printf(" Press any key to enter the book information to be returned \n");
	_getch;
	//2.  Is the book in the system 
	iBookld = SearchBook();
	if (iBookld == -1)
	{
		return;
	}
	//3.  Is there this book in the loan list 
	for (i = 0; i < iBorrow; i++)
	{
		if (astReader[iReaderld].Bookld[i] == astBook[iBookld].iNum)
		{
			// If this book is on the loan list , To return the book 
			for (j = i; j < iBorrow - 1; j++)
			{
				astReader[iReaderld].Bookld[j] = astReader[iReaderld].Bookld[j + 1];
			}
			astReader[iReaderld].Bookld[iBorrow - 1] = 0;
			// Book inventory plus 1
			astBook[iBookld].iAmount++;
			// The number of books that readers can borrow 
			astReader[iReaderld].iAmount++;
			break;
		}
	}
	if (i == iBorrow)
	{
		printf(" The reader did not borrow the book , No need to return !\n");
		return;
	}
	// Return books 
	SaveBookFile(iBookld);
	SaveReaderFile(iReaderld);
	printf(" Return the book successfully \n");
}

// Book borrowing and returning module 
void BorrowReturnManger()
{
	ShowBorrowReturnMenu();// The submenu of borrowing and returning books 
	int iltem;
	scanf("%d", &iltem);
	getchar();
	while (iltem)
	{
		switch (iltem)
		{
		case 1:
			BorrowBook();// Borrow books 
			break;
		case 2:
			ReturnBook();// Return books 
			break;
		default:
			printf("\t\t Please enter the correct number !\n");
		}
		printf(" Press any key to return to the submenu ");
		_getch;
		ShowBorrowReturnMenu();// The submenu of borrowing and returning books 
		scanf("%d", &iltem);
		getchar();
	}
}

原网站

版权声明
本文为[Warm old D]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/03/202203012101365079.html