工具设计图书管理系统源码_设计图书管理系统的管理模块

hacker|
77

文章目录:

c语言 图书管理系统 源代码

#include

#include

#include

#include

#include

struct book{

char number[100];

char tittle[100];

char writer[100];

char publisher[100];

char date[100];

char price[100];

char status[100];

char reader[100];

};

void search_book();

void borrow_book();

void return_book();

void add_book();

void delete_book();

void modify_book();

void scan_book();

int main()

{

int c1=0,c2,c3;

int l,x,z;

while(1)

{

system("color 2C");

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("color 2C");

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)

{

case 1:search_book(); break;

case 2:borrow_book(); break;

case 3:return_book(); break;

case 4:scan_book(); break;

case 5:system("cls"); return 0;

}

}

}

if(c1==2)

{

while(1){

system("color 2C");

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)

{

case 1:add_book(); break;

case 2:delete_book(); break;

case 3:modify_book(); break;

case 4:scan_book(); break;

case 5:system("cls"); return 0;

}

}

}

}

/*查询图书*/

void search_book()

{

FILE*fp;

struct book n;

struct book nn;

int l,r;

char x,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");

}

//添加

void add_book()

{

FILE *fp;

struct book n;

struct book nn;

char x,z;

int l,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");

}

//删除图书

void delete_book()

{

FILE *fp,*fp1;

char x,z;

struct book n;

struct book nn;

int l,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");

}

//修改图书信息

void modify_book()

{

FILE *fp;

struct book n;

struct book nn;

int l,r;

char x,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");

}

//借书

void borrow_book()

{

FILE*fp;

struct book n;

struct book nn;

char x,z;

int l,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");

}

//书

void return_book()

{

FILE*fp;

struct book n;

struct book nn;

char x,z;

int l,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");

}

//浏览

void scan_book()

{

FILE*fp;

char x,z;

struct book n;

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");

}

}

急求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语言编写的图书管理系统源代码

#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);//关闭文件

}

你把保存的文件地址自己修改一下就可以了。。希望能帮到你

2条大神的评论

  • avatar
    访客 2022-07-10 下午 04:53:52

    ; printf(" 5:职工管理系统\n"); printf(" 6:学生管理系统\n"); printf(" 0:返回\n");

  • avatar
    访客 2022-07-10 下午 06:06:49

    修改图书资料\n"); printf(" 4:书籍统计\n"); printf(" 5:职工管理系统\n"); printf(" 6:学生管理系统\n"); printf(" 0:返回\n"); print

发表评论