if(H.elem[i].key!
=NULL_KEY)/*有数据*/
{
printf("图书编号:
%d\n",H.elem[i].key);
printf("书名:
《%s》\n",H.elem[i].title);
printf("作者:
%s\n",H.elem[i].writer);
printf("图书现存量:
%d\n",H.elem[i].current);
printf("图书总量:
%d\n",H.elem[i].total);
printf("***************************************************\n");
}
}
voidBoSearch(HashTable*H)//借阅查询
{
inte,r,t;
system("CLS");
printf("\n\n**************************************************\n");
printf("\t你能在此目录下按借书证号查找图书信息");
printf("\n**************************************************\n");
printf("\n\t请输入你的借书证号:
");
scanf("%d%*c",&e);
if(SearchHash(*H,e,&r,&t))
{
printf("借书证编号:
%d\n",(*H).elem[e].key);
printf("书名:
《%s》\n",(*H).elem[e].title);
printf("作者:
%s\n",(*H).elem[e].writer);
printf("图书现存量:
%d\n",(*H).elem[e].current);
printf("图书总量:
%d\n",(*H).elem[e].total);
}
else
printf("您没有借过书!
!
!
");
}
voidFind(HashTable*H)
{
intx,p,c;
system("CLS");
printf("\n\n**************************************************\n");
printf("\t你能在此目录下按编号查找图书信息");
printf("\n**************************************************\n");
printf("\n\t请输入你想查找的书的编号:
");
scanf("%d%*c",&x);
if(SearchHash(*H,x,&p,&c))
{
printf("图书编号:
%d\n",(*H).elem[p].key);
printf("书名:
《%s》\n",(*H).elem[p].title);
printf("作者:
%s\n",(*H).elem[p].writer);
printf("图书现存量:
%d\n",(*H).elem[p].current);
printf("图书总量:
%d\n",(*H).elem[p].total);
}
else
printf("对不起,不存在该书!
\n");
}
voidBorrowBook(HashTable*H)
{
inti,k,x,f,t;
system("CLS");
printf("\n\n**************************************************\n");
printf("\t你能在此目录下按编号借阅图书");
printf("\n**************************************************\n");
printf("\n\t请输入你想借的书编号:
");
scanf("%d%*c",&x);
if(SearchHash(*H,x,&k,&f))
{
printf("\n\t你想借这本书吗?
(y/n)");
printf("\n\t书名:
《%s》",(*H).elem[k].title);
printf("\n\t作者:
%s",(*H).elem[k].writer);
printf("\n\t现库存量:
%d",(*H).elem[k].current);
printf("\n\t总库存量:
%d",(*H).elem[k].total);
t=getch();
if(t=='y'||t=='Y')
{
if(((*H).elem[k].current)==0)printf("\n\t对不起,这本书已经被借光了...");
else
{
for(i=0;i<10;i++)
if(((*H).elem[k].reader[i]).num[0]=='\0')break;
printf("\n\t请输入你的借书证号:
");
scanf("%s",((*H).elem[k].reader[i]).num);
printf("\n\t请输入借书日期:
");//输入借书日期
printf("\n\t年:
");
scanf("%d",&(((*H).elem[k].reader[i]).bro.year));
printf("\t月:
");
scanf("%d",&(((*H).elem[k].reader[i]).bro.month));
printf("\t日:
");
scanf("%d",&(((*H).elem[k].reader[i]).bro.day));
printf("\n\t输入应还书日期:
");//输入应还书日期
printf("\n\t年:
");
scanf("%d",&(((*H).elem[k].reader[i]).back.year));
printf("\t月:
");
scanf("%d",&(((*H).elem[k].reader[i]).back.month));
printf("\t日:
");
scanf("%d%*c",&(((*H).elem[k].reader[i]).back.day));
(*H).elem[k].current--;//现存书量减1
printf("\n\t你已借了该书.");
}
}
}
elseprintf("\n\t这本书不存在!
\n");
}
voidReturnBook(HashTable*H)
{
inti,k,x,f,t,j;
intyear,month,day,d;
floatpay;
chartemp[20];
system("CLS");
printf("\n\n**************************************************\n");
printf("\t你能在此目录下按编号归还图书");
printf("\n**************************************************\n");
printf("\n\t请输入你还的书:
");
scanf("%d%*c",&x);
if(SearchHash(*H,x,&k,&f))
{
printf("\n\t你想还这本书吗?
(y/n)");
printf("\n\t书名:
《%s》",(*H).elem[k].title);
printf("\n\t作者:
%s",(*H).elem[k].writer);
printf("\n\t现库存量:
%d",(*H).elem[k].current);
printf("\n\t总库存量:
%d",(*H).elem[k].total);
t=getch();
if(t=='y'||t=='Y')
{
printf("\n\t请输入你的借书证号:
");
scanf("%s",temp);
j=0;
for(i=0;i<5;i++)
{
if(!
(strcmp(temp,((*H).elem[k].reader[i]).num))){j=1;break;}//查看是否有借书
}
if(j==0)
{printf("\n\t你没有借书.");return;}//该借书证号的人没借书
printf("\n\t今天是:
");
printf("\n\t年:
");
scanf("%d",&year);
printf("\t月:
");
scanf("%d",&month);
printf("\t日:
");
scanf("%d%*c",&day);
d=0;
if(year<((*H).elem[k].reader[i]).back.year)d=1;//判断是否已过了还书日期,d=1还没过期,d=0过期
if(year<=((*H).elem[k].reader[i]).back.year&&month<((*H).elem[k].reader[i]).back.month)d=1;
if(year<=((*H).elem[k].reader[i]).back.year&&month<=((*H).elem[k].reader[i]).back.month&&day<((*H).elem[k].reader[i]).back.day)d=1;
if(d==0)
{
pay=(year-((*H).elem[k].reader[i]).back.year)*365+(month-((*H).elem[k].reader[i]).back.month)*30+(day-((*H).elem[k].reader[i]).back.day);
printf("\n\t你在%d-%d-%d借了这本书",((*H).elem[k].reader[i]).bro.year,((*H).elem[k].reader[i]).bro.month,((*H).elem[k].reader[i]).bro.day);
printf("\n\t你应该在%d-%d-%d还这本书",((*H).elem[k].reader[i]).back.year,((*H).elem[k].reader[i]).back.month,((*H).elem[k].reader[i]).back.day);
printf("\n\t今天是%d-%d-%d",year,month,day);
printf("\n\n\t所以你超出了还书日期");
printf("\n\t你应该被罚款%2.1f元.",0.1*pay);//过期一天还1角钱
}
((*H).elem[k].reader[i]).num[0]='\0';//已还,清除该读者借书记录
(*H).elem[k].current++;//现存书量加1
printf("\n\t你已经还了这本书.\n");
}
}
elseprintf("\n\t你要还一本没库存的书?
?
?
\n");
}
voidSaveBook(HashTableH){
FILE*fp1;
inti;
fp1=fopen("C:
/record.txt","w");
fprintf(fp1,"===============图书信息记录表=================\n");
for(i=0;i{
if(H.elem[i].key!
=NULL_KEY)
{
fprintf(fp1,"============================================\n");
fprintf(fp1,"图书编号:
%d\n",H.elem[i].key);
fprintf(fp1,"书名:
%s\n",H.elem[i].title);
fprintf(fp1,"作者:
%s\n",H.elem[i].writer);
fprintf(fp1,"现库存量:
%d\n",H.elem[i].current);
fprintf(fp1,"总库存量:
%d\n",H.elem[i].total);
}
}
fprintf(fp1,"**************************************************\n");
fclose(fp1);
printf(