在线阅读图书系统项目源码(图书借阅管理系统源码)
本文目录一览:
- 1、急求C语言编写的图书管理系统源代码,具体要求如下
- 2、求c#图书管理系统 源代码+界面
- 3、急求一个c语言编写的图书管理系统的源代码,谢谢
- 4、急求用C语言编写的图书管理系统源代码
- 5、急求c语言程序设计 图书管理系统 源代码
- 6、图书管理系统C++ 源代码 求好心人帮帮忙
急求C语言编写的图书管理系统源代码,具体要求如下
/*这有个以前用过的程序,你可以自己改改使用,但是有些功
能好像有问题,会中断运行。至于程序的缩进式格式就你自己
敲回车和退格解决吧,不然代码看起来会很乱不好看。*/
#includestdio.h
#includestring.h
#includeconio.h
#includestdlib.h
#includectype.h
#define STACK_INIT_SIZE 10
#define OK 1
#define TRUE 1
#define FALSE 0
#define ERROR 0
struct student /*定义学生类型,用于存放借出的书籍*/
{
int carnum;
char lendbook[10];
}student[1000];
struct employ /*定义职工类型*/
{
int employnum;
char employname[15];
int employage;
char employsex[2];
char employleve[10];
long int employtage;
}employ[50];
struct book /*定义书的类型*/
{
int booknum;
char bookname[10];
char bookcreat[10];
int turefalse; /*用于借书和还书模块判断一本书是否借出的条件*/
}book[1000];
struct car /*借书卡的数据类型*/
{
int carnum;
char studentname[10];
int studentclass;
}car[100];
huanbook() /*还书函数*/
{
FILE *fp,*fp2; /*定义两个文件指针,fp2用于修改数据时设立临时文件用,防止数据遭破坏*/
int i,n;
int carnum;
char lendbook[10];
printf("请你输入你的卡号\n");
scanf("%d",carnum);
fp=fopen("car.txt","r"); /*读取卡号记录*/
for(i=0;fread(car[i],sizeof(struct car),1,fp)!=0;i++) /*for循环判断卡号是否存在*/
{
if(car[i].carnum==carnum) /*卡号存在,进入下一循环*/
{
n=i;
fclose(fp);
printf("请输入你要还的书的名字\n");
scanf("%s",lendbook);
fp=fopen("record.txt","r");
for(i=0;fread(student[i],sizeof(struct student),1,fp)!=0;i++) /*判断是否借阅了输入的书*/
{
if(strcmp(student[i].lendbook,lendbook)==0) /*借阅了该书,进入下一循环,否则出错显示*/
{
fclose(fp);
fp=fopen("record.txt","r");
fp2=fopen("bookl.txt","w");
for(i=0;fread(student[i],sizeof(struct student),1,fp)!=0;i++)
{
if(strcmp(student[i].lendbook,lendbook)==0)
{
continue; /*删除还掉的书的借书记录*/
}
fwrite(student[i],sizeof(struct student),1,fp2); /*写入原来没还的书的记录*/
}
fclose(fp);
fclose(fp2);
fp=fopen("record.txt","w");
fp2=fopen("bookl.txt","r");
for(i=0;fread(student[i],sizeof(struct student),1,fp2)!=0;i++)
{
fwrite(student[i],sizeof(struct student),1,fp); /*将借书记录信息写回*/
}
fclose(fp);
fclose(fp2);
fopen("bookl.txt","w"); /*清临时文件的记录*/
fclose(fp2);
fp=fopen("book.txt","r");
fp2=fopen("bookl.txt","w");
for(i=0;fread(book[i],sizeof(struct book),1,fp)!=0;i++) /*将书的记录写入临时文件,防止因为修改信息破坏以前的记录*/
{
if(i==n)
{
book[i].turefalse=1;
fwrite(book[i],sizeof(struct book),1,fp2); /*将还的书的原来状态设为无人借阅的*/
continue;
}
fwrite(book[i],sizeof(struct book),1,fp2);
}
fclose(fp);
fclose(fp2);
fp=fopen("book.txt","w");
fp2=fopen("bookl.txt","r");
for(i=0;fread(book[i],sizeof(struct book),1,fp2)!=0;i++)
{
fwrite(book[i],sizeof(struct book),1,fp); /*将临时文件写回*/
}
fclose(fp);
fclose(fp2);
fopen("bookl.txt","w"); /*清临时文件*/
fclose(fp2);
printf("还书完毕,按任意键返回\n");
getch();
return 1;
}
}
printf("你没有借这样的书,任意键返回\n"); /*出错提示*/
fclose(fp);
getch();
return 0;
}
}
printf("系统没这样的卡,和管理员联系,按任意键返回\n"); /*出错提示*/
fclose(fp);
getch();
}
findbook()
{
FILE *fp;
char bookname[10];
int ture,i;
fp=fopen("book.txt","r");
printf("请输入你要查找的书名\n");
scanf("%s",bookname);
for(i=0;fread(book[i],sizeof(struct book),1,fp)!=0;i++)
{
if(strcmp(bookname,book[i].bookname)==0)
{
if(book[i].turefalse==1)
{
printf("这本书的详细资料是:%d %s %s 此书现在无人借阅\n按任意键返回\n",book[i].booknum,book[i].bookname,book[i].bookcreat);
}
else {printf("这本书已经有人借出\n");fclose(fp);return 0;}
fclose(fp);
return FALSE;
}
}
printf("没有你要查询的书籍\n");
fclose(fp);
return FALSE;
}
findbook1()
{
FILE *fp;
char bookcreat[10];
int ture,i;
fp=fopen("book.txt","r");
printf("请输入你要查找的作者名\n");
scanf("%s",bookcreat);
for(i=0;fread(book[i],sizeof(struct book),1,fp)!=0;i++)
{
if(strcmp(bookcreat,book[i].bookcreat)==0)
{
if(book[i].turefalse==1)
{
printf("这本书的详细资料是:%d %s %s 此书现在无人借阅\n按任意键返回\n",book[i].booknum,book[i].bookname,book[i].bookcreat);
}
else {printf("这本书已经有人借出\n");fclose(fp);return 0;}
fclose(fp);
return FALSE;
}
}
printf("没有你要查询的书籍\n");
fclose(fp);
return FALSE;
}
lendcount()
{
FILE *fp;
int i,n=0;
fp=fopen("record.txt","r");
for(i=0;fread(student[i],sizeof(struct student),1,fp)!=0;i++)
{
printf("卡号:%d 借出的书籍:%s \n",student[i].carnum,student[i].lendbook);
n=n+1;
}
fclose(fp);
printf("目前共有%d本书借出\n",n);
printf("按任意键\n");
getch();
return n;
}
chabook()
{
char ch5;
do
{
printf("---------------欢迎进入图书查询系统!--------------\n");
printf(" 1:按书名查找\n");
printf(" 2:按作者查找\n");
printf(" 0:返回\n");
printf("请输入0--2,其他输入非法!\n");
scanf("%s",ch5);
switch(ch5)
{
case '1':findbook();getch();break;
case '2':findbook1();getch();break;
case '0':break;
default:printf("无此操作\n");getch();break;
}
}while(ch5!='0');
return FALSE;
}
lendbook()
{
FILE *fp,*fp2;
int i,n;
int carnum;
printf("请你输入你的卡号\n");
scanf("%d",carnum);
fp=fopen("car.txt","r");
for(i=0;fread(car[i],sizeof(struct car),1,fp)!=0;i++)
{
if(car[i].carnum==carnum)
{
n=i;
fclose(fp);
printf("请输入你要借阅的书的名字\n");
scanf("%s",student[n].lendbook);
fp=fopen("book.txt","r");
for(i=0;fread(book[i],sizeof(struct book),1,fp)!=0;i++)
{
if(strcmp(book[i].bookname,student[n].lendbook)==0)
{
if(book[i].turefalse==0) {printf("对不起,此书有人借出,请借其他书\n");fclose(fp);getch();return;}
else
fclose(fp);
fp=fopen("record.txt","a+");
student[n].carnum=carnum;
fwrite(student[n],sizeof(struct student),1,fp);
fclose(fp);
fp=fopen("book.txt","r");
fp2=fopen("bookl.txt","w");
for(i=0;fread(book[i],sizeof(struct book),1,fp)!=0;i++)
{
if(strcmp(book[i].bookname,student[n].lendbook)==0)
{
book[i].turefalse=0;
fwrite(book[i],sizeof(struct book),1,fp2);
continue;
}
fwrite(book[i],sizeof(struct book),1,fp2);
}
fclose(fp);
fclose(fp2);
fp=fopen("book.txt","w");
fp2=fopen("bookl.txt","r");
for(i=0;fread(book[i],sizeof(struct book),1,fp2)!=0;i++)
{
fwrite(book[i],sizeof(struct book),1,fp);
}
fclose(fp);
fclose(fp2);
fopen("bookl.txt","w");
fclose(fp2);
printf("借书完毕,按任意键返回\n");
getch();
return;
}
}
printf("不存在这样的书,任意键返回\n");
fclose(fp);
getch();
return;
}
}
printf("你的卡号不存在,请申请新卡,按任意键返回\n");
fclose(fp);
getch();
}
carcount()
{
FILE *fp;
int i,n=0;
fp=fopen("car.txt","r");
for(i=0;fread(car[i],sizeof(struct car),1,fp)!=0;i++)
{
printf("第%d张卡卡号:%d 姓名:%s 班级:%d\n",i+1,car[i].carnum,car[i].studentname,car[i].studentclass);
n=n+1;
}
fclose(fp);
printf("目前共有%d本书\n",n);
printf("按任意键\n");
getch();
}
delcar()
{
FILE *fp,*fp2;
int i;
int carnum;
char choice;
fp=fopen("car.txt","r");
fp2=fopen("bookl.txt","w");
printf("请输入你要删除的卡号\n");
printf("如果你输入的卡号存在,系统自动删除该信息!如果不存在,系统不做任何改动\n");
scanf("%d",carnum);
for(i=0;fread(car[i],sizeof(struct car),1,fp)!=0;i++)
{
if(car[i].carnum!=carnum)
{
fwrite(car[i],sizeof(struct car),1,fp2);
}
}
fclose(fp);
fclose(fp2);
printf("是否真的要删除该卡?删除后该书籍的所有信息将无法恢复《Y/N》\n");
scanf("%s",choice);
if(choice=='y'||choice=='Y')
{
fp=fopen("car.txt","w");
fp2=fopen("bookl.txt","r");
for(i=0;fread(car[i],sizeof(struct car),1,fp2)!=0;i++)
{
fwrite(car[i],sizeof(struct car),1,fp);
}
fclose(fp);
fclose(fp2);
fp2=fopen("bookl.txt","w");
fclose(fp2);
printf("按任意键返回\n");
getch();
return;
}
else
{
printf("按任意键返回\n");
getch();
return;
}
}
addcar()
{
FILE *fp;
int i=0;
fp=fopen("car.txt","a+");
printf("请你输入卡号\n");
scanf("%d",car[i].carnum);
printf("请你输入学生姓名\n");
scanf("%s",car[i].studentname);
printf("请你输入班级\n");
scanf("%d",car[i].studentclass);
fwrite(car[i],sizeof(struct car),1,fp);
fclose(fp);
printf("输入完毕,任意键返回\n");
getch();
}
changemploy()
{
FILE *fp,*fp2;
char employname[10],choice;
int i;
fp=fopen("employ.txt","r");
fp2=fopen("bookl.txt","w");
printf("请你输入要修改的职工的名字\n");
scanf("%s",employname);
for(i=0;fread(employ[i],sizeof(struct employ),1,fp)!=0;i++)
{
if(strcmp(employ[i].employname,employname)==0)
{
printf("你所要修改的职工的资料如下,请选择你要修改的内容\n");
printf("职工号:%d职工名:%s 年龄:%d 性别:%s 学历:%s 工资:%d\n",employ[i].employnum,employ[i].employname,employ[i].employage,employ[i].employsex,employ[i].employleve,employ[i].employtage);
printf("2:修改职工名\n");
printf("3:修改职工年龄\n");
printf("4:修改职工工资\n");
printf("5:修改职工学历\n");
printf("请输入1-5:");
scanf("%s",choice);
switch(choice)
{
case '1':
{
printf("请输入新的职工号\n");
scanf("%d",employ[i].employnum);
fwrite(employ[i],sizeof(struct employ),1,fp2);
}break;
case '2':
{
printf("请输入新的职工姓名\n");
scanf("%s",employ[i].employname);
fwrite(employ[i],sizeof(struct employ),1,fp2);
}break;
case '3':
{
printf("请输入新的年龄\n");
scanf("%d",employ[i].employage);
fwrite(employ[i],sizeof(struct employ),1,fp2);
}break;
case '4':
{
printf("请输入新的职工工资\n");
scanf("%d",employ[i].employtage);
fwrite(employ[i],sizeof(struct employ),1,fp2);
}break;
case '5':
{
printf("请输入新的职工学历\n");
scanf("%s",employ[i].employleve);
fwrite(employ[i],sizeof(struct employ),1,fp2);
}
default:printf("没有这样的操作");break;
}
continue;
}
fwrite(employ[i],sizeof(struct employ),1,fp2);
}
fclose(fp);
fclose(fp2);
fp=fopen("employ.txt","w");
fp2=fopen("bookl.txt","r");
for(i=0;fread(employ[i],sizeof(struct employ),1,fp2)!=0;i++)
{
fwrite(employ[i],sizeof(struct employ),1,fp);
}
fclose(fp);
fclose(fp2);
fp2=fopen("bookl.txt","w");
fclose(fp2);
printf("按任意键返回\n");
getchar();
return;
}
delemploy()
{
FILE *fp,*fp2;
int i;
char employname[10],choice;
fp=fopen("employ.txt","r");
fp2=fopen("bookl.txt","w");
printf("请输入你要删除的职工名\n");
printf("如果你输入的职工存在,系统自动删除该信息!如果不存在,系统不做任何改动\n");
scanf("%s",employname);
for(i=0;fread(employ[i],sizeof(struct employ),1,fp)!=0;i++)
{
if(strcmp(employname,employ[i].employname)!=0)
{
fwrite(employ[i],sizeof(struct employ),1,fp2);
}
}
fclose(fp);
fclose(fp2);
printf("是否真的要删除该职工信息?删除后的所有信息将无法恢复《Y/N》\n");
scanf("%s",choice);
if(choice=='y'||choice=='Y')
{
fp=fopen("employ.txt","w");
fp2=fopen("bookl.txt","r");
for(i=0;fread(employ[i],sizeof(struct employ),1,fp2)!=0;i++)
{
fwrite(employ[i],sizeof(struct employ),1,fp);
}
fclose(fp);
fclose(fp2);
fp2=fopen("bookl.txt","w");
fclose(fp2);
printf("按任意键返回\n");
getch();
return TRUE;
}
else
{
printf("按任意键返回\n");
getch();
return FALSE;
}
}
employcount()
{
FILE *fp;
int i,n=0;
fp=fopen("employ.txt","r");
for(i=0;fread(employ[i],sizeof(struct employ),1,fp)!=0;i++)
{
printf("第%d职工的信息如下:\n职工号:%d 职工名:%s 年龄:%d 性别:%s 学历:%s 工资:%d\n",n+1,employ[i].employnum,employ[i].employname,employ[i].employage,employ[i].employsex,employ[i].employleve,employ[i].employtage);
n++;
}
fclose(fp);
printf("目前共有%d个职工\n",n);
printf("按任意键返回\n");
}
addemploy()
{
FILE *fp;
char choice='y';
int i=1;
fp=fopen("employ.txt","a+");
while(choice=='y'||choice=='Y')
{
printf("请你输入职工号码\n");
scanf("%d",employ[i].employnum);
printf("请你输入职工名\n");
scanf("%s",employ[i].employname);
printf("请输入职工年龄\n");
scanf("%d",employ[i].employage);
printf("请你输入性别\n");
scanf("%s",employ[i].employsex);
printf("请你输入职工的学历水平\n");
scanf("%s",employ[i].employleve);
printf("请输入职工的工资\n");
scanf("%d",employ[i].employtage);
fwrite(employ[i],sizeof(struct employ),1,fp);
printf("是否要输入下个职工信息?\n");
scanf("%s",choice);
}
printf("按任意键返回\n");
fclose(fp);
}
addbook()
{
FILE *fp;
int i=0;
char choice='y';
fp=fopen("book.txt","a+");
while(choice=='y'||choice=='Y')
{
printf("请你输入第%d本书的序号\n",i+1);
scanf("%d",book[i].booknum);
printf("请你输入书名\n");
scanf("%s",book[i].bookname);
printf("请你输入书的作者\n");
scanf("%s",book[i].bookcreat);
printf("请设为1或0,1代表书还没人借,0表示书已经借出,设其他值,程序运行时无法得出正常结果\n");
printf("请你设定书的状态\n");
scanf("%d",book[i].turefalse);
fwrite(book[i],sizeof(struct book),1,fp);
printf("是否要输入下本书\n");
scanf("%s",choice);
}
fclose(fp);
}
bookcount()
{
FILE *fp;
int i,n=0;
fp=fopen("book.txt","r");
for(i=0;fread(book[i],sizeof(struct book),1,fp)!=0;i++)
{
if(book[i].booknum!=0strlen(book[i].bookname)!=0strlen(book[i].bookcreat)!=0)
{
printf("第%d本书序号:%d 书名:%s 作者:%s 状态:%d\n",i+1,book[i].booknum,book[i].bookname,book[i].bookcreat,book[i].turefalse);
n=n+1;
}
}
fclose(fp);
printf("目前共有%d本书\n",n);
printf("按任意键\n");
}
delbook()
{
FILE *fp,*fp2;
int i;
char bookname[10],choice;
fp=fopen("book.txt","r");
fp2=fopen("bookl.txt","w");
printf("请输入你要删除的书名\n");
printf("如果你输入的书名存在,系统自动删除该信息!如果不存在,系统不做任何改动\n");
scanf("%s",bookname);
for(i=0;fread(book[i],sizeof(struct book),1,fp)!=0;i++)
{
if(strcmp(bookname,book[i].bookname)!=0)
{
fwrite(book[i],sizeof(struct book),1,fp2);
}
}
fclose(fp);
fclose(fp2);
printf("是否真的要删除该书籍?删除后该书籍的所有信息将无法恢复《Y/N》\n");
scanf("%s",choice);
if(choice=='y'||choice=='Y')
{
fp=fopen("book.txt","w");
fp2=fopen("bookl.txt","r");
for(i=0;fread(book[i],sizeof(struct book),1,fp2)!=0;i++)
{
fwrite(book[i],sizeof(struct book),1,fp);
}
fclose(fp);
fclose(fp2);
fp2=fopen("bookl.txt","w");
fclose(fp2);
printf("按任意键返回\n");
getch();
return;
}
else
{
printf("按任意键返回\n");
getch();
return;
}
}
changebook()
{
FILE *fp,*fp2;
char bookname[10],choice;
int i;
fp=fopen("book.txt","r");
fp2=fopen("bookl.txt","w");
printf("请你输入要修改的书籍的书字\n");
scanf("%s",bookname);
for(i=0;fread(book[i],sizeof(struct book),1,fp)!=0;i++)
{
if(strcmp(book[i].bookname,bookname)==0)
{
printf("你所要修改的书的资料如下,请选择你要修改的内容\n");
printf("序号:〈%d〉 书名:〈%s〉 作者:〈%s〉 \n",book[i].booknum,book[i].bookname,book[i].bookcreat);
printf("1:修改书的序号\n");
printf("2:修改书名\n");
printf("3:修改作者\n");
printf("请输入1-3:");
scanf("%s",choice);
switch(choice)
{
case '1':
{
printf("请输入新的序号\n");
scanf("%d",book[i].booknum);
fwrite(book[i],sizeof(struct book),1,fp2);
}break;
case '2':
{
printf("请输入新的书名\n");
scanf("%s",book[i].bookname);
fwrite(book[i],sizeof(struct book),1,fp2);
}break;
case '3':
{
printf("请输入新的作者\n");
scanf("%s",book[i].bookcreat);
fwrite(book[i],sizeof(struct book),1,fp2);
}break;
defaut:printf("没有这样的操作");break;
}
continue;
}
fwrite(book[i],sizeof(struct book),1,fp2);
}
fclose(fp);
fclose(fp2);
fp=fopen("book.txt","w");
fp2=fopen("bookl.txt","r");
for(i=0;fread(book[i],sizeof(struct book),1,fp2)!=0;i++)
{
fwrite(book[i],sizeof(struct book),1,fp);
}
fclose(fp2);
fp2=fopen("bookl.txt","w");
fclose(fp2);
printf("按任意键返回\n");
getchar();
return;
}
main()
{
char ch1,ch2,ch3,ch4,ch5;
do
{
printf("\t\t请你选择操作类型:\n");
printf(" 1:查阅图书\n");
printf(" 2:借阅图书\n");
printf(" 3:管理系统\n");
printf(" 4:还书\n");
printf(" 0:退出\n");
printf("请输入0--4\n");
scanf("%s",ch1);
switch(ch1)
{
case '1':chabook();break;
case '2':lendbook();;break;
case '3':{
do
{
printf("---------------欢迎进入管理系统!--------------\n");
printf(" 1:增加图书\n");
printf(" 2:删除图书\n");
printf(" 3:修改图书资料\n");
printf(" 4:书籍统计\n");
printf(" 5:职工管理系统\n");
printf(" 6:学生管理系统\n");
printf(" 0:返回\n");
printf("请输入0--6,其他输入非法!\n");
scanf("%s",ch2);
switch(ch2)
{
case '1':addbook();
break;
case '2':delbook();break;
case '3':changebook();break;
case '4':bookcount();getch();break;
case '5':{do
{
printf("---------------欢迎进入职工管理系统!--------------\n");
printf(" 1:增加员工\n");
printf(" 2:删除员工\n");
printf(" 3:修改员工资料\n");
printf(" 4:员工统计\n");
printf(" 0:返回\n");
printf("请输入0--4,其他输入非法!\n");
scanf("%s",ch3);
switch(ch3)
{
case '1':addemploy();getch();break;
case '2':delemploy();break;
case '3':changemploy();break;
case '4':employcount();getch();break;
case '0':break;
default:printf("无此操作\n");getch();break;
}
}while(ch3!='0');}break;
case '6':{
do
{
printf("---------------欢迎进入学生管理系统!--------------\n");
printf(" 1:申请新卡\n");
printf(" 2:删除卡号\n");
printf(" 3:借书统计\n");
printf(" 4:卡号统计\n");
printf(" 0:返回\n");
printf("请输入0--4,其他输入非法!\n");
scanf("%s",ch4);
switch(ch4)
{
case '1':addcar();break;
case '2':delcar();break;
case '3':lendcount();break;
case '4':carcount();break;
case '0':break;
default:printf("无此操作\n");getch();break;
}
}while(ch4!='0');}break;
case '0':break;
default:printf("无此操作\n");getch();break;
}
}while(ch2!='0');}break;
case '4':huanbook();break;
case '0':break;
default:printf("无此操作\n");getch();break;
}
}while(ch1!='0');
}
求c#图书管理系统 源代码+界面
是网页的还是窗体的程序啊 可以看看
系统演示视频 希望适合
急求一个c语言编写的图书管理系统的源代码,谢谢
/* Note:Your choice is C IDE */
#include "stdio.h"
#includegraphics.h
#include "conio.h"
#includestdlib.h
#includestring.h
void main()
{void adm1(),adm2(),build(),huan(),borrow(),dele();
adm1();
}
void adm1()
{ FILE *fp,*p ;
char adp[20],password[20];
int i,n=0;
textbackground(2);
clrscr();
gotoxy(25,12);
fp=fopen("pass","r");
if(fp==NULL) { printf("no exit ");getch();exit(0);}
printf("input password:");
for(;;)
{
window(42,12,53,12);
textbackground(0);
clrscr();
gets(adp);
for(i=0;adp[i]!='\0';i++);
fgets(password,i+1,fp);
gotoxy(55,12);
if(strcmp(password,adp)==0) { window(55,12,70,12);clrscr();cprintf("YES");getch();adm2();getch();exit(0);}
else{ n++;
window(55,12,60,12);clrscr();gotoxy(55,12);cprintf("error");
for(i=0;i30;i++) delay(8000);
if(n==2) { window(55,12,70,12);clrscr();gotoxy(55,12);cprintf("once again");for(i=0;i=30;i++) delay(8000);}
if(n==3) { window(55,12,70,12);clrscr();gotoxy(55,12);cprintf("3 second out");for(i=0;i=30;i++) { delay(8000);}
exit(0);
}
}
fclose(fp);clrscr();
}
}
void adm2()
{ char a;
window(1,1,80,25);
clrscr();
for(;;)
{ clrscr();
gotoxy(30,8);printf("built a new user (B)");
gotoxy(30,10);printf("return book (R)");
gotoxy(30,12);printf("borrow books (J)");
gotoxy(30,14);printf("delete user (D)");
a=getch();
if(a=='b') build();
if(a=='r') huan();
if(a=='j') borrow();
if(a=='d') dele();
else continue;
}
}
void build()
{ FILE *f,*p;
char id[20],name[20],sex[2],age[3],grad[50];
window(1,1,80,25);
clrscr();
printf("ID number:");
scanf("%s",id);
printf("name:");
scanf("%s",name);
printf("sex:");
scanf("%s",sex);
printf("grad:");
scanf("%s",grad);
p=fopen(id,"w+");
if(p==NULL) { printf("can't build that user");getch();adm2();}
fprintf(p,"%s ",name);
fprintf(p,"%s ",id);
fprintf(p,"%s ",sex);
fprintf(p,"%s ",grad);
printf("bulid success");
getch();
fclose(p);
}
void huan()
{
FILE *fp,*p,*f;
char id[20],a[5][50],name[20],c;
int i=0,m,k; clrscr();
printf("input ID number:");
scanf("%s",id);
p=fopen(id,"r");
if(p==NULL) { printf("error");getch();fclose(p);exit(0);}
fscanf(p,"%s",name);
fclose(p);
fp=fopen(name,"r");
do{ fscanf(fp,"%s",a[i++]); }while(!feof(fp));
for(k=0;ki-1;k++) printf("\nbook %d: %s",k+1,a[k]);
fclose(fp);
f=fopen(name,"w+");
for(;;)
{
printf("\n\npress the book number that you want to return. \n\nPress 6 if you want to return all. \n\npress 7 to cancle.\n");
scanf("%d",m);
if(m==7) { for(k=0;ki-1;k++)
{
fprintf(f,"%s\n",a[k]);
}
fclose(f);
adm2();
}
if(m==6) remove(name);
if(m6)
for(k=0;ki-1;k++)
{ if(k!=m-1)
fprintf(f,"%s\n",a[k]);
}
printf("book %d has returned.",m);
printf("\ncontinue? (Y/N)");
c=getch();
if(c=='y') continue;
if(c=='n') { fclose(f);adm2(); }
}
}
void borrow()
{ FILE *f,*m,*p;
char id[20],book[5][50],name[20],c;
int i=0,n=0,k;
window(1,1,80,25);clrscr();
printf("please input the user's ID:");
scanf("%s",id);
m=fopen(id,"r");
if(m==NULL) { printf("user no exit"); getch();fclose(m);adm2();}
fscanf(m,"%s",name);
fclose(m);
p=fopen(name,"r");
if(p==NULL);
else
{ while(!feof(p))
{
fscanf(p,"%s",book[i]);
i++;
}
i--;
for(k=0;ki;k++) printf("\nbook %d :%s",k+1,book[k]);
}
fclose(p);
f=fopen(name,"w");
printf("\nhow many book do you want to borrow?:");
do{printf("\ninput:");scanf("%d",n); }while(i+n=6);
for(k=i;ki+n;k++)
{ printf("\nbook %d :",k+1);
scanf("%s",book[k]);
}
for(k=0;ki+n;k++) fprintf(f,"%s\n",book[k]);
fputc('\0',f);
printf("success");
fclose(f);
}
void dele()
{ FILE *fp,*f;
char id[20],a[4][20],c,b[5][50];
int i=0,j=0,k;
window(1,1,80,25);clrscr();
printf("Input ID number:");
scanf("%s",id);
fp=fopen(id,"r");
if(fp==NULL) { printf("\nuser isn't exit");getch(); fclose(fp);adm2();}
else while(!feof(fp))
{ fscanf(fp,"%s",a[i++]);}
printf("\nname: %s",a[0]);
printf("\nID: %s",a[1]);
printf("\nsex: %s",a[2]);
printf("\ngrad: %s",a[3]);
f=fopen(a[0],"r");
if(f==NULL);
else {
while(!feof(f))
{ fscanf(f,"%s",b[j++]);}
for(k=0;kj-1;k++) printf("\nbook %d: %s",k+1,b[k]);
}
printf("\nDo you want to delete? (Y/N): ");
c=getch();
fclose(fp);
fclose(f);
if(c=='y') { remove(id);remove(a[0]);printf("\nsuccess");getch();adm2();}
if(c=='n') adm2();
}
急求用C语言编写的图书管理系统源代码
#includestdio.h
#includestring.h
#includeconio.h
#includestdlib.h
#includectype.h
#define STACK_INIT_SIZE 10
#define OK 1
#define TRUE 1
#define FALSE 0
#define ERROR 0
struct student /*定义学生类型,用于存放借出的书籍*/
{
int carnum;
char lendbook[10];
}student[1000];
struct employ /*定义职工类型*/
{
int employnum;
char employname[15];
int employage;
char employsex[2];
char employleve[10];
long int employtage;
}employ[50];
struct book /*定义书的类型*/
{
int booknum;
char bookname[10];
char bookcreat[10];
int turefalse; /*用于借书和还书模块判断一本书是否借出的条件*/
}book[1000];
struct car /*借书卡的数据类型*/
{
int carnum;
char studentname[10];
int studentclass;
}car[100];
huanbook() /*还书函数*/
{
FILE *fp,*fp2; /*定义两个文件指针,fp2用于修改数据时设立临时文件用,防止数据遭破坏*/
int i,n;
int carnum;
char lendbook[10];
printf("请你输入你的卡号\n");
scanf("%d",carnum);
fp=fopen("car.txt","r"); /*读取卡号记录*/
for(i=0;fread(car[i],sizeof(struct car),1,fp)!=0;i++) /*for循环判断卡号是否存在*/
{
if(car[i].carnum==carnum) /*卡号存在,进入下一循环*/
{
n=i;
fclose(fp);
printf("请输入你要还的书的名字\n");
scanf("%s",lendbook);
fp=fopen("record.txt","r");
for(i=0;fread(student[i],sizeof(struct student),1,fp)!=0;i++) /*判断是否借阅了输入的书*/
{
if(strcmp(student[i].lendbook,lendbook)==0) /*借阅了该书,进入下一循环,否则出错显示*/
{
fclose(fp);
fp=fopen("record.txt","r");
fp2=fopen("bookl.txt","w");
for(i=0;fread(student[i],sizeof(struct student),1,fp)!=0;i++)
{
if(strcmp(student[i].lendbook,lendbook)==0)
{
continue; /*删除还掉的书的借书记录*/
}
fwrite(student[i],sizeof(struct student),1,fp2); /*写入原来没还的书的记录*/
}
fclose(fp);
fclose(fp2);
fp=fopen("record.txt","w");
fp2=fopen("bookl.txt","r");
for(i=0;fread(student[i],sizeof(struct student),1,fp2)!=0;i++)
{
fwrite(student[i],sizeof(struct student),1,fp); /*将借书记录信息写回*/
}
fclose(fp);
fclose(fp2);
fopen("bookl.txt","w"); /*清临时文件的记录*/
fclose(fp2);
fp=fopen("book.txt","r");
fp2=fopen("bookl.txt","w");
for(i=0;fread(book[i],sizeof(struct book),1,fp)!=0;i++) /*将书的记录写入临时文件,防止因为修改信息破坏以前的记录*/
{
if(i==n)
{
book[i].turefalse=1;
fwrite(book[i],sizeof(struct book),1,fp2); /*将还的书的原来状态设为无人借阅的*/
continue;
}
fwrite(book[i],sizeof(struct book),1,fp2);
}
fclose(fp);
fclose(fp2);
fp=fopen("book.txt","w");
fp2=fopen("bookl.txt","r");
for(i=0;fread(book[i],sizeof(struct book),1,fp2)!=0;i++)
{
fwrite(book[i],sizeof(struct book),1,fp); /*将临时文件写回*/
}
fclose(fp);
fclose(fp2);
fopen("bookl.txt","w"); /*清临时文件*/
fclose(fp2);
printf("还书完毕,按任意键返回\n");
getch();
return 1;
}
}
printf("你没有借这样的书,任意键返回\n"); /*出错提示*/
fclose(fp);
getch();
return 0;
}
}
printf("系统没这样的卡,和管理员联系,按任意键返回\n"); /*出错提示*/
fclose(fp);
getch();
}
findbook()
{
FILE *fp;
char bookname[10];
int ture,i;
fp=fopen("book.txt","r");
printf("请输入你要查找的书名\n");
scanf("%s",bookname);
for(i=0;fread(book[i],sizeof(struct book),1,fp)!=0;i++)
{
if(strcmp(bookname,book[i].bookname)==0)
{
if(book[i].turefalse==1)
{
printf("这本书的详细资料是:%d %s %s 此书现在无人借阅\n按任意键返回\n",book[i].booknum,book[i].bookname,book[i].bookcreat);
}
else {printf("这本书已经有人借出\n");fclose(fp);return 0;}
fclose(fp);
return FALSE;
}
}
printf("没有你要查询的书籍\n");
fclose(fp);
return FALSE;
}
findbook1()
{
FILE *fp;
char bookcreat[10];
int ture,i;
fp=fopen("book.txt","r");
printf("请输入你要查找的作者名\n");
scanf("%s",bookcreat);
for(i=0;fread(book[i],sizeof(struct book),1,fp)!=0;i++)
{
if(strcmp(bookcreat,book[i].bookcreat)==0)
{
if(book[i].turefalse==1)
{
printf("这本书的详细资料是:%d %s %s 此书现在无人借阅\n按任意键返回\n",book[i].booknum,book[i].bookname,book[i].bookcreat);
}
else {printf("这本书已经有人借出\n");fclose(fp);return 0;}
fclose(fp);
return FALSE;
}
}
printf("没有你要查询的书籍\n");
fclose(fp);
return FALSE;
}
lendcount()
{
FILE *fp;
int i,n=0;
fp=fopen("record.txt","r");
for(i=0;fread(student[i],sizeof(struct student),1,fp)!=0;i++)
{
printf("卡号:%d 借出的书籍:%s \n",student[i].carnum,student[i].lendbook);
n=n+1;
}
fclose(fp);
printf("目前共有%d本书借出\n",n);
printf("按任意键\n");
getch();
return n;
}
chabook()
{
char ch5;
do
{
printf("---------------欢迎进入图书查询系统!--------------\n");
printf(" 1:按书名查找\n");
printf(" 2:按作者查找\n");
printf(" 0:返回\n");
printf("请输入0--2,其他输入非法!\n");
scanf("%s",ch5);
switch(ch5)
{
case '1':findbook();getch();break;
case '2':findbook1();getch();break;
case '0':break;
default:printf("无此操作\n");getch();break;
}
}while(ch5!='0');
return FALSE;
}
lendbook()
{
FILE *fp,*fp2;
int i,n;
int carnum;
printf("请你输入你的卡号\n");
scanf("%d",carnum);
fp=fopen("car.txt","r");
for(i=0;fread(car[i],sizeof(struct car),1,fp)!=0;i++)
{
if(car[i].carnum==carnum)
{
n=i;
fclose(fp);
printf("请输入你要借阅的书的名字\n");
scanf("%s",student[n].lendbook);
fp=fopen("book.txt","r");
for(i=0;fread(book[i],sizeof(struct book),1,fp)!=0;i++)
{
if(strcmp(book[i].bookname,student[n].lendbook)==0)
{
if(book[i].turefalse==0) {printf("对不起,此书有人借出,请借其他书\n");fclose(fp);getch();return;}
else
fclose(fp);
fp=fopen("record.txt","a+");
student[n].carnum=carnum;
fwrite(student[n],sizeof(struct student),1,fp);
fclose(fp);
fp=fopen("book.txt","r");
fp2=fopen("bookl.txt","w");
for(i=0;fread(book[i],sizeof(struct book),1,fp)!=0;i++)
{
if(strcmp(book[i].bookname,student[n].lendbook)==0)
{
book[i].turefalse=0;
fwrite(book[i],sizeof(struct book),1,fp2);
continue;
}
fwrite(book[i],sizeof(struct book),1,fp2);
}
fclose(fp);
fclose(fp2);
fp=fopen("book.txt","w");
fp2=fopen("bookl.txt","r");
for(i=0;fread(book[i],sizeof(struct book),1,fp2)!=0;i++)
{
fwrite(book[i],sizeof(struct book),1,fp);
}
fclose(fp);
fclose(fp2);
fopen("bookl.txt","w");
fclose(fp2);
printf("借书完毕,按任意键返回\n");
getch();
return;
}
}
printf("不存在这样的书,任意键返回\n");
fclose(fp);
getch();
return;
}
}
printf("你的卡号不存在,请申请新卡,按任意键返回\n");
fclose(fp);
getch();
}
carcount()
{
FILE *fp;
int i,n=0;
fp=fopen("car.txt","r");
for(i=0;fread(car[i],sizeof(struct car),1,fp)!=0;i++)
{
printf("第%d张卡卡号:%d 姓名:%s 班级:%d\n",i+1,car[i].carnum,car[i].studentname,car[i].studentclass);
n=n+1;
}
fclose(fp);
printf("目前共有%d本书\n",n);
printf("按任意键\n");
getch();
}
delcar()
{
FILE *fp,*fp2;
int i;
int carnum;
char choice;
fp=fopen("car.txt","r");
fp2=fopen("bookl.txt","w");
printf("请输入你要删除的卡号\n");
printf("如果你输入的卡号存在,系统自动删除该信息!如果不存在,系统不做任何改动\n");
scanf("%d",carnum);
for(i=0;fread(car[i],sizeof(struct car),1,fp)!=0;i++)
{
if(car[i].carnum!=carnum)
{
fwrite(car[i],sizeof(struct car),1,fp2);
}
}
fclose(fp);
fclose(fp2);
printf("是否真的要删除该卡?删除后该书籍的所有信息将无法恢复《Y/N》\n");
scanf("%s",choice);
if(choice=='y'||choice=='Y')
{
fp=fopen("car.txt","w");
fp2=fopen("bookl.txt","r");
for(i=0;fread(car[i],sizeof(struct car),1,fp2)!=0;i++)
{
fwrite(car[i],sizeof(struct car),1,fp);
}
fclose(fp);
fclose(fp2);
fp2=fopen("bookl.txt","w");
fclose(fp2);
printf("按任意键返回\n");
getch();
return;
}
else
{
printf("按任意键返回\n");
getch();
return;
}
}
addcar()
{
FILE *fp;
int i=0;
fp=fopen("car.txt","a+");
printf("请你输入卡号\n");
scanf("%d",car[i].carnum);
printf("请你输入学生姓名\n");
scanf("%s",car[i].studentname);
printf("请你输入班级\n");
scanf("%d",car[i].studentclass);
fwrite(car[i],sizeof(struct car),1,fp);
fclose(fp);
printf("输入完毕,任意键返回\n");
getch();
}
急求c语言程序设计 图书管理系统 源代码
#includestdio.h
#includemath.h
#includestdlib.h
#includestring.h
#define N 100 //书籍的最多本数
struct book
{ char title[30];
int number;
char author[30];
float price;
int store;
char borrower_name[20];
char borrower_gender[5];
int borrower_number;
}s[N];
int m=0;
void input(structbook *p); //输入图书信息
void save(structbook *p); //保存图书信息
void read(structbook *p); //读取图书信息
void search(structbook *p); //查找图书信息
void del(structbook *p); //删除图书信息
void borrow(structbook *p); //借阅图书
void retur(structbook *p); //归还图书
void main()
{
int x;
do
{
printf("**************************************菜单**************************************\n"
" *********** 1.输入图书信息 ********** \n"
" *********** 2.查找图书信息 ********** \n"
" *********** 3.删除图书信息 ********** \n"
" *********** 4.借阅图书 ********** \n"
" *********** 5.归还图书 ********** \n"
" *********** 0.退出 ********** \n");
printf("********************************************************************************\n");
printf("请在0-5中选择,以回车键结束\n");
scanf("%d",x);
switch(x)
{ case 1: input(s[0]);break;
case 2: search(s[0]);break;
case 3: del(s[0]);break;
case 4: borrow(s[0]);break;
case 5: retur(s[0]);break;
case 0: break;
}
}while(x!=0);
}
void input(structbook *p)
{ int y;
for(;p(s[0]+N);p++)
{ printf("请输入书名:");scanf("%s",p-title);
printf("请输入编号:"); scanf("%d",p-number);
printf("请输入作者:"); scanf("%s",p-author);
printf("请输入图书价格:"); scanf("%f",p-price);
printf("请输入图书数量:"); scanf("%d",p-store);
m++;
printf("第%d个信息已经输入完毕,是否继续?\n按任意键继续,按0键结束.",m);
scanf("%d",y);//读取是否继续
if(y==0)
{ save(s[0]);
read(s[0]);//调用读取文件函数
break;
}
}
}
void search(structbook *p)//查询模块
{ int n;
char name1[20];
char name2[20];
char c[3];
do
{ p=s[0];
printf("\t请选择查找方式:\n");//打印查询方式菜单
printf(" 1.按书名查找\n 2.按作者查找\n 0.返回\n");
printf("请在0-2中选择:\n\n");
scanf("%d",n);//读取查找方式
if(n==0) break;
switch(n)
{ case 1: printf("请输入书名:\n");scanf("%s",name1);break;
case 2: printf("请输入作者:\n");scanf("%s",name2);break;
}
for(;ps[m];p++)
{ read(s[0]);//调用读取函数
if(strcmp(p-title,name1)==0||strcmp(p-author,name2)==0)
{ printf("\n查找图书信息成功!\n");
printf("书名 编号 作者 价格 数量\n");
printf("%-10s%-10d%-10s%-10.2f%-10d\n",p-title,p-number,p-author,p-price,p-store);//打印信息
break;
}
}
printf("是否继续查找?\n“是”请键入“yes”, “否”请按任意键,返回菜单\n");
scanf("%s",c);
}while(strcmp(c,"yes")==0);//判断是否结束
}
void del(structbook *p)//删除模块
{ int i;
struct book *p1,*p2;
char name1[20];
char name2[20];
char c[3];
int n;
do
{ p=s[0];
printf("请选择删除以方式回车键结束:\n");//打印删除方式菜单
printf( " 1.按书名删除\n 2.按作者删除\n 0.返回\n");
printf("请在0-2中选择:\n\n");
scanf("%d",n);//读取查找方//
if(n==0) break;
switch(n)
{case 1:printf("请输入书名:\n");
scanf("%s",name1);break;
case 2: printf("请输入作者:\n");
scanf("%s",name2);break;
}
read(s[0]); //调用读取函数
for(i=0;im;i++,p++)
{
if(strcmp(p-title,name1)==0||strcmp(p-author,name2)==0)
{ p1=p;
for(p2=p1+1;p2=s[m];p1++,p2++)
{
strcpy(p1-title,p2-title);
strcpy(p1-author,p2-author);
p1-number=p2-number;
p1-store=p2-store;
p1-price=p2-price;
m--;
printf("删除成功!!\n");
}
}
else {printf("没有该书记录!!");
break;}
}
printf("是否继续删除?“是”请键入“yes”, “否”请按任意键,返回菜单\n");
scanf("%s",c); //读取是否继续
save(s[0]); //调用保存函数
}while(strcmp(c,"yes")==0); //判断是否继续删除
}
void borrow(structbook *p)//借书模块
{ int z;
char name3[20],name4[20];
char w[3];
do
{ p=s[0];
printf("请先查找您要借阅的图书!");
printf("请选择查找方式:\n");//打印查询方式菜单
printf(" 1.按书名查找\n 2.按作者查找\n 0.返回\n");
printf("请在0-2中选择:\n");
scanf("%d",z);//读取查找方式
if(z==0) break;
switch(z)
{ case 1: printf("请输入书名:\n");scanf("%s",name3);break;
case 2: printf("请输入作者:\n");scanf("%s",name4);break;
}
read(s[0]);//调用读取函数
for(;ps[m];p++)
{ if(strcmp(p-title,name3)==0||strcmp(p-author,name4)==0)
{
printf("\n查找图书信息成功!\n");
printf("书名 编号 作者 价格 数量\n");
printf("%-10s%-10d%-10s%-10.2fs%-10d\n",p-title,p-number,
p-author,p-price,p-store);//打印信息
printf("请输入您的姓名:");scanf("%s",p-borrower_name);
printf("请输入您的性别:");scanf("%s",p-borrower_gender);
printf("请输入您的学号:");scanf("%d",p-borrower_number);
p-store--;
printf("借书成功!\n");
printf("书名 编号 作者 价格 数量 借书人 性别 学号\n");
printf("%-10s%-10d%-10s%-10.2f%-10d%-10s%-10s%-10d\n",p-title,p-number,p-author,
p-price,p-store,p-borrower_name,p-borrower_gender,p-borrower_number);
break;
}
}
printf("是否继续借书??");
printf("“是”请键入“yes”, “否”请按任意键,返回菜单\n");
scanf("%s",w); //读取是否继续
save(s[0]); //调用保存函数
}while(strcmp(w,"yes")==0); //判断是否继续借书
}
void retur(structbook *p)//还书模块
{ int e,f;
char name5[20];
char name6[20];
char t[3];
do
{ p=s[0];
printf("请先查找您要还的图目!");
printf("请选择查找方式:\n"); //打印查询方式菜单
printf(" 1.按书名查找\n 2.按作者查找\n 0.返回\n");
printf("请在0-2中选择:\n\n");
scanf("%d",e); //读取查找方式
if(e==0) break;
switch(e)
{ case 1: printf("请输入书名:\n");scanf("%s",name5);break;
case 2: printf("请输入作者:\n");scanf("%s",name6);break;
}
read(s[0]);//调用读取函数
for(;ps[m];p++)
{ if(strcmp(p-title,name5)==0||strcmp(p-author,name6)==0)
{ printf("\n查找图书信息成功!\n");
printf("确认还书请按“1”!");//确认是否还书
scanf("%d",f);
if(f==1)
{ strcpy(p-borrower_name,"0");
strcpy(p-borrower_gender,"0");
p-borrower_number=0;
p-store++;
printf("书名 编号 作者 价格 数量 借书人 性别 学号\n");
printf("%-10s%-10d%-10s%-10.2f%-10d%-10s%-10s%-10d\n",p-title,p-number,p-author,
p-price,p-store,p-borrower_name,p-borrower_gender,p-borrower_number);
//打印信息
}
break;
}
else {printf("没有该书记录!!");
break;}
}
printf("是否继续还书?\n");
printf("“是”请键入“yes”, “否”请按任意键,返回菜单\n");
scanf("%s",t); //读取是否继续
save(s[0]); //调用保存函数
}while(strcmp(t,"yes")==0); //判断是否继续还书
}
void save(structbook *p)//保存文件
{ FILE *fp,*fp1;
int i;
if((fp=fopen("tushu.txt","wb"))==NULL)//打开文件并判断是否出错
{ printf("创建文件失败!\n\n");//打印出错提示
getchar(); return;
}
if((fp1=fopen("book.txt","wb"))==NULL)//打开文件并判断是否出错
{ printf("创建文件失败!\n\n");//打印出错提示
getchar(); return;
}
for(i=0;im;i++,p++)
if(fwrite(p,sizeof(structbook),1,fp)==0)//向文件写入数据,并判断是否出错
printf("向文件输入数据失败!\n\n");
fprintf(fp1,"%d",m);
fclose(fp);//关闭文件
fclose(fp1);//关闭文件
}
void read(structbook *p)//从文件读取信息模块
{ FILE *fp,*fp1;
int i;
if((fp=fopen("tushu.txt","rb"))==NULL)//打开文件,并判断是否出错
{ printf("出错,请检查文件是否存在,按任意键返回住菜单");//打印出错提示
getchar();
}
if((fp1=fopen("book.txt","rb"))==NULL)//打开文件并判断是否出错
{ printf("创建文件失败!\n\n");//打印出错提示
getchar(); return;
}
fscanf(fp1,"%d",m);
fclose(fp1);//关闭文件
for(i=0;im;i++,p++)
{ fread(p,sizeof(struct book),1,fp);//从文件中读取信息
}
fclose(fp);//关闭文件
}
你把保存的文件地址自己修改一下就可以了。。希望能帮到你
图书管理系统C++ 源代码 求好心人帮帮忙
#includestdio.h
#includestring.h
#includeconio.h
#includestdlib.h
#includectype.h
#define STACK_INIT_SIZE 10
#define OK 1
#define TRUE 1
#define FALSE 0
#define ERROR 0
struct student /*定义学生类型,用于存放借出的书籍*/
{
int studentnum,phonenum;
char lendbook[10];
}student[1000];
struct book /*定义书的类型*/
{
char bookname[11];
char publisher[20];
char page;
char year[6];
char status[4];
char name[11];
char author[51];
char booknum;
char bookcreat[10];
char borrownum;
char turefalse; /*用于借书和还书模块判断一本书是否借出的条件*/
}book[1000];
struct car /*借书卡的数据类型*/
{
int carnum;
char studentname[10];
int studentclass;
int studentphone;
}car[100];
addcar()
{
FILE *fp;
int i=0;
double allnum,stillbook,outbook,allmoney,avemoney;
fp=fopen("car.txt","a+");
printf("请你输入学生姓名\n");
scanf("%s",car[i].studentname);
printf("请你输入班级\n");
scanf("%d",car[i].studentclass);
fwrite(car[i],sizeof(struct car),1,fp);
fclose(fp);
printf("注册完毕,任意键返回\n");
fp=fopen("book.txt","r");
avemoney=allmoney/allnum;
fclose(fp);
printf("书籍总数:%ld,已借出的书籍:%ld,在馆的书籍:%ld,书籍贯总金额:%ld,书籍平均价格:%ld",
stillbook,outbook,allmoney,avemoney);
getch();
}
carcount()
{
FILE *fp;
int i,n=0;
fp=fopen("car.txt","r");
for(i=0;fread(car[i],sizeof(struct car),1,fp)!=0;i++)
{
printf("第%d张卡卡号:%d 姓名:%s 班级:%d 手机号码:%d\n",
i+1,car[i].carnum,car[i].studentname,car[i].studentclass,car[i].studentphone);
n=n+1;
}
fclose(fp);
printf("目前共有%d本书\n",n);
printf("按任意键\n");
getch();
}
void findbook()
{
FILE *fp;
char bookname[10];
int ture,i,booknum;
fp=fopen("book.txt","r");
printf("请输入你要查找的booknum");
scanf("%d",booknum);
for(i=0;fread(book[i],sizeof(struct book),1,fp)!=0;i++)
{
if(strcmp(booknum,book[i].booknum)==0)
{
if(book[i].turefalse==1)
printf("这本书的详细资料是:%d %s %s 此书现在无人借阅\n按任意键返回\n",book[i].booknum,book[i].bookname,book[i].bookcreat);
else {printf("这本书已经有人借出\n");fclose(fp);return 0;}
fclose(fp);
return FALSE;
}
else
printf("没有你要查询的书籍\n");
fclose(fp);}
return FALSE;
}
void borrowbook(struct book *m) //借阅图书函数
{
int num;
struct book *b, *b1;
printf("输入要借书的编码:");
scanf("%d",num);
b = searchbook(num); /*调用查找图书结点函数*/
if(b != NULL)
{
if(m-borrownum 10)
{
// b-status = '0';
// b1 = m-book[m-borrownum];
strcpy(b1-name,b-name);
strcpy(b1-author,b-author);
b1-booknum = b-booknum;
strcpy(b1-year,b-year);
b1-page = b-page;
strcpy(b1-publisher,b-publisher);
// b1-price = b-price;
// b1-status = b-status;
m-borrownum++;
printf("%s借书成功!",b-name);
getch();
}
else
{
printf("你已借满10本书.");
getch();
}
}
else
{
printf("没有你要借的书.");
getch();
}
}
huanbook() /*还书函数*/
{
FILE *fp,*fp2; /*定义两个文件指针,fp2用于修改数据时设立临时文件用,防止数据遭破坏*/
int i,n;
int carnum,booknum;
char lendbook[10];
printf("请你输入你的卡号\n");
scanf("%d",carnum);
fp=fopen("car.txt","r"); /*读取卡号记录*/
{
if(car[i].carnum==carnum) /*卡号存在,进入下一循环*/
{
n=i;
fclose(fp);
printf("请输入你要还的书的booknum\n");
scanf("%d",booknum);
fp=fopen("record.txt","r");
for(i=0;fread(student[i],sizeof(struct student),1,fp)!=0;i++) /*判断是否借阅了输入的书*/
{
if(strcmp(student[i].lendbook,lendbook)==0) /*借阅了该书,进入下一循环,否则出错显示*/
{
fclose(fp);
fp=fopen("record.txt","r");
fp2=fopen("bookl.txt","w");
for(i=0;fread(student[i],sizeof(struct student),1,fp)!=0;i++)
{
if(strcmp(student[i].lendbook,lendbook)==0)
{
continue; /*删除还掉的书的借书记录*/
}
fwrite(student[i],sizeof(struct student),1,fp2); /*写入原来没还的书的记录*/
}
fclose(fp);
fclose(fp2);
fp=fopen("record.txt","w");
fp2=fopen("bookl.txt","r");
for(i=0;fread(student[i],sizeof(struct student),1,fp2)!=0;i++)
{
fwrite(student[i],sizeof(struct student),1,fp); /*将借书记录信息写回*/
}
fclose(fp);
fclose(fp2);
fopen("bookl.txt","w"); /*清临时文件的记录*/
fclose(fp2);
fp=fopen("book.txt","r");
fp2=fopen("bookl.txt","w");
for(i=0;fread(book[i],sizeof(struct book),1,fp)!=0;i++) /*将书的记录写入临时文件,防止因为修改信息破坏以前的记录*/
{
if(i==n)
{
book[i].turefalse=1;
fwrite(book[i],sizeof(struct book),1,fp2); /*将还的书的原来状态设为无人借阅的*/
continue;
}
fwrite(book[i],sizeof(struct book),1,fp2);
}
fclose(fp);
fclose(fp2);
fp=fopen("book.txt","w");
fp2=fopen("bookl.txt","r");
for(i=0;fread(book[i],sizeof(struct book),1,fp2)!=0;i++)
{
fwrite(book[i],sizeof(struct book),1,fp); /*将临时文件写回*/
}
fclose(fp);
fclose(fp2);
fopen("bookl.txt","w"); /*清临时文件*/
fclose(fp2);
printf("还书完毕,按任意键返回\n");
getch();
return 1;
}
else
printf("你没有借这样的书,任意键返回\n");}/*出错提示*/
fclose(fp);
getch();
return 0;
}
else
printf("系统没这样的卡,和管理员联系,按任意键返回\n");}/*出错提示*/
fclose(fp);
getch();
}
void main()
{
struct book *m;
char ch5;
do
{
printf("---------------欢迎进入图书查询系统!--------------\n");
printf(" 1:注册卡号\n");
printf(" 2: 卡号信息\n");
printf(" 3:按书籍编号查找\n");
printf(" 4: 借书\n");
printf(" 5: 还书\n");
printf(" 0:返回\n");
printf("请输入0--5,其他输入非法!\n");
scanf("%s",ch5);
switch(ch5)
{
case '1':addcar();getch();
case '2':carcount();getch();break;
case '3':findbook();getch();break;
case '4':borrowbook(m );getch();break;
case '5':huanbook();getch();break;
case '0':break;
default:printf("无此操作\n");getch();break;
}
}while(ch5!='0');
//return FALSE;
}