📄 pro2.c
字号:
printf("\nPlease input member's number:");
scanf("%s",temp);
pm=GetMember(temp);
if(pm->money!=0)
{
printf("the reader must pay back fine first,go to pay back?y/n(y):");
ch=getch();
if(ch=='n'||ch=='N')
return;
else
PayBack(pm);
}
while(1)
{
printf("\nplease input the booknumber to be returned:\n");
scanf("%s",temnum);
ReturnABook(pm,temnum);
printf("return another one?y/n(y):");
ch=getch();
if(ch=='n'||ch=='N')
break;
}
}
void ReturnABook(MEMBER *h,char tem[])
{
int i,m,n;
m=BookCheck1(h,tem);
if(m==-1)
printf("the booknumber isnot borrowed by the people\n");
else
{
n=h->count;
for(i=m;i<10-n-1;i++)
{
strcpy(h->book[i],h->book[i+1]);
h->bordate[i]=h->bordate[i+1];
h->retdate[i]=h->retdate[i+1];
}
h->count++;
for(pb=headb;pb!=NULL;pb=pb->next)
if(strcmp(pb->num,tem)==0)
{
pb->numexist++;
return;
}
}
}
void SearchBorrower()
{
char ch;
while(1)
{
printf("\nplease input the borrower's number:");
scanf("%s",temp);
pm=GetMember(temp);
if(pm!=NULL)
ShowBorrower(pm);
printf("Search anoter one?y/n(y):");
ch=getch();
if(ch=='n'||ch=='N')
break;
}
}
void ShowBorrower(MEMBER * h)
{
int i;
printf("\nThe borrower's infomation is followed:\n");
printf("name:%s\n",h->name);
printf("number:%s\n",h->num);
if(h->count==10)
{
printf("No book be borrowed\n");
return;
}
printf("\nhave borrowed %d :\n",10-h->count);
printf("num booknumber bordate retdate\n");
for(i=0;i<(10-(h->count));i++)
printf(" %d: %-20s%-10ld%-10ld\n",i+1,h->book[i],h->bordate[i],h->retdate[i]);
}
void DeleteBorrower()
{
int i;
char ch;
printf("\nplease input borrower's number to be deleted:");
scanf("%s",temp);
pm=GetMember(temp);
if(pm->count!=10)
{
printf("The borrower havenot return all the books.Are you want ot return books then delete?y/n(y)");
ch=getch();
if(ch=='n'||ch=='N')
return;
else
for(i=0;i<10-pm->count;i++)
ReturnABook(pm,pm->book[i]);
}
else
{
if(pm==headm)
headm=headm->next;
else if(pm==tailm)
{
tailm=qm;
tailm->next=NULL;
}
else
qm=pm->next;
free(pm);
}
}
void PrintBook()
{
pb=headb;
printf("\nbooknumber\t name\t sum_in_lib exist price\n");
while(pb!=NULL)
{
printf("%-20s%-20s%-14d%-9d%-6.2d\n",pb->num,pb->name,pb->numbook,pb->numexist,pb->price);
pb=pb->next;
}
printf("Press any key to continue...");
getch();
}
void PrintBorrower()
{
pm=headm;
printf("\nname\t\t number\t borrowed fine\n");
while(pm!=NULL)
{
printf("%-20s%-16s%-12d%-6.1f\n",pm->name,pm->num,10-pm->count,pm->money);
pm=pm->next;
}
printf("Press any key to continue...");
getch();
}
void SaveBook()
{
pb=headb;
if((fp=fopen("book.dat","wb"))==NULL)
{
printf("cannot open this file.\n");
getch();
exit(0);
}
while(pb!=NULL)
{
fwrite(pb,sizeof(BOOK),1,fp);
pb=pb->next;
}
printf("\nthe book data has been stored to book.dat");
fclose(fp);
getch();
}
void LoadBook()
{
while(headb!=NULL) /*释放已占用的内存*/
{
pb=headb;
headb=headb->next;
free(pb);
}
headb=tailb=NULL;
if((fp=fopen("book.dat","ab+"))==NULL)
{
printf("cannot open this file.\n");
getch();exit(0);
}
while(1)
{
qb=BUILDBOOK;
if((fread(qb,sizeof(BOOK),1,fp))!=1)
break;
if(headb==NULL)
headb=pb=qb;
else
{
pb->next=qb;
pb=qb;
}
}
tailb=pb;
tailb->next=NULL;
fclose(fp);
}
void LoadMember()
{
while(headm!=NULL) /*释放已占用的内存*/
{
pm=headm;
headm=headm->next;
free(pm);
}
headm=tailm=NULL;
if((fp=fopen("member.dat","ab+"))==NULL)
{
printf("cannot open this file.\n");
getch();exit(0);
}
while(1)
{
qm=BUILDMEMBER;
if((fread(qm,sizeof(MEMBER),1,fp))!=1)
break;
if(headm==NULL)
headm=pm=qm;
else
{
pm->next=qm;
pm=qm;
}
}
tailm=pm;
tailm->next=NULL;
fclose(fp);
}
void SaveMember()
{
pm=headm;
if((fp=fopen("member.dat","wb"))==NULL)
{
printf("cannot open this file.\n");
getch();
exit(0);
}
while(pm!=NULL)
{
fwrite(pm,sizeof(MEMBER),1,fp);
pm=pm->next;
}
printf("\nthe member data has been stored to member.dat");
fclose(fp);
getch();
}
int CheckDate(long a)
{
if(a/100000000>0)
{
printf("date format more than 8 bit,input again\n");
return 0;
}
else if(a/10000000==0)
{
printf("date format less than 8 bit,input again\n");
return 0;
}
else if((a%10000)/100>12)
{
printf("month format isnot fit,input again\n");
return 0;
}
else if(a%100>=31)
{
printf("day format isnot fit,input again\n");
return 0;
}
return 1;
}
void CheckFineMoney()
{
int i,year,month,day;
float m=0;
long l,a,b;
struct tm *tm;
time(&l);
tm=localtime(&l);
year=tm->tm_year+1900;
month=tm->tm_mon+1;
day=tm->tm_mday;
pm=headm;
while(pm!=NULL)
{
b=(long)year*10000+month*100+day;
for(i=0;i<10-pm->count;i++)
{
a=pm->retdate[i];
if(b>a)
{
m+=(year-a/10000)*365*30*0.1;
m+=(month-a%10000/100)*30*0.1;
m+=(day-a%100)*0.1;
}
}
pm->money=m;
pm=pm->next;
}
}
void PayBack(MEMBER *h)
{
printf("\nThe reader should pay %5.2f for the fine.press any key to pay...",h->money);
getch();
h->money=0;
}
void CountBooks()
{
int m=0,n=0;
for(pb=headb;pb!=NULL;pb=pb->next)
{
m+=pb->numbook;
n+=pb->numexist;
}
printf("number of total book is:%d\n",m);
printf("number of borrowed book is:%d\n",m-n);
printf("number of book exist in library is:%d\n",n);
printf("press any key to continue.....");
getch();
}
void CountMoney()
{
long l=0;
int sumbook=0;
for(pb=headb;pb!=NULL;pb=pb->next)
{
l+=(pb->price)*(pb->numbook);
sumbook+=pb->numbook;
}
printf("\namonut of money of books is %ld\naverage is %6.2f",l,l*1.0/sumbook);
printf("\npress any key to continue.....");
getch();
}
void Others()
{
char *menu[]={"1 Show members information","2 Show books information",
"3 Statistics book count","4 Statistics book money","5 Back up"};
char ch;
int i,flag=1;
while(flag)
{
clrscr();
for(i=0;i<5;i++)
printf("\n\t\t%s",menu[i]);
printf("\nPlease select one to run:");
ch=getch();
switch(ch)
{
case'1': PrintBorrower(); break;
case'2': PrintBook(); break;
case'3': CountBooks(); break;
case'4': CountMoney(); break;
case'5': flag=0;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -