#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
#include<conio.h>
#include<dos.h>
struct reader { /*读者链*/
char name [25]; /*读者姓名*/
char partment [45]; /*单位*/
unsigned number; /*借书证*/
int lend_num; /*借书总数*/
float punish; /*罚款*/
struct book_infor *bhead;
struct reader *rnext;
};
struct book_infor { /*读者所借图书信息*/
char name [45]; /*书名*/
int lendyear; /*借阅日期*/
int lendmonth;
int lendday;
int returnyear; /*归还日期*/
int returnmonth;
int returnday;
struct book_infor *next;
};
struct infor_A { /*馆藏图书信息*/
int subject;
int number; /*馆藏总数*/
int lend_num; /*借出数*/
int in_num; /*在馆数*/
float value; /*图书总金额*/
struct infor_B *head;
};
struct infor_B { /*每种图书的信息*/
char sort [5]; /*中图法分类号*/
char sort_name [45]; /*种类名称*/
int number; /*数目*/
int sort_num; /*本种类不同图书数目*/
int lend_num; /*借出数*/
int in_num; /*在馆数*/
float value; /*本种类图书金额*/
struct infor_B *next;
struct BOOK *first;
};
struct BOOK { /*每本图书的信息*/
unsigned book_num; /*图书编号*/
char name[45]; /*书名*/
char writer[5][25]; /*作者*/
char press[45]; /*出版社*/
char ISBN[40]; /*ISBN*/
int publish_num; /*版次*/
int number; /*馆藏数*/
int lend_num; /*借出数*/
int in_num; /*在馆数*/
int year; /*出版日期*/
int month;
int day;
int n; /*被借次数*/
float value; /*单价*/
struct BOOK *next;
struct student *first;
};
struct student { /*每本图书的借阅者链*/
char name [30]; /*姓名*/
char partment [45]; /*单位*/
unsigned card_num; /*借书证号*/
struct student *next;
};
struct buy_infor { /*购买信息*/
char name[40]; /*书名*/
char writer[15][25]; /*作者*/
int year; /*购买日期*/
int month;
int day;
int number;
float per_value; /*单价*/
float total_value; /*总价*/
long invoice_num; /*发票号码*/
unsigned book_num; /*图书编号*/
int i; /*数目*/
struct buy_infor *next;
};
struct BUY_INFOR { /*购买总信息*/
int number; /*总数量*/
int kind; /*种类*/
struct buy_infor *first;
};
struct MAIN {
int stu_num;
struct reader *head;
};
#define leap_y(year) ((year)%4==0&&(year)%100!=0||(year)%400==0?1:0)
int daytab[2][13]={
{0,31,28,31,30,31,30,31,31,30,31,30,31},
{0,31,29,31,30,31,30,31,31,30,31,30,31}
};
void draw (int,int,int,int,int);
void give_name (char []);
void create (struct infor_A *);
void read_file (struct infor_A *,FILE *);
void save (struct infor_A *,FILE *);
void delete_book (struct infor_A *);
void insert (struct infor_A *);
void borrow (struct infor_A *,struct MAIN *);
int return_book (struct infor_A *,struct MAIN *);
void search (struct infor_A *);
void look_into (struct infor_A *);
int day_of_year (int,int,int);
int day (int,int,int);
void create_reader (struct MAIN *);
void read_reader (struct MAIN *,FILE *);
void save_reader (struct MAIN *,FILE *);
void insert_reader (struct MAIN *);
void delete_reader (struct MAIN *);
void search_reader (struct MAIN *);
void rlook_into (struct MAIN *);
void create_buy_infor (struct BUY_INFOR *);
void read_buy_infor (struct BUY_INFOR *,FILE *);
void save_buy (struct BUY_INFOR *,FILE *);
void insert_book (struct BUY_INFOR *);
void delete_buy_infor (struct BUY_INFOR *);
void search_buy_infor (struct BUY_INFOR *);
void all_buy_infor (struct BUY_INFOR *);
void count (struct infor_A *);
void bookvalue (struct infor_A *);
void sort_punish (struct MAIN *);
void sort_reader (struct MAIN *);
void sort_book (struct infor_A *);
void main (void)
{
int i,y,key,key1,key2,key3,flag,dx,dy;
struct MAIN p;
struct infor_A p1;
struct BUY_INFOR p2;
FILE *fp;
char *chp []={
"BOOK",
"READER",
"PURCHASE",
"COUNT"
};
char *chp1 []={
"Insert",
"Delete",
"Search",
"LOOK",
"Quit alt+x"
};
char *chp2 []={
"Insert",
"Delete",
"Search",
"Borrow",
"Return",
"LOOK",
};
char *chp3 []={
"Insert infor",
"Delete infor",
"Search",
"LOOK"
};
char *chp4 []={
"Number of book",
"Value of book",
"Top 10 book",
"Top 5 reader",
"PUNISH infor"
};
char buf[16*20*2],buf1[16*2];
char ch;
key1=key2=0;
textbackground(BLUE);
clrscr();
window(1,1,80,1);
textbackground(WHITE);
textcolor(BLACK);
clrscr();
window(1,1,80,2);
for(i=0;i<4;i++)
cprintf(" %s",chp[i]);
dx=0;
while(1)
{
key=0;
while(bioskey(1)==0);
key=bioskey(0);
key=key&0xff?0:key>>8;
if(key==45)
exit(0);
if(key==48)
{
textcolor(WHITE);
window(1,2,80,25);
if((fp=fopen("library.dat","rb"))==NULL)
{
p1.head=NULL;
p1.subject=0;
p1.number=0;
p1.lend_num=0;
p1.in_num=0;
p1.value=0;
create(&p1);
printf("\nsave or not?(y/n)");
while(isspace(ch=getchar()));
if(ch=='y'||ch=='Y')
{
if((fp==fopen("library.dat","wb"))==NULL)
{
fprintf(stderr,"Can't create the file!");
return;
}
rewind(fp);
fwrite(&p1,sizeof(struct infor_A),1,fp);
save(&p1,fp);
fclose(fp);
}
}
else
{
fread(&p1,sizeof(struct infor_A),1,fp);
p1.head=NULL;
read_file(&p1,fp);
fclose(fp);
}
if((fp=fopen("reader.dat","rb"))==NULL)
{
p.head=NULL;
p.stu_num=0;
create_reader(&p);
printf("\nsave or not?(y/n)");
while(isspace(ch=getchar()));
if(ch=='y'||ch=='Y')
{
if((fp=fopen("reader.dat","wb"))==NULL)
{
fprintf(stderr,"Can't create the file!");
return;
}
rewind(fp);
fwrite(&p,sizeof(struct MAIN),1,fp);
save_reader(&p,fp);
fclose(fp);
}
}
else
{
fread(&p,sizeof(struct MAIN),1,fp);
p.head=NULL;
read_reader(&p,fp);
fclose(fp);
}
textbackground(BLUE);
clrscr();
dx=0;
window(1,1,80,1);
textbackground(WHITE);
textcolor(BLACK);
clrscr();
window(1,1,80,2);
for(i=0;i<4;i++)
cprintf(" %s",chp[i]);
textbackground(BLACK);
textcolor(WHITE);
gotoxy(8,1);
cprintf("%s",chp[0]);
gettext(8+dx,2,19+dx,10,buf);
window(8+dx,2,19+dx,10);
textbackground(WHITE);
textcolor(BLACK);
clrscr();
draw(1,1,16,9,BLACK);
for(i=2;i<7;