📄 library.cpp
字号:
#include "head.h"
void GetInformation(Record &book)
{
/*printf("enter the name of the book:\n");
getchar();
gets(book.name);
printf("enter the number of the book:\n");
scanf("%d",&book.booknum);
printf("enter the writer of the book:\n");
getchar();
gets(book.writer);
printf("enter the total storage of the book:\n");
scanf("%d",&book.total);
book.current=book.total;*/
strcpy(book.name,"happy");
strcpy(book.writer,"sunny");
book.total=5;
book.current=book.total;
printf("enter the number of the book:\n");
scanf("%d",&book.booknum);
}
void PrintBookInfomation(Record *book)
{
int i;
printf("the booknum:%d\n",book->booknum);
printf("name:%s\n",book->name);
printf("writer:%s\n",book->writer);
printf("total storage:%d,current storage:%d",book->total,book->current);
for(i=0;i<book->total-book->current;i++)
printf("\nNO.:%d LIBRARYNUM:%s RETURNDATE:%s",i+1,book->librarynum[i],book->returndate[i]);
}
void CopyBook(KeyType &k,Record book)
{
int i;
k.k=book.booknum;
k.recptr=(Record *)malloc(sizeof(Record));
k.recptr->booknum=book.booknum;
k.recptr->current=book.current;
k.recptr->total=book.total;
strcpy(k.recptr->name,book.name);
strcpy(k.recptr->writer,book.writer);
for(i=0;i<book.total-book.current;i++)
{
strcpy(k.recptr->librarynum[i],book.librarynum[i]);
strcpy(k.recptr->returndate[i],book.returndate[i]);
}
}
void Procurement(BTree &T)
{
Record book;
Result result;
KeyType k;
GetInformation(book);
result=SearchBTree(T,book.booknum);
if(result.tag==0)
{
CopyBook(k,book);
InsertBTree( T,k,result.pt,result.i);
}
else
result.pt->key[result.i]->recptr->total++;
}
void DeleteBook(BTree &T,int k)
{
DeleteBTree(T,k);
}
void Lending(BTree &T,int k,char librarynum[10],char returndate[10])
{
Result result;
BTree p;
int i,j;
result=SearchBTree(T,k);
p=result.pt;
i=result.i;
if(result.tag==0)
{
printf("This book is not exited.\n");
return;
}
if(result.pt->key[result.i]->recptr->current==0)
{
printf("This book is already borrowed.\n");
return;
}
p->key[i]->recptr->current--;
for(j=0;j<p->key[i]->recptr->total-p->key[i]->recptr->current;j++)
{
strcpy(p->key[i]->recptr->librarynum[j],librarynum);
strcpy(p->key[i]->recptr->returndate[j],returndate);
}
PrintBookInfomation(p->key[i]->recptr);
}
void Return(BTree &T,int k,char *librarynum)
{
Result result;
BTree p;
int i,j,n,current,total;
result=SearchBTree(T,k);
p=result.pt;
i=result.i;
current=p->key[i]->recptr->current;
total=p->key[i]->recptr->total;
for(j=0;j<=total-current;j++)
if(p->key[i]->recptr->librarynum[j]==librarynum)
break;
for(n=j;n<total-current;n++)
{
strcpy(p->key[i]->recptr->librarynum[n],p->key[i]->recptr->librarynum[n+1]);
strcpy(p->key[i]->recptr->returndate[n],p->key[i]->recptr->returndate[n+1]);
}
p->key[i]->recptr->current++;
PrintBookInfomation(p->key[i]->recptr);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -