#include
#include
struct BOOK
{
int id,usr[10],total,store,days[10];
char name[31],author[21];
}books[100];
void page_title(char *menu_item)
{
clrscr();
printf(">>> tu shu guan li xi tong <<<\n\n- %s -\n\n",menu_item);
}
void return_confirm(void)
{
printf("\nan ren yi jian fan hui......\n");
getch();
}
int search_book(void)
{
int n,i;
printf("input book id:");
scanf("%d",&i);
for(n=0;n<100;n++)
{
if(books[n].id==i)
{
printf("books'name:%s\n",books[n].name);
printf("author:%s\n",books[n].author);
printf("rest books:%d of ",books[n].store);
printf("%d\n",books[n].total);
return n;
}
}
printf("\nerror input .\n");
return -1;
}
void book_out(void)
{
int n,s,l,d;
page_title("jie yue tu shu");
if((n=search_book())!=-1&&books[n].store>0)
{
printf("input jieshuzheng id:");
scanf("%d",&s);
printf("input kejietianshu:");
scanf("%d",&d);
for(l=0;l<10;l++)
{
if(books[n].usr[l]==0)
{
books[n].usr[l]=s;
books[n].days[l]=d;
break;
}
}
books[n].store--;
}
if(n!=-1&&books[n].store==0)
{
printf("ci shu yi quan bu jie chu!.\n");
return_confirm();
}
}
void book_in(void)
{
int n,s,l;
page_title("gui huan tu shu");
if((n=search_book())!=-1&&books[n].store
printf("reader's tushuzheng list:\n");
for(l=0;l<10;l++)
if(books[n].usr[l]!=0)
printf("[%d] - %d\n",books[n].usr[l],books[n].days[l]);
printf("input tushuzheng id:");
scanf("%d",&s);
for(l=0;l<10;l++)
{
if(books[n].usr[l]==s)
{
books[n].usr[l]=0;
books[n].days[l]=0;
break;
}
}
books[n].store++;
}
if(n!=-1&&books[n].store==books[n].total)
printf("all saved.\n");
return_confirm();
}
void book_add(void)
{
int n;
page_title("zhu ce xin shu");
for(n=0;n<100;n++)
if(books[n].id==0) break;
printf("id:");
scanf("%d",&books[n].id);
printf("name:");
scanf("%s",&books[n].name);
printf("author:");
scanf("%s",&books[n].author);
printf("total:");
scanf("%d",&books[n].total);
books[n].store=books[n].total;
return_confirm();
}
void book_del(void)
{
int n;
page_title("zhu xiao jiu shu");
if((n=search_book())!=-1) books[n].id=0;
printf("gai shu yi zhu xiao.\n");
return_confirm();
}
void main(void)
{
menu: page_title("cao zuo xuan dan");
printf("\n\nplease press numberbutton1,2,3,4 to play system below!\n\n");
printf("\n 1 jie yue tu shu\n\n 2 gui huan tu shu\n\n");
printf("\n 3 zhu ce xin shu\n\n 4 zhu xiao jiu shu\n\n");
printf("\n\n press 0 to exit\n");
switch(getch())
{
case '1' : book_out();break;
case '2' : book_in();break;
case '3' : book_add();break;
case '4' : book_del();break;
case '0' : exit(0);
}
goto menu;
}