音像图书租借管理系统设计Word格式文档下载.docx
《音像图书租借管理系统设计Word格式文档下载.docx》由会员分享,可在线阅读,更多相关《音像图书租借管理系统设计Word格式文档下载.docx(51页珍藏版)》请在冰豆网上搜索。
structborrower{ //租借者信息
ﻩcharuname[100];
charbianhao[10];
structdateborrow;
ﻩintmoney;
ﻩstruct dateback;
int rent;
};
4.程序代码设计
(1)创建音像图书库
void build_book()
{
charch[10],op;
structlibrarya;
ﻩFILE*fp1=NULL;
fflush(stdin);
ﻩfp1=fopen("
d:
\\Library.txt"
"
a"
);
ﻩif(fp1==NULL)
{
ﻩprintf("
\n文件打开错误!
\n"
);
exit(0);
}
printf("\n 请输入音像图书的编号:
"
ﻩscanf("
%s"
a.bianhao);
ﻩstrcpy(ch,a.bianhao);
ﻩif(ch[0]!
='
B'&
&
ch[0]!
='V'
&&
ch[0]!
='R'
)
ﻩprintf(" 非法输入!
\n"
printf(" 请按任意键重新输入!
");
op=getchar();
op=getchar();
ﻩbuild_book();
ﻩ}
ﻩprintf("
请输入音像图书的名称:
ﻩscanf("
%s"
,a.name);
ﻩprintf("
请输入音像图书的原价:
ﻩscanf("%d"
&
a.price);
ﻩprintf(" 请输入音像图书的原数量:
ﻩscanf("
%d",&
a.amount);
ﻩprintf("
请输入音像图书的剩余数量:
scanf("
a.shengyu);
if(a.amount<
=a.shengyu)
{
ﻩﻩprintf("
原数量不得小于剩余数量!
请重新输入!
printf("
请输入音像图书的原数量:
scanf("
%d"
&a.amount);
ﻩprintf(" 请输入音像图书的剩余数量:
ﻩscanf("%d"
a.shengyu);
ﻩ}
fprintf(fp1,"
%s\t%s\t%d\t%d\t%d\n"
a.bianhao,a.name,a.price,a.amount,a.shengyu);
ﻩif(fclose(fp1)){
ﻩprintf("不能关闭文件!
ﻩexit(0);
ﻩprintf("
\n创建音像图书《%s》成功!
a.name);
printf("
\n输入任意键继续!
ﻩop=getchar();
op=getchar();
}
打开名为Library.txt的文件,将音像图书的编号、名称、原价、原数量和剩余数量写入文件中,然后关闭文件。
(2)租借音像图书
voidborrow_book()
{
ﻩstructlibrarya={0},b[Max]={0},*p1=NULL,*p2=NULL;
//b为结构数组
ﻩstruct borrowerc={0};
charch[10]={0},op;
intn=0,m=0;
ﻩFILE*fp1;
FILE*fp2;
fflush(stdin);
ﻩif((fp1=fopen("
d:
\\borrow.txt","a"
))==NULL){
ﻩprintf("
文件打开错误!
exit(0);
if((fp2=fopen("
\\Library.txt","
r"
))==NULL){
ﻩprintf("文件打开错误!
ﻩexit(0);
ﻩ}
printf("
请输入您的姓名:
"
ﻩscanf("
c.uname);
printf("请输入租借的书的编号:
ﻩscanf("
%s"
,c.bianhao);
ﻩprintf("
请输入租借的日期(年/月/日):
%d%c%d%c%d"
,&
c.borrow.year,&
c.borrow.ch1 ,&
c.borrow.month,&c.borrow.ch2,&
c.borrow.day);
strcpy(ch,c.bianhao);
ﻩfprintf(fp1,"
%s\t%s\t%d%c%d%c%d "
c.uname,c.bianhao,c.borrow.year,c.borrow.ch1,c.borrow.month,c.borrow.ch2,c.borrow.day);
p1=b;
ﻩwhile(feof(fp2)==0)
ﻩ{
ﻩfscanf(fp2,"%s%s%d%d%d",p1->
bianhao,p1->
name,&
p1->price,&
p1->
amount,&
p1->
shengyu);
ﻩp1++;
ﻩn++;
ﻩfor(p1=b;
p1<
b+n;
p1++)
ﻩif(strcmp(c.bianhao,p1->
bianhao)==0)
ﻩ{
ﻩﻩp2=p1;
ﻩﻩm=1;
ﻩﻩbreak;
ﻩﻩ}
ﻩif(m==0)
ﻩﻩprintf("
无此音像图书!
ﻩprintf("
输入任意键继续!
op=getchar();
op=getchar();
else
ﻩif((strcmp(ch,p2->bianhao)==0)&&(p2->
shengyu==0))
{
printf("
\n此音像图书已全部借出!
\n"
ﻩﻩprintf("
op=getchar();
op=getchar();
ﻩ}
ﻩelse
ﻩif((strcmp(ch,p2->
bianhao)==0)&
&(p2->
shengyu!
=0))
ﻩ{
ﻩﻩ printf("
应交的押金额为 %d元!
,(p2->
price)*3);
ﻩ c.money=(p2->
price)*3;
p2->shengyu=p2->
shengyu-1;
ﻩﻩ
ﻩ fprintf(fp1,"
%d\n"
,c.money);
ﻩ fclose(fp1);
fclose(fp2);
ﻩ printf("
\n输入任意键继续!
ﻩ op=getchar();
op=getchar();
}
ﻩif((fp2=fopen("
\\Library.txt"
w"
))==NULL){
ﻩprintf("文件打开错误!
ﻩﻩexit(0);
ﻩfor(p1=b;
p1<
b+n;
p1++)
ﻩfprintf(fp2,"
%s\t%s\t%d\t%d\t%d\n",p1->
bianhao,p1->
name,p1->price,p1->
amount,p1->
shengyu);
fclose(fp2);
}
打开borrow.txt和Library.txt文件,将租借者的姓名、租借的书的编号和租借日期写入borrow.txt文件中,计算并显示应交押金,同时把押金写入borrow.txt文件该租借者的信息中,并且Library.txt文件中相应音像图书数量减少。
然后关闭文件。
(3)归还音像图书
voidback_book()
structlibrarya={0},b[Max]={0},*p1=NULL,*p2=NULL;
//b为结构数组
structborrowerc={0},d[Max]={0},*p3=NULL,*p4=NULL;
ﻩcharch[10]={0},ch1[100],op;
intday,n1=0,n2=0,m=0,rent,money_1;
ﻩintx,i;
ﻩint month_day[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}
ﻩ};
FILE*fp1;
ﻩFILE*fp2;
ﻩfflush(stdin);
if((fp1=fopen("
\\Library.txt"
))==NULL){
ﻩprintf("
文件打开错误!
exit(0);
if((fp2=fopen("
d:
\\borrow.txt"
))==NULL){
printf("
ﻩﻩexit(0);
printf("
请输入您的名字:
");
ﻩscanf("
%s",c.uname);
请输入归还的书的编号:
"
ﻩscanf("
%s"
c.bianhao);
ﻩprintf("
请输入归还的日期(年/月/日):
"
%d%c%d%c%d"
c.back.year,&
c.back.ch1,&
c.back.month,&c.back.ch2,&
c.back.day);
strcpy(ch,c.bianhao);
strcpy(ch1,c.uname);
ﻩ
//在文件中寻找被借的书
ﻩp1=b;
p3=d;
while(feof(fp1)==0)
ﻩfscanf(fp1,"%s%s%d%d%d"
p1->bianhao,p1->
name,&
p1->
price,&
p1->
amount,&p1->shengyu);
p1++;
ﻩn1++;
ﻩwhile(feof(fp2)==0)
ﻩfscanf(fp2,"%s%s%d%c%d%c%d%d"
p3->uname,p3->
bianhao,&
p3->
borrow.year,&p3->borrow.ch1,&p3->
borrow.month,&
p3->
borrow.ch2,&
p3->borrow.day,&
p3->
money);
ﻩﻩp3++;
n2++;
for(p1=b;
p1<
b+n1;
ﻩif(strcmp(ch,p1->
bianhao)==0)
ﻩﻩp2=p1;
break;
ﻩﻩ}
for(p3=d;
p3<
d+n2;
p3++)
ﻩif(strcmp(ch,p3->
bianhao)==0&
&strcmp(ch1,p3->
uname)==0)
ﻩﻩp4=p3;
ﻩﻩﻩm=1;
ﻩbreak;
//当输入的姓名或者借书的编号错误时
if(m==0)
ﻩﻩprintf("
您没有借书记录!
\n");
printf("
输入y重新填写资料,输入n返回上一菜单!
\n");
ﻩscanf(" %c"
&op);
ﻩif(op=='y'
ﻩback_book();
ﻩﻩif(op=='
n'
ﻩﻩsystem("
cls"
main();
ﻩﻩ
printf("\n此音像图书名为《%s》 \n"
,p2->name);
ﻩif((fp1=fopen("d:
\\Library.txt"
))==NULL){
printf("文件打开错误!
p2->
shengyu =p2->
shengyu+1;
ﻩfor(p1=b;
p1<b+n1;
p1++)
ﻩfprintf(fp1,"
%s\t%s\t%d\t%d\t%d\n"
,p1->bianhao,p1->
name,p1->
price ,p1->
amount,p1->
shengyu);
ﻩ//计算租借的总天数
x=(p4->
borrow.year%4==0&
p4->
borrow.year%100!
=0||p4->
borrow.year%400==0);
ﻩif(p4->borrow.year==c.back.year)
if(p4->
borrow.month==c.back.month)
ﻩﻩday=c.back.day-p4->
borrow.day;
ﻩelse
ﻩﻩ{
ﻩday=month_day[x][p4->
borrow.month]-p4->
borrow.day;
ﻩfor(i=p4->
borrow.month+1;
i<
c.back.month;
i++)
ﻩﻩﻩﻩday=day+month_day[x][i];
ﻩﻩﻩday=day+c.back.day;
ﻩ
printf("
一共租借了%d 天!
\n",day);
if(ch[0]=='
B')
ﻩrent=day;
ﻩif(ch[0]=='
V')
ﻩﻩrent=day*2;
if(ch[0]=='
R')
ﻩrent=day*3;
if(rent>
=p3->
money)
money_1=0;
if(rent<
money)
ﻩﻩmoney_1=p3->money-rent;
ﻩprintf("
已交押金%d元,应交租金%d元,应退金额%d元\n"
p4->
money,rent,money_1);
fclose(fp1);
ﻩfclose(fp2);
ﻩ//删除租借者的信息
p3=d;
n1=0;
if((fp2=fopen("d:
\\borrow.txt","r"
))==NULL){
ﻩprintf("文件打开错误!
\n"
ﻩexit(0);
ﻩ}
ﻩwhile(feof(fp2)==0)
fscanf(fp2,"%s%s%d%c%d%c%d%d"
p3->
uname,p3->
bianhao,&p3->borrow.year,&
p3->borrow.ch1,&
borrow.month,&p3->
borrow.ch2,&p3->
borrow.day,&
money);
ﻩﻩp3++;
ﻩn2++;
ﻩfclose(fp2);
for(p3=d;
d+n1;
p3++)
ﻩif(strcmp(ch1,p3->
uname)==0)
ﻩ{
ﻩp4=p3;
break;
if((fp2=fopen("d:
\\borrow.txt"
,"w"
))==NULL)
printf("文件打开错误!
ﻩ exit(0);
ﻩfor(p3=d;
p3<d+n1-1;
p3++)
ﻩ{
if(strcmp(p4->
uname,p3->
uname)==0)
ﻩﻩcontinue;
ﻩelse
ﻩ fprintf(fp1,"
%s%s %d%c%d%c%d%d"
uname,p3->
bianhao,p3->
borrow.year,p3->
borrow.ch1,p3->
borrow.month,p3->
borrow.ch2,p3->
borrow.day,p3->money);
成功删除%s 的信息!
\n",p4->uname);
ﻩprintf("
按任意键结束!
");
ﻩop=getchar();
op=getchar();
fclose(fp2);
打开borrow.txt和Library.txt文件,输入归还者的姓名、归还的书的编号和归还日期,计算租借天数,显示已交押金、应交租金、应退金额;
将borrow.txt中相应租借者的信息删除,Library.txt中相应音像图书的数量增加。
(4)购进音像图书
voidbuy_book()
ﻩstruct librarya={0},b[Max]={0},*p1=NULL,*p2=NULL;
//b为结构数组
char ch[10]={0},ch1[100]={0},op;
ﻩintn=0,m=1,number;
FILE*fp1;
ﻩfflush(stdin);
ﻩif((fp1=fopen("
\\Library.txt"
))==NULL){
exit(0);
ﻩprintf("
请输入购进音像图书的编号:
");
scanf("%s"
a.bianhao);
strcpy(ch,a.bianhao);
ﻩp1=b;
ﻩwhile(feof(fp1)==0)
ﻩfscanf(fp1,"%s%s%d%d%d"
p1->bianhao,p1->
name,&
p1->
price,&
amount,&
shengyu);
ﻩp1++;
n++;
fclose(fp1);
for(p1=b;
p1<b+n;
p1++)
ﻩif(strcmp(a.bianhao,p1->
bianhao)==0)
p2=p1;
ﻩstrcpy(ch1,p1->
name);
m=0;
ﻩﻩﻩbreak;
ﻩif(m)
if((fp1=fopen("
d:
\\Library.txt"
"a"))==NULL){
ﻩ printf("
ﻩ exit(0);
ﻩprintf("
请输入要购进音像图书的名称:
ﻩscanf("
a.name);
printf("
请输入要购进音像图书的原价:
scanf("
a.price);
printf("
请输入要购进音像图书的数量:
scanf("%d"
a.amount);
ﻩprintf("
购进音像图书《%s》成功!
a.name);
ﻩﻩa.shengyu=a.amount;
ﻩfprintf(fp1,"
%s\t%s\t%d\t%d\t%d\n"
,a.bianhao,a.name,a.price,a.amount,a.shengyu);
ﻩfclose(fp1);
}
else
ﻩ{
ﻩif((fp1=fopen("
\\Library.txt","
))==NULL){
printf("文件打开错误!
exit(0);
ﻩﻩprintf("
此书已存在!
printf("请输入要购进图书的数量:
"
ﻩscanf("%d",&
number);
printf("
购进音像图书《%s》成功!
ch1);
p2->
amount=p2->
amount+number;
ﻩp2->
shengyu=p2->
shengyu+number;
ﻩfor(p1=b;
p1<b+n;
ﻩfprintf(fp1,"
%s\t%s\t%d\t%d\t%d\n",p1->
bianhao,p1->
name,p1->
price,p1->
amount,p1->
shengyu);
printf("
按任意键结束!
op=getchar();
op=getchar();
fclose(fp1);
打开Library.txt文件,写入购进音像图书的编号,若音像图书已存在,则只输入购进数量;
并在文件中添加原有音像图书的数量,若不存在,则输入新音像图书的名称、原价及数量,并添加到文件中,然后关闭文件。
(5)报废音像图书
voidscrap_book()
ﻩstructlibrarya={0},b[Max]={0},*p1=NULL,*p2=NULL;
//b为结构数组
charch[10]={0},op;
intn=0,m=1;
FILE*fp1;
ﻩfflush(stdin);
if((fp1=fopen("
\\Library.txt"
,"
r"
))==NULL){
ﻩprintf("
\n");
ﻩexit(0);
ﻩprintf("
请输入要报废的书的编号:
ﻩscanf("
%s",a.bianhao