图书管理系统c语言绝对可以用.docx
- 文档编号:6905407
- 上传时间:2023-01-12
- 格式:DOCX
- 页数:22
- 大小:18.56KB
图书管理系统c语言绝对可以用.docx
《图书管理系统c语言绝对可以用.docx》由会员分享,可在线阅读,更多相关《图书管理系统c语言绝对可以用.docx(22页珍藏版)》请在冰豆网上搜索。
图书管理系统c语言绝对可以用
#include
#definebooksize100
#defineblhnum50
#definerrunm50
#include
typedefstruct{
intbno;
charbname[21];
intnamenext;
charauthor[9];
intauthnext;
charpress[11];
intprenext;
charsortno[4];
intstorenum;
intborrownum;
}bookrectype;
typedefstruct{
bookrectypebookdbase[booksize];
intlen;
}bookdbasefile;
typedefstruct{
intbno;
intrecno;
}bidxrectype;
typedefstruct{
bidxrectypebnoidx[booksize];
intlen;
}bnoidxfile;
typedefstruct{
charbname[21];
intlhead;
intrecnum;
}bnrectype;
typedefstruct{
bnrectypelhfrec1[blhnum];
intlen1;
}lhfile1;
typedefstruct{
charauthor[9];
intlhead;
intrecnum;
}barectype;
typedefstruct{
barectypelhfrec2[blhnum];
intlen2;
}lhfile2;
typedefstruct{
charpress[11];
intlhead;
intrecnum;
}bprectype;
typedefstruct{
bprectypelhfrec3[blhnum];
intlen3;
}lhfile3;
typedefstruct{
intrno;
charname[8];
intbn1;
intbn2;
}rrectype;
typedefstruct{
rrectypereadrec[rrunm];
intlen;
}readerfile;
typedefstruct{
intrno;
intrecno;
}ridxrectype;
typedefstruct{
ridxrectypernoidx[rrunm];
intlen;
}rnoidxfile;
typedefstruct{
intrno;
intbno;
chardate1[9];
chardate2[9];
}bbookrectype;
typedefstruct{
bbookrectypebbook[booksize];
intlen;
}bbookfile;
bookdbasefileappedbaserec(bookdbasefilebf)
{inti;
i=++bf.len;
printf("书号书名作者名出版商分类号藏书量\n");
scanf("%d%s",&bf.bookdbase[i].bno,bf.bookdbase[i].bname);
scanf("%s%s",&bf.bookdbase[i].author,bf.bookdbase[i].press);
scanf("%s%d",&bf.bookdbase[i].sortno,&bf.bookdbase[i].storenum);
bf.bookdbase[i].borrownum=0;
returnbf;
}
bnoidxfilechangebnoidxf(bookdbasefilebf,bnoidxfilebif)
{inti,j,k=1;
i=bf.len;
j=bif.len;
while(j>=1)
{
if(bf.bookdbase[i].bno>bif.bnoidx[i].bno)
{k=j+1;break;}
j--;
}
if(bif.len>0)
for(j=bif.len;j>=k;j--)
bif.bnoidx[j+1]=bif.bnoidx[j];
bif.bnoidx[k].bno=bf.bookdbase[i].bno;
bif.bnoidx[k].recno=i;
bif.len++;
returnbif;
}
lhfile1changelinkheabf1(bookdbasefile*bf,lhfile1lhf1)
{inti,j,k,m;
charsm[21];
i=bf->len;
strcpy(sm,bf->bookdbase[i].bname);
j=1;k=0;
while(j<=lhf1.len1)
{
if(strcmp(sm,lhf1.lhfrec1[j].bname)==0)
{k=j;break;}
j++;
}
if(k!
=0)
{
bf->bookdbase[i].namenext=lhf1.lhfrec1[k].lhead;
lhf1.lhfrec1[k].lhead=i;
lhf1.lhfrec1[k].recnum++;
}
else
{m=++lhf1.len1;
bf->bookdbase[i].namenext=0;
lhf1.lhfrec1[m].lhead=i;
lhf1.lhfrec1[m].recnum=1;
strcpy(lhf1.lhfrec1[m].bname,sm);
}
returnlhf1;
}
lhfile2changelinkheabf2(bookdbasefile*bf,lhfile2lhf2)
{inti,j,k,m;
charzz[9];
i=bf->len;
strcpy(zz,bf->bookdbase[i].author);
j=1;k=0;
while(j<=lhf2.len2)
{
if(strcmp(zz,lhf2.lhfrec2[j].author)==0)
{k=j;break;}
j++;
}
if(k!
=0)
{
bf->bookdbase[i].authnext=lhf2.lhfrec2[k].lhead;
lhf2.lhfrec2[k].lhead=i;
lhf2.lhfrec2[k].recnum++;
}
else
{m=++lhf2.len2;
bf->bookdbase[i].authnext=0;
lhf2.lhfrec2[m].lhead=i;
lhf2.lhfrec2[m].recnum=1;
strcpy(lhf2.lhfrec2[m].author,zz);
}
returnlhf2;
}
lhfile3changelinkheabf3(bookdbasefile*bf,lhfile3lhf3)
{inti,j,k,m;
charcbs[11];
i=bf->len;
strcpy(cbs,bf->bookdbase[i].press);
j=1;k=0;
while(j<=lhf3.len3)
{
if(strcmp(cbs,lhf3.lhfrec3[j].press)==0)
{k=j;break;}
j++;
}
if(k!
=0)
{
bf->bookdbase[i].prenext=lhf3.lhfrec3[k].lhead;
lhf3.lhfrec3[k].lhead=i;
lhf3.lhfrec3[k].recnum++;
}
else
{m=++lhf3.len3;
bf->bookdbase[i].prenext=0;
lhf3.lhfrec3[m].lhead=i;
lhf3.lhfrec3[m].recnum=1;
strcpy(lhf3.lhfrec3[m].press,cbs);
}
returnlhf3;
}
intbinsearch(bnoidxfilebif,intkey)
{intlow,high,mid;
low=1;
high=bif.len;
while(low<=high)
{
mid=(low+high)/2;
if(key==bif.bnoidx[mid].bno)
returnbif.bnoidx[mid].recno;
elseif(key high=mid-1; elselow=mid+1; } return0; }//binsearch intbnamefind(lhfile1lhf1,charkey[]) {inti,k=0; for(i=1;i<=lhf1.len1;i++) {if(strcmp(key,lhf1.lhfrec1[i].bname)==0) { k=lhf1.lhfrec1[i].lhead;break; } } returnk; } intbauthfind(lhfile2lhf2,charkey[]) {inti,k=0; for(i=1;i<=lhf2.len2;i++) {if(strcmp(key,lhf2.lhfrec2[i].author)==0) { k=lhf2.lhfrec2[i].lhead;break; } } returnk; } intbpressfind(lhfile3lhf3,charkey[]) {inti,k=0; for(i=1;i<=lhf3.len3;i++) {if(strcmp(key,lhf3.lhfrec3[i].press)==0) { k=lhf3.lhfrec3[i].lhead;break; } } returnk; } voidshowrec(bookdbasefilebf,inti) { printf("书号书名作者名出版社分类号可借数\n"); printf("===============================================================\n"); printf("%d%13s",bf.bookdbase[i].bno,bf.bookdbase[i].bname); printf("%8s%12s",bf.bookdbase[i].author,bf.bookdbase[i].press); printf("%6s",bf.bookdbase[i].sortno); printf("%7d\n",bf.bookdbase[i].storenum,bf.bookdbase[i].borrownum); printf("===============================================================\n"); } voidsearchbook(bookdbasefilebf,bnoidxfilebif,lhfile1f1,lhfile2f2,lhfile3f3) {charsm[21],zz[9],cbs[11]; inti,k,choose=1; intsh; while(choose>=1&&choose<=5) { printf("图书查询子系统\n"); printf("----------------------\n"); printf("1.书号2.书名\n"); printf("3.作者4.出版社\n"); printf("5.退出查询\n"); printf("----------------------\n"); printf("请用户选择: "); scanf("%d",&choose); switch(choose) { case1: printf("输入书号: ");scanf("%d",&sh); k=binsearch(bif,sh); if(k==0) { printf("没有要查找的图书,请检验是否输入有错\n"); break; } showrec(bf,k); break; case2: printf("输入书名: ");scanf("%s",&sm); k=bnamefind(f1,sm); if(k==0) { printf("没有要查找的图书,请检验是否输入有错\n"); break; } for(i=k;i;i=bf.bookdbase[i].namenext) showrec(bf,i); break; case3: printf("输入作者名: ");scanf("%s",&zz); k=bauthfind(f2,zz); if(k==0) { printf("没有要查找的图书,请检验是否输入有错\n"); break; } for(i=k;i;i=bf.bookdbase[i].authnext) showrec(bf,i); break; case4: printf("输入出版社: ");scanf("%s",&cbs); k=bpressfind(f3,cbs); if(k==0) { printf("没有要查找的图书,请检验是否输入有错\n"); break; } for(i=k;i;i=bf.bookdbase[i].prenext) showrec(bf,i); break; case5: return; } } } rnoidxfilechangernoidxf(readerfilerf,rnoidxfilerif) {inti,j,k=1; i=rf.len; j=rif.len; while(j>=1) { if(rf.readrec[i].rno>rif.rnoidx[i].rno) {k=j+1;break;} j--; } if(rif.len>0) for(j=rif.len;j>=k;j--) rif.rnoidx[j+1]=rif.rnoidx[j]; rif.rnoidx[k].rno=rf.readrec[i].rno; rif.rnoidx[k].recno=i; rif.len++; returnrif; } intrinsearch(rnoidxfilerif,intkey) {intlow,high,mid; low=1; high=rif.len; while(low<=high) { mid=(low+high)/2; if(key==rif.rnoidx[mid].rno) returnrif.rnoidx[mid].recno; elseif(key high=mid-1; elselow=mid+1; } return0; }//rinsearch readerfilereadermanage(readerfilerf) {inti; i=++rf.len; printf("输入读者号读者名可借图书数\n"); scanf("%d%s",&rf.readrec[i].rno,rf.readrec[i].name); scanf("%d",&rf.readrec[i].bn1); rf.readrec[i].bn2=0; returnrf; } voidborrowbook(bookdbasefile*bf,bnoidxfilebif,bbookfile*bbf,readerfile*rf,rnoidxfilerif) { charjyrq[9]; intsh,dzh; inti,j,k; printf("输入读者号书号借阅日期\n"); scanf("%d%d%s",&dzh,&sh,jyrq); k=rinsearch(rif,dzh);//查找读者文件 if(k==0) {printf("非法读者! \n");return;} if(rf->readrec[k].bn2>=rf->readrec[k].bn1) {printf("书已借满! \n");return;} j=binsearch(bif,sh);//查找图书文件 if(j==0) {printf("非法书号! \n");return;} if(bf->bookdbase[j].borrownum>=bf->bookdbase[j].storenum) {printf("图书已借出! \n");return;} i=++bbf->len;//借还书记录数加1 bbf->bbook[i].rno=dzh;//借还书文件追加一条记录,记录相关内容 bbf->bbook[i].bno=sh; strcpy(bbf->bbook[i].date1,jyrq); rf->readrec[k].bn2++;//读者借出数加1 bf->bookdbase[j].borrownum++;//图书借出数加1 printf("借书成功! \n"); } voidbackbook(bookdbasefile*bf,bnoidxfilebif,bbookfile*bbf,readerfile*rf,rnoidxfilerif) {charhsrq[9]; intsh,dzh; inti,j,k,m=0; printf("读者号书号还书日期\n"); scanf("%d%d%s",&dzh,&sh,hsrq); k=rinsearch(rif,dzh);//查找读者文件 if(k==0) {printf("非法读者! \n");return;} for(i=1;i<=bbf->len;i++)//查询借还书文件 if(sh==bbf->bbook[i].bno) {m=i;break;} if(m==0){printf("非法书号! \n");return;} j=binsearch(bif,sh);//查找图书文件 if(j==0) {printf("非法书号! \n");return;} strcpy(bbf->bbook[m].date2,hsrq);//填入还书日期 rf->readrec[k].bn2--;//修改借书数 bf->bookdbase[j].borrownum--;//修改借出数 printf("还书成功! \n"); } voidwritefile(bookdbasefilebf,bnoidxfilebif,lhfile1f1, lhfile2f2,lhfile3f3,readerfilerf,bbookfilebbf,rnoidxfilerif) {FILE*fp;inti; //写图书主文件 fp=fopen("book","wb"); for(i=1;i<=bf.len;i++) fwrite(&bf.bookdbase[i],sizeof(bookrectype),1,fp); fclose(fp); //写图书索引文件 fp=fopen("bidx","wb"); for(i=1;i<=bif.len;i++) fwrite(&bif.bnoidx[i],sizeof(bidxrectype),1,fp); fclose(fp); //写书名索引链头文件 fp=fopen("nidx","wb"); for(i=1;i<=f1.len1;i++) fwrite(&f1.lhfrec1[i],sizeof(bnrectype),1,fp); fclose(fp); //写作者索引链头文件 fp=fopen("aidx","wb"); for(i=1;i<=f2.len2;i++) fwrite(&f2.lhfrec2[i],sizeof(barectype),1,fp); fclose(fp); //写出版社索引链头文件 fp=fopen("pidx","wb"); for(i=1;i<=f3.len3;i++) fwrite(&f3.lhfrec3[i],sizeof(bprectype),1,fp); fclose(fp); //写读者文件 fp=fopen("read","wb"); for(i=1;i<=rf.len;i++) fwrite(&rf.readrec[i],sizeof(rrectype),1,fp); fclose(fp); //写借还书文件 fp=fopen("bbf","wb"); for(i=1;i<=bbf.len;i++) fwrite(&bbf.bbook[i],sizeof(bbookrectype),1,fp); fclose(fp); //写读者号文件 fp=fopen("ridx","wb"); for(i=1;i<=rif.len;i++) fwrite(&rif.rnoidx[i],sizeof(ridxrectype),1,fp); fclose(fp); } voidreadfile(bookdbasefile*bf,bnoidxfile*bif,lhfile1*f1, lhfile2*f2,lhfile3*f3,readerfile*rf,bbookfile*bbf,rnoidxfile*rif)
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 图书 管理 系统 语言 绝对 可以
![提示](https://static.bdocx.com/images/bang_tan.gif)