1.C语言 有关于书信息管理系统代码
2.急求C语言编写的图书图书管理系统源代码,具体要求如下
C语言 有关于书信息管理系统代码
#include<stdio.h>
#include <string.h>
#include <stdlib.h>
#include<conio.h>
#define Max 2
typedef struct book //书的管理信息
{
char book_num[];//书号
char book_name[];//书名
char book_writer[];//作者
int book_xy;//书的剩余数量
int book_kc;//书的总数量
struct book *next;
}BK;
typedef struct borrow //被借书的信息
{
char borrow_book_num[];//借书书号
char limit_date[8];//借书归还日期
}BO;
typedef struct reader //读者信息
{
char reader_num[];//读者号
char reader_name[];//读者姓名
int right;//已借数量
BO borrow[Max];//已借书信息
struct reader *next;
}RD;
BK *h_book;
RD *h_reader;
void Login();
int Menu();
void Init();
void Init_book();
void Menu_select();
void Insert_New_Book();
void Find_Book();
void add_reader();
void Print_reader();
void Print_book();
void Borrow_Book();
void Return_Book();
void Save();
void Save_Book();
void Save_Reader();
void Load();
void Load_Reader();
void Load_Book();
void Login()
{
system("cls");
printf("\n\n\n\t\t\t欢迎使用图书管理系统\n");
printf("\n\n\t\t本程序分析者 秦义 学号:\n\n\n\n\n\n\n");//以前是设计者 xxxx
printf("\n\n\n\t\t 按 任 意 键 进 入 系 统 ...");
getch(); system("cls");
}
int Menu() /*主菜单*/
{ int dm;
printf("\n\t\t图书管理系统主菜单\n");
printf("=================================================\n");
printf("☆\t0----退出系统 ☆\n");
printf("☆\t1----采编入库 ☆\n");
printf("☆\t2----登记读者 ☆\n");
printf("☆\t3----借阅登记 ☆\n");
printf("☆\t4---还书管理 ☆\n");
printf("☆\t5---查询图书信息 ☆\n");
printf("☆\t6----查询读者信息 ☆\n");
printf("=================================================\n");
printf("请选择相应的代码:");
for(;;)
{ scanf("%d",&dm);
if(dm<0||dm>6)
printf("\n错误!请重新输入:");
else break;
}
return dm;
}
void Menu_select()/*主菜单选择函数*/
{
for(;;)
{
switch(Menu()) /*功能选择*/
{ case 0:
system("cls");
Save();
printf("\n\n\t文件保存成功!\n");
printf("\n\n\t欢迎下次使用本系统!\n");
getch();
exit(0);
case 1:Insert_New_Book();break;
case 2:add_reader();break;
case 3:Borrow_Book();break;
case 4:Return_Book();break;
case 5:Print_book();break;
case 6:Print_reader();break;
default:printf("\n错误!");
exit(0);}
}
}
void Init() /*初始化*/
{
Init_book();
}
void Init_book() /*初始化图书信息*/
{
BK *p0;
printf("\n图书初始化开始,请输入图书信息..\n包括编号.书名.数量..\n");
p0=(BK*)malloc(sizeof(BK));
h_book=p0;
printf("\n请输入图书信息:\n");
printf("图书编号:"); /*输入图书编号(唯一)*/
scanf("%s",p0->book_num);
printf("图书名称:"); /*输入图书名称*/
scanf("%s",p0->book_name);
printf("图书作者:"); /*输入图书作者*/
scanf("%s",p0->book_writer);
printf("图书数量:"); /*输入图书数量*/
scanf("%d",&p0->book_kc);
p0->book_xy=p0->book_kc; /*开始时图书现有量和库存量相等*/
p0->next=NULL;
printf("\n图书信息初始化完毕!按任意键继续下一步操作..\n");
getch();
system("cls");
}
void Insert_New_Book()/*新书入库*/
{
BK *p,*p0,*p1;
p=p1=h_book;
printf("\n新书入库模块...\n");
printf("\n请输入新书信息..\n包括书号.书名.数量..\n");
p0=(BK *)malloc(sizeof(BK));
printf("图书编号:");
scanf("%s",p0->book_num);
while(strcmp(p0->book_num,p1->book_num)!=0&&p1->next!=NULL)
p1=p1->next;
if(strcmp(p0->book_num,p1->book_num)==0) /*此处分两种情况,若图书编号存在,则直接进库,只须输入书的数量*/
{
printf("\n此编号图书已存在!!直接入库!\n");
printf("图书数量:");
scanf("%d",&p0->book_kc);
p1->book_kc+=p0->book_kc;
p1->book_xy+=p0->book_kc;
}
else/*若不存在,则需要输入其他的信息 ,然后在进行插入操作*/
{
printf("图书名称:");
scanf("%s",p0->book_name);
printf("图书作者:");
scanf("%s",p0->book_writer);
printf("图书数量:");
scanf("%d",&p0->book_kc);
while(p->next)
{ p=p->next; }
if(h_book==NULL) h_book=p0; /*此处分两种情况,链表中没有数据,head直接指向p0处*/
else p->next=p0; /*此处分两种情况,链表中有数据,链表中最后元素的next指向p0处*/
p0->next=NULL;
p0->book_xy=p0->book_kc;
}
printf("\n新书入库完毕!按任意键继续下一步操作..\n");
getch();
system("cls");
}
void add_reader()/*添加读者*/
{ RD *p0;
int i;
printf("\n读者初始化开始,请输入读者信息..\n包括书证号.姓名..\n");
p0=(RD*)malloc(sizeof(RD)); /*申请新结点存储空间*/
h_reader=p0;
printf("\n请输入读者的信息:\n");
printf("读者书证号:");
scanf("%s",p0->reader_num);
printf("读者姓名:");
scanf("%s",p0->reader_name);
p0->right=0;
for(i=0;i<Max;i++)
{
strcpy(p0->borrow[i].borrow_book_num,"0"); /*所借图书直接置为0(即没有借书)*/
strcpy(p0->borrow[i].limit_date,"0");
}
p0->next=NULL;
printf("\n读者信息初始化完毕!按任意键继续下一步操作..\n");
getch();
system("cls");
}
void Borrow_Book() /*借书模块*/
{
BK *p0; RD *p1;
char bo_num[],rea_num[],lim_date[8];
int i;
p0=h_book; p1=h_reader;
printf("\n借书模块...\n");
printf("\n请输入借书的读者书证号:");
scanf("%s",rea_num);
while(p1->next!=NULL&&strcmp(rea_num,p1->reader_num)!=0) //查找读者号
{ p1=p1->next;}
if(p1->next==NULL&&strcmp(rea_num,p1->reader_num)!=0)
{
printf("\n此读者编号不存在!按任意键返回..\n");
goto END;
}
printf("\n请输入你要借的书的编号:");
scanf("%s",bo_num);
while(strcmp(bo_num,p0->book_num)!=0&&p0->next!=NULL) //查找书号
{ p0=p0->next;}
if(p0->next==NULL&&strcmp(bo_num,p0->book_num)!=0)
{
printf("\n此图书编号不存在!按任意键返回..\n");
}
else if(p0->book_xy<=0)
{
printf("\n抱歉,此书已借完!请等待新书的到来!!\n按任意键返回....");
}
else if(p1->right>=Max)
{
printf("\n不好意思,借书数目已满!不能借书!\n按任意键返回....");
}
else if(strcmp(p1->borrow[0].borrow_book_num,"0")!=0)
{
for(i=0;i<Max;i++)
{
if(strcmp(p1->borrow[i].borrow_book_num,bo_num)==0)
{
printf("\n抱歉!同一个读者不能同借两本相同的书!\n");
}
else if(strcmp(p1->borrow[i].borrow_book_num,"0")==0)
{
printf("\n请输入你要归还图书的日期:");
scanf("%s",lim_date);
strcpy(p1->borrow[p1->right++].borrow_book_num,bo_num);
strcpy(p1->borrow[p1->right-1].limit_date,lim_date);
p0->book_xy--;
printf("\n读者编号%s借书完毕!按任意键继续下步操作..",p1->reader_num);
}
}
}
else
{
printf("\n请输入你要归还图书的日期:");
scanf("%s",lim_date);
strcpy(p1->borrow[p1->right++].borrow_book_num,bo_num);
strcpy(p1->borrow[p1->right-1].limit_date ,lim_date );
p0->book_xy--;
printf("\n读者编号%s借书完毕!按任意键继续下步操作..",p1->reader_num);
}
END:getch(); system("cls");
}
void Return_Book() /*还书模块*/
{
BK *p; RD *q;
int i,j,find=0;
char return_book_num[],return_reader_num[];
p=h_book; q=h_reader;
printf("\n还书模块...\n");
printf("\n请输入要还书的读者编号:");
scanf("%s",return_reader_num);
while(q->next!=NULL&&strcmp(return_reader_num,q->reader_num)!=0)
q=q->next;
if(q->next==NULL&&strcmp(return_reader_num,q->reader_num)!=0)
{
find=2;
printf("\n此读者编号不存在!按任意键返回..\n");
goto end;
}
printf("\n请输入读者还书的编号:");
scanf("%s",return_book_num);
while(p->next!=NULL&&strcmp(return_book_num,p->book_num)!=0)
p=p->next;
if(p->next==NULL&&strcmp(return_book_num,p->book_num)!=0)
{
find=2;
printf("\n错误!此图书编号不存在!按任意键返回..\n");
goto end;
}
for(i=0;i<Max;i++)
if(strcmp(return_book_num,q->borrow[i].borrow_book_num)==0) /*如果此读者借了此书*/
{
find=1;
for(j=i;j<Max-1;j++)
{
strcpy(q->borrow[j].borrow_book_num,q->borrow[j+1].borrow_book_num);
strcpy(q->borrow[j].limit_date,q->borrow[j+1].limit_date);
}
strcpy(q->borrow[Max-1].borrow_book_num,"0");
strcpy(q->borrow[Max-1].limit_date,"0");
p->book_xy++;
q->right--;
printf("\n编号%s的读者还书完毕!按任意键继续下步操作..",return_reader_num);
}
if(find==0)
printf("\n错误!此读者未借此书!按任意键返回..\n");
end: getch(); system("cls");
}
void Print_book() /*查询图书信息*/
{
BK *p;
p=h_book;
printf("\n图书信息如下:\n\n");
printf("图书编号\t图书名称\t图书作者\t现有\t\t库存\n");
while(p!=NULL)
{
printf("%s\t\t%s\t\t%s\t\t%d\t\t%d\n",p->book_num,p->book_name,p->book_writer,p->book_xy,p->book_kc);
p=p->next;
}
printf("\n图书信息打印完毕!按任意键继续下一步操作..");
getch();
system("cls");
}
void Print_reader() /*查询读者信息*/
{
RD *p;
int i;
p=h_reader;
printf("\n读者信息如下:\n\n");
printf("读者书证号\t\t读者姓名\n");
printf("\n");
while(p!=NULL)
{
printf("\t%s\t\t%s",p->reader_num,p->reader_name);
for(i=0;i<Max;i++)
{
printf("\n");
printf("图书编号",i+1);
printf("\t还书日期",i+1);
printf("\n");
printf("\t%s",p->borrow[i].borrow_book_num);
printf("\t\t%s",p->borrow[i].limit_date);
}
printf("\n");
p=p->next;
}
printf("\n读者信息打印完毕!按任意键继续下一步操作..");
getch();
system("cls");
}
//文件模块
void Save() /*保存信息*/
{
Save_Reader();
Save_Book();
}
void Save_Reader() /*保存读者信息*/
{
FILE *fp_reader;
RD *p,*p0;
p=h_reader;
if((fp_reader=fopen("Reader.txt","wb"))==NULL) /*创建文件,进行保存*/
{
printf("\n文件保存失败!\n请重新启动本系统...\n");
exit(0);
}
while(p!=NULL)
{
if(fwrite(p,sizeof(RD),1,fp_reader)!=1) /*将链表中的信息写入文件中*/
printf("\n写入文件失败!\n请重新启动本系统!\n");
p0=p;
p=p->next;
free(p0); /*释放所有结点*/
}
h_reader=NULL;
fclose(fp_reader); /*关闭文件*/
}
void Save_Book() /*保存图书信息*/
{
FILE *fp_book; /*创建文件型指针*/
BK *p,*p0;
p=h_book;
if((fp_book=fopen("Book.txt","wb"))==NULL) /*创建文件,进行保存*/
{
printf("\n文件保存失败!\n请重新启动本系统...\n");
exit(0);
}
while(p!=NULL)
{
if(fwrite(p,sizeof(BK),1,fp_book)!=1) /*将链表中的信息写入文件中*/
printf("\n写入文件失败!\n请重新启动本系统!\n");
p0=p;
p=p->next;
free(p0);
}
h_book=NULL;
fclose(fp_book); /*关闭文件*/
}
void Load() /*加载信息*/
{
Load_Reader();
Load_Book();
}
void Load_Reader() /*加载读者信息*/
{
RD *p1,*p2,*p3;
FILE *fp; /*创建文件型指针*/
fp=fopen("book.txt","rb"); /*打开文件*/
p1=(RD *)malloc(sizeof(RD));
fread(p1,sizeof(RD),1,fp);
h_reader=p3=p2=p1;
while(! feof(fp)) /*读出信息,重新链入链表*/
{ p1=(RD *)malloc(sizeof(RD));
fread(p1,sizeof(RD),1,fp);
p2->next=p1;
p3=p2;
p2=p1;
}
p3->next=NULL;
free(p1);
fclose(fp); /*关闭文件*/
}
void Load_Book() /*加载图书信息*/
{
BK *p1,*p2,*p3;
FILE *fp; /*创建文件型指针*/
fp=fopen("Book.txt","rb"); /*打开文件*/
p1=(BK *)malloc(sizeof(BK));
fread(p1,sizeof(BK),1,fp);
h_book=p3=p2=p1;
while(! feof(fp)) /*读出信息,重新链入链表*/
{ p1=(BK *)malloc(sizeof(BK));
fread(p1,sizeof(BK),1,fp);
p2->next=p1;
p3=p2;
p2=p1;
}
p3->next=NULL;
free(p1);
fclose(fp); /*关闭文件*/
}
void main()
{
FILE *fp_book,*fp_reader; /*创建文件型指针*/
Login();
if((fp_book=fopen("Book.txt","rb"))==NULL||(fp_reader=fopen("Reader.txt","rb"))==NULL)
{ Init(); }
else Load();
Menu_select(); /*调用主菜单*/
}
急求C语言编写的图书管理系统源代码,具体要求如下
/*这有个以前用过的系统程序,你可以自己改改使用,源码免单 源码但是图书有些功
能好像有问题,会中断运行。管理至于程序的系统缩进式格式就你自己
敲回车和退格解决吧,不然代码看起来会很乱不好看。源码*/
#include<stdio.h>
#include<string.h>
#include<conio.h>
#include<stdlib.h>
#include<ctype.h>
#define STACK_INIT_SIZE
#define OK 1
#define TRUE 1
#define FALSE 0
#define ERROR 0
struct student /*定义学生类型,图书用于存放借出的管理书籍*/
{
int carnum;
char lendbook[];
}student[];
struct employ /*定义职工类型*/
{
int employnum;
char employname[];
int employage;
char employsex[2];
char employleve[];
long int employtage;
}employ[];
struct book /*定义书的类型*/
{
int booknum;
char bookname[];
char bookcreat[];
int turefalse; /*用于借书和还书模块判断一本书是否借出的条件*/
}book[];
struct car /*借书卡的数据类型*/
{
int carnum;
char studentname[];
int studentclass;
}car[];
huanbook() /*还书函数*/
{
FILE *fp,*fp2; /*定义两个文件指针,fp2用于修改数据时设立临时文件用,系统溯源码如何生成防止数据遭破坏*/
int i,源码n;
int carnum;
char lendbook[];
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++) /*将书的记录写入临时文件,防止因为修改信息破坏以前的appios远控源码记录*/
{
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[];
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[];
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[],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[],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!=0&&strlen(book[i].bookname)!=0&&strlen(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[],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[],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');
}