您的位置首页生活快答

图书管理系统C++ 源代码 求好心人帮帮忙

图书管理系统C++ 源代码 求好心人帮帮忙

的有关信息介绍如下:

图书管理系统C++  源代码 求好心人帮帮忙

这种东西好多C++学习站都有下载!全是源码!

易语言也有!

你可以去找找!很多的!

#include

#include

#include

#include

#include

#define STACK_INIT_SIZE 10

#define OK 1

#define TRUE 1

#define FALSE 0

#define ERROR 0

struct student /*定义学生类型,用于存放借出的书籍*/

{

int studentnum,phonenum;

char lendbook;

}student;

struct book /*定义书的类型*/

{

char bookname;

char publisher;

char page;

char year;

char status;

char name;

char author;

char booknum;

char bookcreat;

char borrownum;

char turefalse; /*用于借书和还书模块判断一本书是否借出的条件*/

}book;

struct car /*借书卡的数据类型*/

{

int carnum;

char studentname;

int studentclass;

int studentphone;

}car;

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;

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

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;

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;

}