============
#ifndef _DATA_STRUCT_H_
#define _DATA_STRUCT_H_
/* Book structure */
Structural book
{
Unsigned long BookID/* Book number */
char BookName[5 12]; /* Title */
char Writer[5 12]; /* Author */
Int CurrentNumber/* quantity on hand */
Book * pNext/* next book information */
};
/* Book index structure */
Structural index
{
Unsigned long BookID/* Book number */
Index * pNext/* Next index pointer */
};
/* Borrowing information structure */
Structural borrowing
{
Unsigned long BookID/* Borrowing Book Number */
char BookName[5 12]; /* Title */
Unsigned long integer StuID/* library ID number */
Char return time [512]; /* Return date */
Borrow * pNext/* next loan information */
};
#endif/*_DATA_STRUCT_H_*/
Implementation file:
===============
// BookManage.cpp: defines the entry point of the console application.
//
# include & ltstdio.h & gt
# include & ltstdlib.h & gt
# include & ltstring.h & gt
# include & lttime.h & gt
# contains "DataStruct.h"
/*
Data Structure Course Design (Based on C) Book Management System
Reward points: 100- 14 days. The question ended 23 hours ago.
problem description
The basic business activities of book management include the warehousing, clearing, borrowing and returning of books. Try to design a book management system to complete the above business activities with the help of computer system.
basic requirement
(1) The registration of each book includes at least five items: book number, title, number of authors on hand and total inventory.
(2) Establish an index table (linear table) for the book number to improve the searching efficiency.
(3) The operations and functions to be realized by the system are defined as follows:
1 cataloging and warehousing: new books are purchased, classified and counted, and then registered in the library account. If the book is already in the account, only the total inventory will increase.
Borrowing: If the existing quantity of a book is greater than zero, lend a book and cancel the borrower's library card number and return date.
Return: Cancel the borrower's registration and change the existing number of books.
*/
/* Get the input string */
void GetInput(char *pInOutStr,int StrLen,bool only getnumber = false);
/* Display the main menu and return to the selection */
int ShowMainMenu();
/* For the book warehousing operation, the passed-in parameters are the pointer of the book list header pointer and the pointer of the index information header pointer, because the value of the header pointer may change within this function */
void PutBookInLib(Book **pHead,Index * * pIndex);
/* Query the warehouse inventory, and the query will not change the data, so the incoming pointer can be */
void query booklib(Book * pHead);
/* Borrow books */
Void BorrowBook (borrow **pBorrow, book * phead);
/* Query and borrowing */
void query Borrow(Borrow * p Borrow);
/* Return books */
Void ReturnBook (borrow **pBorrow, book * phead);
/* List of published books, indexes and borrowing information */
void delete booklist(Book * * pHead);
void DeleteIndexList(Index * * pIndex);
void DeleteBorrowList(Borrow * * p Borrow);
int main()
{
/* Book list title pointer */
Book * pBookHead = NULL
/* Book index header pointer */
Index * pIndexHead = NULL
/* Lend header pointer */
Borrow * pBorrowHead = NULL
/* Used to save the current user's input */
int choosed num =- 1;
While (true)
{
choosed num = ShowMainMenu();
Switch (select menu)
{
Case 0 :/* Exit */
{
Returns 0;
Break;
}
Case 1:/* Book storage */
{
PutBookInLib(& amp; pBookHead & amp; pIndexHead);
Break;
}
Case 2:/* Query inventory */
{
QueryBookLib(pBookHead);
Printf ("Press Enter to continue ...");
fflush(stdin);
getchar();
System ("CLS");
Break;
}
Case 3:/* Borrowing books */
{
QueryBookLib(pBookHead);
Borrow books. pBorrowHead,pBookHead);
Break;
}
Case 4:/* Query and Borrowing */
{
query borrow(pBorrowHead);
Printf ("Press Enter to continue ...");
fflush(stdin);
getchar();
System ("CLS");
Break;
}
Case 5:/* Returning Books */
{
query borrow(pBorrowHead);
return book(amp; pBorrowHead,pBookHead);
Break;
}
}
}
Delete the book list (& AMPBOOKHead);
DeleteIndexList(& amp; pIndexHead);
DeleteBorrowList(& amp; pBorrowHead);
fflush(stdin);
getchar();
Returns 0;
}
/* Get the input string */
void GetInput(char *pInOutStr,int StrLen,bool OnlyGetNumber)
{
memset(pInOutStr,0x0,StrLen);
fflush(stdin);
int Count = 0;
While (true)
{
char TmpC = 0;
Fred (& ampTmpC, 1, 1, stdin);
if ( 10 == TmpC)
{
Break;
}
if(only get number & amp; & ampTmpC & gt= ' 0 ' & amp& ampTmpC & lt= '9' )
{
pinout str[Count]= TmpC;
count++;
}
other
{
pinout str[Count]= TmpC;
count++;
}
}
}
/* Display the main menu and return to the selection */
int ShowMainMenu()
{
char InPutStr[ 1024];
No input:
printf(" \ n \ n \ n ");
printf(" * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \ n ");
Printf("* book management system * \ n ");
printf(" * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \ n ");
printf(" \ n ");
Printf ("Please select: \ n");
Printf("\t 1。 Book storage \ n ");
Printf("\t2。 Query inventory \ n ");
Printf("\t3。 Borrow books \ n ");
Printf("\t4。 Query borrowing \ n ");
Printf("\t5。 Return the book \ n ");
Printf("\t0。 Exit \ n ");
printf(" \ n ");
printf(" \ t input:");
GetInput(InPutStr, 1024,true);
if(strlen(input str)& lt; 1 )
{
System ("CLS");
goto NO _ INPUT
}
Returns atoi (input str);
}
/* Book warehousing operation */
void PutBookInLib(Book * * phe head,Index **pIndex)
{
Book * pWork = * pHead
Unsigned length BookID =1;
char InPutStr[ 1024];
/* First calculate the ID number of the currently stored book */
if ( NULL == pWork)
{
BookID = 1;
}
other
{
while(pWork-& gt; pNext! = empty)
{
p work = p work-& gt; pNext
}
BookID = pWork-& gt; BookID+ 1;
}
Book * pTmpNewBook =(Book *)(malloc(sizeof(Book)));
memset(pTmpNewBook,0x0,sizeof(Book));
Index * PTM Index =(Index *)(malloc(sizeof(Index)));
memset(PTM Index,0x0,sizeof(Index));
pTmpNewBook-& gt; BookID = BookID
PTM index-& gt; BookID = BookID
System ("CLS");
Printf ("Enter book name:");
GetInput(InPutStr, 1024);
strcpy(pTmpNewBook-& gt; BookName,input str);
System ("CLS");
printf(" & lt; & lt% s & gt& gt\n ",pTmpNewBook-& gt; Title);
Printf ("book author:");
GetInput(InPutStr, 1024);
strcpy(pTmpNewBook-& gt; Writer,input str);
System ("CLS");
printf(" & lt; & lt% s & gt& gt\n ",pTmpNewBook-& gt; Title);
Printf ("Author: %s\n", ptmp new book-> Writer);
Printf ("quantity received:");
GetInput(InPutStr, 1024,true);
pTmpNewBook-& gt; current number = atoi(input str);
if(pTmpNewBook-& gt; Current number & lt 1)
{
System ("CLS");
Printf ("Incorrect purchase quantity! (Press Enter to continue ...) ");
fflush(stdin);
getchar();
System ("CLS");
Return;
}
if ( NULL == *pHead)
{
* pHead = pTmpNewBook
* pIndex = pTmpIndex
}
other
{
Book * pWork = * pHead
while ( pWork! = empty)
{
if(strcmp(p work-& gt; BookName,pTmpNewBook-& gt; BookName)= = 0 & amp; & ampstrcmp(p work-& gt; Writer, ptmp new book-> Writer) == 0)
{
Work-> current number+= pTmpNewBook-& gt; Current number;
Return;
}
p work = p work-& gt; pNext
}
pWork = * pHead
while(pWork-& gt; pNext! = empty)
{
p work = p work-& gt; pNext
}
Work-> pNext = pTmpNewBook
Index * pWork2 = * pIndex
while(pwork 2-& gt; pNext! = empty)
{
pwork 2 = pwork 2-& gt; pNext
}
pwork 2-& gt; pNext = pTmpIndex
}
System ("CLS");
Printf ("Books:
fflush(stdin);
getchar();
System ("CLS");
}
/* Publish book linked list and index linked list */
void DeleteBookList(Book **pHead)
{
Book * pWork = * pHead
Book * pNext = pWork
while ( NULL! = pWork)
{
pNext = p work-& gt; pNext
Free (pwork);
pWork = pNext
}
}
void delete Index list(Index * * pIndex)
{
Index * pWork = * pIndex
Index * pNext = pWork
while ( NULL! = pWork)
{
pNext = p work-& gt; pNext
Free (pwork);
pWork = pNext
}
}
void DeleteBorrowList(Borrow * * p Borrow)
{
Borrow * pWork = * pBorrow
Borrow * pNext = pWork
while ( NULL! = pWork)
{
pNext = p work-& gt; pNext
Free (pwork);
pWork = pNext
}
}
/* Query the warehouse inventory, and the query will not change the data, so the incoming pointer can be */
void QueryBookLib(Book *pHead)
{
Book * pWork = pHead
int total count = 0;
while ( NULL! = pWork)
{
total count++;
p work = p work-& gt; pNext
}
System ("CLS");
Printf ("There are ***%d books in stock at present, as follows: \ n = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
pWork = pHead
while ( NULL! = pWork)
{
Printf ("No.:[%d] Title:
p work = p work-& gt; pNext
}
printf(" = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = \ n ",total count);
}
/* Borrow books */
void BorrowBook(Borrow **pBorrow,Book *pHead)
{
char InPutStr[ 1024];
bool HadTheBook = false
Borrow * pTmpBorrow =(Borrow *)(malloc(sizeof(Borrow)));
memset(pTmpBorrow,0x0,sizeof(Borrow));
Printf ("Please enter the number of books you want to borrow:");
GetInput(InPutStr, 1024,true);
pTmpBorrow-& gt; BookID = atoi(input str);
Book * pWorkBook = pHead
while ( pWorkBook! = empty)
{
if(pWorkBook-& gt; BookID = = pTmpBorrow-& gt; BookID)
{
HadTheBook = true
Break;
}
p workbook = p workbook-& gt; pNext
}
If (HadTheBook)
{
if(pWorkBook-& gt; Current number & lt 1)
{
System ("CLS");
Printf ("Books
fflush(stdin);
getchar();
System ("CLS");
Free (ptmp borrow);
Return;
}
}
other
{
System ("CLS");
Printf ("ISBN %d does not exist! \n (press Enter to continue ...) ",pTmpBorrow-& gt;; BookID);
fflush(stdin);
getchar();
System ("CLS");
Free (ptmp borrow);
Return;
}
strcpy(pTmpBorrow-& gt; BookName,pWorkBook-& gt; Title);
Printf ("Please enter the library card number:");
GetInput(InPutStr, 1024,true);
pTmpBorrow-& gt; StuID = atoi(input str);
if(0 = = pTmpBorrow-& gt; StuID)
{
System ("CLS");
Printf ("Library ID number does not exist (enter an integer for the library ID number)! \n (press Enter to continue ...) ");
fflush(stdin);
getchar();
System ("CLS");
Free (ptmp borrow);
Return;
}
Time_t time;
struct tm * today
Time (ltime);
ltime+= 60 * 60 * 24 * 30;
today = local time(& lt; ime);
sprintf(pTmpBorrow-& gt; ReturnTime, "%d year %d month %d day", today-& gt;; tm_year+ 1900,
Today-> tm_mon+ 1,
Today-> TM _ mday);
if ( *pBorrow == NULL)
{
* pBorrow = pTmpBorrow
}
other
{
Borrow * pWork = * pBorrow
while ( NULL! = p work-& gt; pNext)
{
p work = p work-& gt; pNext
}
Work-> pNext = pTmpBorrow
}
pWorkBook-& gt; Current number-;
System ("CLS");
Printf ("Library card number:% d \ Borrow books:
fflush(stdin);
getchar();
System ("CLS");
}
/* Query and borrowing */
void QueryBorrow(Borrow *pBorrow)
{
Borrow * pWork = pBorrow
int total count = 0;
while ( NULL! = pWork)
{
total count++;
p work = p work-& gt; pNext
}
System ("CLS");
Printf ("There are ***%d pieces of current loan information, which are listed as follows: \ n = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
pWork = pBorrow
while ( NULL! = pWork)
{
Printf ("borrowing number: [%d] borrowing name:
p work = p work-& gt; pNext
}
printf(" = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = \ n ",total count);
}
/* Return books */
Void ReturnBook (borrow * *, book *pHead)
{
char InPutStr[ 1024];
Borrow TmpBorrow
bool HasFindBorrwo = false
memset(& amp; TmpBorrow,0x0,sizeof(tmp borrow));
Printf ("Please enter the library card number:");
GetInput(InPutStr, 1024,true);
TmpBorrow。 StuID = atoi(input str);
Printf ("Please enter the returned ISBN:");
GetInput(InPutStr, 1024,true);
TmpBorrow。 BookID = atoi(input str);
Borrow * pWorkBorrow = * pBorrow
Borrow * pDeletePre = NULL
while ( NULL! = pWorkBorrow)
{
if(pWorkBorrow-& gt; BookID == TmpBorrow。 BookID & amp& amppWorkBorrow-& gt; StuID == TmpBorrow。 StuID)
{
HasFindBorrwo = true
Break;
}
pDeletePre = pWorkBorrow
pWorkBorrow = pWorkBorrow-& gt; pNext
}
If (! HasFindBorrwo)
{
System ("CLS");
Printf ("The borrowing information you entered does not exist! \n (press Enter to continue ...) ");
fflush(stdin);
getchar();
System ("CLS");
Return;
}
if ( NULL == pDeletePre)
{
* p borrow = pWorkBorrow-& gt; pNext
}
other
{
pDeletePre-& gt; pNext = pWorkBorrow-& gt; pNext
}
Book * pWorkBook = pHead
while ( NULL! = pWorkBook)
{
if(pWorkBook-& gt; BookID = = pWorkBorrow-& gt; BookID)
{
pWorkBook-& gt; current number++;
}
p workbook = p workbook-& gt; pNext
}
System ("CLS");
Printf ("library card number. :% d \ Return the book:
fflush(stdin);
getchar();
System ("CLS");
Pworkborrow;
}
This is the answer someone gave me. //I need to add some Chinese comments before, and there are still errors in VC environment, so I can't run it directly.
Time_t time;
struct tm * today
Time (ltime);
ltime+= 60 * 60 * 24 * 30;
today = local time(& lt; ime);
sprintf(pTmpBorrow-& gt; ReturnTime, "%d year %d month %d day", today-& gt;; tm_year+ 1900,
Today-> tm_mon+ 1,
Today-> TM _ mday);
This is the main problem. I wanted to post my modified ones, but I can't, if you like. Leave a mailbox.