#include
#include
#include
#include
#include
structbook{
charnumber[100];
chartittle[100];
charwriter[100];
charpublisher[100];
chardate[100];
charprice[100];
charstatus[100];
charreader[100];
};
voidsearch_book();
voidborrow_book();
voidreturn_book();
voidadd_book();
voiddelete_book();
voidmodify_book();
voidscan_book();
intmain()
{
intc1=0,c2,c3;
intl,x,z;
while(1)
{
system("color2C");
printf("\t\t\t^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^\n");
printf("\t\t\t|*-*-*-图书管理系统*-*-*|\n");
printf("\t\t\t*[1]用户登录*\n");
printf("\t\t\t*[2]管理员登录*\n");
printf("\t\t\t^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^\n");
printf("\n");
printf("请选择操作:");
scanf("%d",&c1);
system("cls");
break;
}
if(c1==1)
{
while(1){
system("color2C");
printf("\t\t\t^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^\n");
printf("\t\t\t|*-*-*-图书管理系统*-*-*|\n");
printf("\t\t\t*[1]查询图书*\n");
printf("\t\t\t|[2]借阅图书|\n");
printf("\t\t\t*[3]借图书*\n");
printf("\t\t\t*[4]浏览图书信息*\n");
printf("\t\t\t|[5]退图书管理系统|\n");
printf("\t\t\t^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^\n");
printf("\n");
printf("请选择操作:");
scanf("%d",&c2);
getchar();
switch(c2)
{
case1:search_book();break;
case2:borrow_book();break;
case3:return_book();break;
case4:scan_book();break;
case5:system("cls");return0;
}
}
}
if(c1==2)
{
while(1){
system("color2C");
printf("\t\t\t^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^\n");
printf("\t\t\t|*-*-*-图书管理系统*-*-*|\n");
printf("\t\t\t|[1]添加图书|\n");
printf("\t\t\t*[2]删减图书*\n");
printf("\t\t\t|[3]修改图书信息|\n");
printf("\t\t\t*[4]浏览图书信息*\n");
printf("\t\t\t|[5]退图书管理系统|\n");
printf("\t\t\t^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^\n");
printf("\n");
printf("请选择操作:");
scanf("%d",&c3);
getchar();
switch(c3)
{
case1:add_book();break;
case2:delete_book();break;
case3:modify_book();break;
case4:scan_book();break;
case5:system("cls");return0;
}
}
}
}
voidsearch_book()
{
FILE*fp;
structbookn;
structbooknn;
intl,r;
charx,z;
fp=fopen("F:\\课程设计\\图书管理系统.txt","rb");
while(1)
{
l=0;
system("cls");
printf("请输入图书名称:");
scanf("%s",n.tittle);
fflush(stdin);
rewind(fp);
while(1)
{
fread(&nn,sizeof(nn),1,fp);
if(feof(fp))
break;
r=strcmp(n.tittle,nn.tittle);
if(r==0)
{
l=1;
break;
}
}
if(l==0)
{
printf("没要查询图书\n\n");
}
else
{
printf("查询图书:");
printf("\n");
printf("****************************************\n");
printf("编号书名作者版社版间价格状态借阅者\n");
printf("\n");
printf("%s%s%s%s%s%s%s",nn.number,nn.tittle,nn.writer,nn.publisher,nn.date,nn.price,nn.status,nn.reader);
printf("\n\n\n");
}
printf("否继续查询图书?[(y)/否(n)]?\n\n");
do
{
x=getche();
}while(x!='n'&&x!='y');
if(x=='n')
break;
}
fclose(fp);
system("cls");
}
//添加
voidadd_book()
{
FILE*fp;
structbookn;
structbooknn;
charx,z;
intl,r;
fp=fopen("F:\\课程设计\\图书管理系统.txt","ab+");
do
{
system("cls");
do
{
l=0;
printf("\n");
printf("编号书名作者版社版间价格状态借阅者\n");
fflush(stdin);
scanf("%s%s%s%s%s%s%s%s",n.number,n.tittle,n.writer,n.publisher,n.date,n.price,n.status,n.reader);
system("cls");
rewind(fp);
while(!feof(fp))
{
fread(&nn,sizeof(nn),1,fp);
r=strcmp(n.tittle,nn.tittle);
if(r==0)
{
l=1;
printf("该图书已存请输入新图书信息:\n\n");
break;
}
}
}while(l);
fwrite(&n,sizeof(n),1,fp);
printf("\n");
printf("否继续输入新图书信息[y/n]\n\n");
do
{
x=getche();
}while(x!='n'&&x!='y');
}while(x=='y');
fclose(fp);
system("cls");
}
//删除图书
voiddelete_book()
{
FILE*fp,*fp1;
charx,z;
structbookn;
structbooknn;
intl,r;
fp=fopen("F:\\课程设计\\图书管理系统.txt","ab+");
while(1)
{
l=0;
system("cls");
printf("\n");
printf("请输入需要删除图书名:\n\n");
fflush(stdin);
scanf("%s",&n.tittle);
rewind(fp);
while(1)
{
fread(&nn,sizeof(nn),1,fp);
if(feof(fp))
break;
r=strcmp(n.tittle,nn.tittle);
if(r==0)
{
l=1;
break;
}
}
if(l==0)
{
printf("\n");
printf("起未找该图书\n");
}
else
{
printf("\n");
printf("****************************************\n");
printf("编号书名作者版社版间价格状态借阅者\n");
printf("\n");
printf("%s%s%s%s%s%s%s%s",nn.number,nn.tittle,nn.writer,nn.publisher,nn.date,nn.price,nn.status,nn.reader);
printf("\n");
printf("确认删除图书信息[(y)/否(n)]\n\n");
do
{
z=getche();
}while(z!='n'&&z!='y');
if(z=='n')
break;
else
{
fp1=fopen("F:\\课程设计\\图书管理系统new.txt","wb");
rewind(fp);
while(1)
{
fread(&nn,sizeof(nn),1,fp);
if(feof(fp))
break;
r=strcmp(n.tittle,nn.tittle);
if(r!=0)
fwrite(&nn,sizeof(nn),1,fp1);
}
fclose(fp);
fclose(fp1);
fp=fopen("F:\\课程设计\\图书管理系统.txt","wb");
fp1=fopen("F:\\课程设计\\图书管理系统new.txt","rb");
while(1)
{
fread(&nn,sizeof(nn),1,fp1);
if(feof(fp1))
break;
fwrite(&nn,sizeof(nn),1,fp);
}
fclose(fp);
fclose(fp1);
}
}
printf("\n");
printf("否继续删除图书信息[(y)/否(n)]\n");
do
{
x=getche();
}while(x!='n'&&x!='y');
if(x=='n')
break;
}
fclose(fp);
system("cls");
}
//修改图书信息
voidmodify_book()
{
FILE*fp;
structbookn;
structbooknn;
intl,r;
charx,z;
fp=fopen("F:\\课程设计\\图书管理系统.txt","rb+");
while(1)
{
l=0;
printf("\n");
system("cls");
printf("请输入需要修改图书名:\n\n");
fflush(stdin);
scanf("%s",&n.tittle);
system("cls");
rewind(fp);
while(1)
{
fread(&nn,sizeof(nn),1,fp);
if(feof(fp))
break;
r=strcmp(n.tittle,nn.tittle);
if(r==0)
{
l=1;
break;
}
}
if(l==0)
{
printf("\n");
printf("起未找该图书信息\n\n");
}
else
{
printf("\n");
printf("****************************************\n");
printf("编号书名作者版社版间价格状态借阅者\n");
printf("\n");
printf("%s%s%s%s%s%s%s%s",nn.number,nn.tittle,nn.writer,nn.publisher,nn.date,nn.price,nn.status,nn.reader);
printf("请依修改图书信息\n\n\n");
fflush(stdin);
scanf("%s%s%s%s%s%s%s%s",n.number,n.tittle,n.writer,n.publisher,n.date,n.price,n.status,n.reader);
fseek(fp,sizeof(nn),1);
fwrite(&n,sizeof(nn),1,fp);
}
printf("\n");
printf("否继续修改用户信息[y/n]?\n\n");
do
{
x=getch();
}while(x!='n'&&x!='y');
if(x=='n')
break;
}
fclose(fp);
system("cls");
}
//借书
voidborrow_book()
{
FILE*fp;
structbookn;
structbooknn;
charx,z;
intl,r;
fp=fopen("F:\\课程设计\\图书管理系统.txt","rb+");
while(1)
{
l=0;
system("cls");
printf("\n");
printf("请输入需要借阅图书名:\n");
fflush(stdin);
scanf("%s",&n.tittle);
rewind(fp);
while(1)
{
fread(&nn,sizeof(nn),1,fp);
if(feof(fp))
break;
r=strcmp(n.tittle,nn.tittle);
if(r==0)
{
l=1;
break;
}
}
if(l==0)
{
printf("\n");
printf("起未找该图书\n");
}
else
{printf("\n");
printf("****************************************\n");
printf("编号书名作者版社版间价格状态借阅者\n");
printf("\n");
printf("%s%s%s%s%s%s%s%s",nn.number,nn.tittle,nn.writer,nn.publisher,nn.date,nn.price,nn.status,nn.reader);
printf("\n");
fflush(stdin);
printf("请输入图书信息并修改库状态及借阅者信息");
printf("****************************************\n");
printf("编号书名作者版社版间价格状态借阅者\n");
printf("\n");
scanf("%s%s%s%s%s%s%s%s",n.number,n.tittle,n.writer,n.publisher,n.date,n.price,n.status,n.reader);
fseek(fp,sizeof(nn),1);
fwrite(&n,sizeof(nn),1,fp);
}
printf("\n");
printf("否继续借书[(y)/否(n)]\n\n");
do
{
x=getch();
}while(x!='n'&&x!='y');
if(x=='n')
break;
}
fclose(fp);
system("cls");
}
//书
voidreturn_book()
{
FILE*fp;
structbookn;
structbooknn;
charx,z;
intl,r;
fp=fopen("F:\\课程设计\\图书管理系统.txt","rb+");
while(1)
{
l=0;
system("cls");
printf("\n");
printf("请输入需要借图书名:\n");
fflush(stdin);
scanf("%s",&n.tittle);
rewind(fp);
while(1)
{
fread(&nn,sizeof(nn),1,fp);
if(feof(fp))
break;
r=strcmp(n.tittle,nn.tittle);
if(r==0)
{
l=1;
break;
}
}
if(l==0)
{
printf("\n");
printf("起未找该图书\n");
}
else
{
printf("\n");
printf("****************************************\n");
printf("编号书名作者版社版间价格状态借阅者\n");
printf("\n");
printf("%s%s%s%s%s%s%s%s",nn.number,nn.tittle,nn.writer,nn.publisher,nn.date,nn.price,nn.status,nn.reader);
printf("\n");
fflush(stdin);
printf("请输入图书信息并修改库状态\n\n");
printf("****************************************\n");
printf("编号书名作者版社版间价格状态借阅者\n");
printf("\n");
scanf("%s%s%s%s%s%s%s%s",n.number,n.tittle,n.writer,n.publisher,n.date,n.price,n.status,n.reader);
fseek(fp,-(int)sizeof(nn),1);
fwrite(&n,sizeof(nn),1,fp);
}
printf("\n");
printf("否继续书[(y)/否(n)]\n");
do
{
x=getche();
}while(x!='n'&&x!='y');
if(x=='n')
break;
}
fclose(fp);
system("cls");
}
//浏览
voidscan_book()
{
FILE*fp;
charx,z;
structbookn;
fp=fopen("F:\\课程设计\\图书管理系统.txt","rb");
rewind(fp);
system("cls");
while(1)
{
fread(&n,sizeof(n),1,fp);
if(feof(fp))
break;
else
{
printf("********************************************\n");
printf("编号书名作者版社版间价格状态借阅者\n");
printf("\n");
printf("%s%s%s%s%s%s%s%s",n.number,n.tittle,n.writer,n.publisher,n.date,n.price,n.status,n.reader);
printf("\n");
}
}
printf("\n");
printf("主菜单请按车");
do
{
x=getche();
}while(x!='\r');
if(x=='\r')
{
fclose(fp);
system("cls");
}
}