C语言图书馆管理系统.docx
- 文档编号:30036133
- 上传时间:2023-08-04
- 格式:DOCX
- 页数:28
- 大小:18.92KB
C语言图书馆管理系统.docx
《C语言图书馆管理系统.docx》由会员分享,可在线阅读,更多相关《C语言图书馆管理系统.docx(28页珍藏版)》请在冰豆网上搜索。
C语言图书馆管理系统
#include
#include
#include
#include
#include
#defineTRUE1
#defineFALSE0
structmember
{
intmid;
charmname[20],madd[30];
structmsince
{
intday,mon,year;
}ms;
structmexpir
{
intday,mon,year;
}me;
}M;
structbook
{
structbkid
{
intgno,bno,no;
}b;
charbname[20],author[15],pub[20];
intprice;
}B;
structtransaction
{
intmid,tid;
structbookid
{
intgno,bno,no;
}b;
structissued
{
intday,mon,year;
}i;
structreturned
{
intday,mon,year;
}r;
floatfine;
charreason;
}T;
structdated;
FILE*fm,*fb,*ft;
char*mainmenu[]={
"Member",
"Book",
"Reports",
"Help",
"Exit"
};
char*memmenu[]={
"AddNewMember",
"RenewExistingMember",
"IssueDuplicateI-Card",
"Back"
};
char*bookmenu[]={
"AddNewBooks",
"IssueBook",
"ReturnBook",
"Back"
};
char*rptmenu[]={
"MembersDetails",
"BooksDetails",
"TransactionsDetails",
"Back"
};
voidmainscr();
voidshowmenu(char**menu,intcount,intsr,intsc);
intgetchoice(char**menu,char*hotkeys,intr,intc,intcount);
voidaddmember();
voidrenewmem();
voidmemdupid();
intmemcheck(intid);
voidaddbook();
voidissbook();
voidretbook();
intchkbook(intbno,intgno,intno);
voidtransac1(intmid,charch);
voidtransac2(intmid,intbno,intgno,intno,charc);
voidallmem();
voidallbook();
voidalltransac();
voidshowhelp();
/****************************MAIN******************************************/
voidmain()
{
intch,ch1,ch2,ch3;
fm=fopen("member.dat","a+");
ft=fopen("trans.dat","a+");
fb=fopen("book.dat","a+");
mainscr();
while
(1)
{
bk:
showmenu(mainmenu,5,10,35);
ch=getchoice(mainmenu,"MBRHE",10,35,5);
switch(ch)
{
case1:
bk1:
showmenu(memmenu,4,10,35);
ch1=getchoice(memmenu,"ARIB",10,35,4);
switch(ch1)
{
case1:
addmember();gotobk1;
case2:
renewmem();gotobk1;
case3:
memdupid();gotobk1;
case4:
gotobk;
}
break;
case2:
bk2:
showmenu(bookmenu,4,10,35);
ch2=getchoice(bookmenu,"AIRB",10,35,4);
switch(ch2)
{
case1:
addbook();gotobk2;
case2:
issbook();gotobk2;
case3:
retbook();gotobk2;
case4:
gotobk;
}
break;
case3:
bk3:
showmenu(rptmenu,4,10,35);
ch3=getchoice(rptmenu,"MBTB",10,35,4);
switch(ch3)
{
case1:
allmem();gotobk3;
case2:
allbook();gotobk3;
case3:
alltransac();gotobk3;
case4:
gotobk;
}
break;
case4:
showhelp();break;
case5:
fclose(ft);fclose(fm);fclose(fb);
exit();
}
}
}
/********************FunctionDoDisplayTheMainScreen*******************/
voidmainscr()
{
inti,j;
clrscr();
textcolor(BLUE);
for(i=1;i<80;i++)
for(j=1;j<24;j++)
{
gotoxy(i,j);cprintf("?
);
}
textbackground(BLUE);
textcolor(LIGHTMAGENTA);
gotoxy(8,1);
cprintf("赏屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯突");
gotoxy(8,2);
cprintf("?
赏屯屯屯屯屯屯屯屯屯屯屯屯?
?
);
gotoxy(8,3);
cprintf("掏屯屯屯屯屯屯屯屯屯凸WelcomeToObaidBooks掏屯屯屯屯屯屯屯屯?
);
gotoxy(8,4);
cprintf("?
韧屯屯屯屯屯屯屯屯屯屯屯屯?
?
);
gotoxy(8,5);
cprintf("韧屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯图");
textcolor(RED);
gotoxy(1,10);
cprintf("LoadingFilesPleaseWait...");
textcolor(DARKGRAY);
for(i=1;i<81;i++)
{
gotoxy(i,12);
cprintf("?
);
}
delay(200);
textcolor(LIGHTGRAY);
for(i=1;i<81;i++)
{
gotoxy(i,12);
cprintf("?
);
delay(50);
}
textcolor(WHITE);
for(i=1;i<81;i++)
{
gotoxy(i,12);
cprintf("?
);
delay(20);
}
textcolor(WHITE);
}
/**************************TheShowmenufunction***************************/
voidshowmenu(char**menu,intcount,intsr,intsc)
{
inti;clrscr();
textcolor(LIGHTMAGENTA);
gotoxy(8,1);
cprintf("赏屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯突");
gotoxy(8,2);
cprintf("?
赏屯屯屯屯屯屯屯屯屯屯屯屯?
?
);
gotoxy(8,3);
cprintf("掏屯屯屯屯屯屯屯屯屯凸WelcomeToObaidBooks掏屯屯屯屯屯屯屯屯?
);
gotoxy(8,4);
cprintf("?
韧屯屯屯屯屯屯屯屯屯屯屯屯?
?
);
gotoxy(8,5);
cprintf("韧屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯图");
for(i=0;i { gotoxy(sc,sr++);textcolor(DARKGRAY);cprintf(menu[i]); } } /***********************FuntionToGetUser'sChoice*************************/ intgetchoice(char**menu,char*hotkeys,intr,intc,intcount) { intchoice=1,hotkeychoice=1,ascii,scan; char*s; while (1) { gotoxy(c,r+choice-1);textcolor(WHITE+BLINK);cprintf(menu[choice-1]); while(! kbhit()) ; ascii=getch(); if(ascii==0) scan=getch(); gotoxy(c,r+choice-1);textcolor(DARKGRAY);cprintf(menu[choice-1]); if(ascii==0) { if(scan==80) choice++; if(scan==72) choice--; if(choice==0) choice=count; if(choice>count) choice=1; } else { if(ascii==13) return(choice); s=hotkeys; hotkeychoice=1; while(*s) { if(ascii==*s) return(hotkeychoice); hotkeychoice++; s++; } } } } /*********************FunctionToAddNewMembers****************************/ voidaddmember() { clrscr(); rewind(fm); while(fread(&M,sizeof(M),1,fm)==1) ; M.mid+=1; fseek(fm,0,SEEK_END); printf("\n\tEnterName: : "); fflush(stdin);gets(M.mname);M.mname[19]='';M.mname[20]='\0'; printf("\n\tEnterAdd: : "); fflush(stdin);gets(M.madd);M.madd[29]='';M.madd[30]='\0'; getdate(&d); M.ms.year=d.da_year;M.ms.day=d.da_day;M.ms.mon=d.da_mon; M.me.day=M.ms.day;M.me.year=M.ms.year;M.me.mon=(M.ms.mon+6); /*ToSetMonthAfterDecToJan*/ if(M.me.mon>12) { M.me.year+=1;M.me.mon=(M.me.mon-12); } /*IfSayTheOldDateis31/12/2003i.e31DecThenTheNewDateis31/06/2004i.e31Jun ButJunconsistsofOnly30dayssoweshalladd1dayextrasothecorrectDateis01/07/2004*/ if(M.me.day==31) {/*MonthsLikeApr,Jun,Sep,&Novhave30days*/ if(M.me.mon==4||M.me.mon==6||M.me.mon==9||M.me.mon==11) { M.me.day=1; M.me.mon+=1; } /*FortheMonthofFebthereare28OR29days*/ if(M.me.mon==2) {/*ForYearslike(1996,2000,2004etcthereare29daysinFeb*/ if((M.me.year%4)==0) { M.me.day=31-29;M.me.mon+=1; } else { M.me.day=31-28;M.me.mon+=1; } } } fwrite(&M,sizeof(M),1,fm); transac1(M.mid,'A'); } /**********************FunctionToRenewAMember****************************/ voidrenewmem() { FILE*tt; intno,ch; clrscr(); tt=fopen("temp1.dat","w"); printf("\n\tEnterMembershipId: : ");scanf("%d",&no); ch=memcheck(no); if(ch==FALSE) { printf("\n\tNoSuchMember.....");getch();return; } rewind(fm); while(fread(&M,sizeof(M),1,fm)==1) { if(M.mid==no) { M.me.mon=(M.me.mon+6); if(M.me.mon>12&&M.me.mon! =12) { M.me.year+=1;M.me.mon=(M.me.mon-12); } if(M.me.day==31) { if(M.me.mon==4||M.me.mon==6||M.me.mon==9||M.me.mon==11) { M.me.day=1; M.me.mon+=1; } if(M.me.mon==2) { if((M.me.year%4)==0) { M.me.day=31-29;M.me.mon+=1; } else { M.me.day=31-28;M.me.mon+=1; } } } fwrite(&M,sizeof(M),1,tt); } else fwrite(&M,sizeof(M),1,tt); } fclose(tt);fclose(fm); remove("member.dat"); rename("temp1.dat","member.dat"); fm=fopen("member.dat","a+"); printf("\n\tMemberRenewed.."); getch(); transac1(no,'E'); } /********************FunctionToIssueDuplicateIdCard*********************/ voidmemdupid() { intno,ch; clrscr(); printf("\n\tEnterMembershipId: : ");scanf("%d",&no); ch=memcheck(no); if(ch==FALSE) { printf("\n\tNoSuchMember.....");getch();return; } printf("\n\tDuplicateIDIssued...."); getch(); transac1(no,'D'); } /*************************FunctionToCheckAMember*************************/ intmemcheck(intid) { rewind(fm); while(fread(&M,sizeof(M),1,fm)==1) { if(M.mid==id) returnTRUE; } returnFALSE; } /*************FunctionToRecordTransactionMadeByMembers*****************/ voidtransac1(intmid,charch) { rewind(ft); while(fread(&T,sizeof(T),1,ft)==1) ; fseek(ft,0,SEEK_END); T.tid+=1;T.mid=mid; T.reason=ch; T.b.bno=0;T.b.gno=0;T.b.no=0; getdate(&d); T.i.day=d.da_day;T.i.mon=d.da_mon;T.i.year=d.da_year; T.r.day=0;T.r.mon=0;T.r.year=0; if(ch=='A') T.fine=500; elseif(ch=='E') T.fine=300; elseif(ch=='D') T.fine=50; fwrite(&T,sizeof(T),1,ft); } /*******************FunctionToAddBooksToTheLibrary*********************/ voidaddbook() { intnum,i; clrscr(); rewind(fb); while(fread(&B,sizeof(B),1,fb)==1) ; B.b.gno+=1;getdate(&d);B.b.bno=d.da_year; fseek(fb,0,SEEK_END); printf("\n\tEnterNoOfBooks: : ");scanf("%d",&num); fflush(stdin); printf("\nEnterName: : ");gets(B.bname);B.bname[19]='';B.bname[20]='\0'; fflush(stdin); printf("\nEnterAuthor'sName: : ");gets(B.author);B.author[14]='';B.author[15]='\0'; fflush(stdin); printf("\nEnterPublisher'sName: : ");gets(B.pub);B.pub[19]='';B.pub[20]='\0'; fflush(stdin); printf("\nEnterBookPrice: : ");scanf("%d",&B.price); for(i=0;i { B.b.no=i+1; fwrite(&B,sizeof(B),1,fb); } } /*******************FunctionToIssueBookToMembers***********************/ voidissbook() { inti,j,k,id; intf1,f2; clrscr(); gotoxy(5,1);cprintf("EnterBookid: : "); gotoxy(9,2);cprintf("/");gotoxy(13,2);cprintf("/"); gotoxy(5,2);scanf("%d",&i); gotoxy(10,2);scanf("%d",&j); gotoxy(14,2);scanf("%d",&k); f1=chkbook(i,j,k); if(f1==FALSE) { printf("\n\tNoSuchBook.....");getch();return; } printf("\n\tEnterMembershipid: : "); scanf("%d",&id); f2=memcheck(id); if(f2==FALSE) { printf("\n\tNoSuchMember.....");getch();return; } transac2(id,i,j,k,'I'); printf("\n\tBookIssued...."); getch(); } /*****************FunctionToReturnBookToTheLibrary*********************/ voidretbook() { inti,j,k,id; intf1,f2,f3; f3=FALSE; clrscr(); gotoxy(5,1);cprintf("EnterBookid: : "); gotoxy(9,2);cprintf("/");gotoxy(13,2);cprintf("/"); gotoxy
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 语言 图书馆 管理 系统