图书管理系统的制作(共11页).doc
精选优质文档-倾情为你奉上#include <stdio.h>#include <stdlib.h>#include <string.h>typedef structchar id10;char name15;char daihao10;char zz10; int sj;float dj;int kc; int jc;int zs;BOOK;BOOK s10;BOOK all10; BOOK d10; int length=0; int k=0; char fname10; int menu(); int input(); int display();int delete1(); int deletef(int local);int search(); int modify(); int modifyf(int i); int home();int showsingle(int);int add();int recovery();int count();int save();int open();int main() int i;home();while (1)system("cls");i=menu();if (i=0) printf("n请按任意键退出n");return 1;if (i=1) input();system("cls"); if (i=2) display();system("cls");if (i=3) modify();system("cls");if (i=4) search();system("cls"); if (i=5) delete1(); system("cls"); if (i=6) recovery();system("cls");if (i=7) add();system("cls"); if (i=8) count();system("cls"); if (i=9) save();system("cls");if (i=10)open();system("cls");return 1;int home() system("cls");printf(" nnnnnnn");printf(" * n"); printf(" * 中南大学图书管理系统 * n"); printf(" * * n ");printf(" * * n");printf(" * 信息科学与工程学院 * n");printf(" * * n ");printf(" * * n ");printf(" * 电气1029班 张鑫 * n");printf(" * * n ");printf(" * n"); printf(" 请按 Enter 键进入 n");printf(" n ");while (getchar()!='n');return 1;int menu() int flag=0;printf(" 中南大学图书管理系统 n");printf(" n");printf(" 1 输入记录 2 显示记录 n"); printf(" n");printf(" 3 修改记录 4 查找记录 n"); printf(" n");printf(" 5 删除记录 6 恢复记录 n");printf(" n");printf(" 7 添加记录 8 统计 n");printf(" n");printf(" 9 保存数据文件 10 打开数据文件 n");printf(" n"); printf(" 0 退出 n"); printf(" n");printf(" 请选择相应的数字: n");printf(" :");scanf("%d",&flag); return flag;int input() int num,i;printf("n请输入你想创建的记录个数:"); scanf("%d",&num);printf("n");for (i=0;i<num;i+)printf("ID号:");scanf("%s",&slength.id);printf("代号:");scanf("%s",&slength.daihao);printf("书名:");scanf("%s",&slength.name); printf("作者:");scanf("%s",&slength.zz);printf("时间:");scanf("%d",&slength.sj);printf("单价:");scanf("%f",&slength.dj);printf("库存:");scanf("%d",&slength.kc);printf("借出:");scanf("%d",&slength.jc); +length; system("pause"); return 1; int showsingle(int i)printf(" ID号 代号 书名 作者 时间 单价 库存 借出 总数 n");si.zs=si.kc+si.jc;printf("%4s %6s %8s %9s %10d %9.1f %9d %10d %4d n",si.id,si.daihao, si.name,si.zz,si.sj,si.dj,si.kc,si.jc,si.zs); return 1;int display() int i; printf("n ID号 代号 书名 作者 时间 单价 库存 借出 总数n");for(i=0;i<length;i+) si.zs=si.kc+si.jc;printf("%4s %6s %8s %9s %10d %9.1f %9d %10d %d n",si.id,si.daihao,si.name,si.zz,si.sj,si.dj,si.kc,si.jc,si.zs);system ("pause");return 1;int modify() char name30;int i,n;printf("输入要修改书名:");scanf("%s",name);printf("n");for(i=0;i<length;i+)if(strcmp(si.name,name)=0) n=modifyf(i); printf("n");if (n!=1) printf("对不起,该书不存在nn");system("pause");return 1;int modifyf(int i) showsingle(i);printf("n请输入修改后的数据:nn"); printf("代号:");scanf("%s",&si.daihao);printf("书名:");scanf("%s",&si.name);printf("作者:");scanf("%s",&si.zz);printf("时间:");scanf("%d",&si.sj);printf("单价:");scanf("%f",&si.dj);printf("库存");scanf("%d",&si.kc); printf("借出:");scanf("%d",&si.jc); printf("n"); printf("修改结果如下:nn"); showsingle(i);return 1; int search() char name30;int i,n;printf("请输入要查询的书的名字:");scanf("%s",name);printf("n");for(i=0;i<length;i+)if(strcmp(si.name,name)=0) n=showsingle(i);printf("n");if (n!=1) printf("对不起,该书不存在nn");system ("pause");return 1;int delete1() char name30;int i,n;printf("请输入要删除的书的名字:");scanf("%s",name);for(i=0;i<length;i+)if(strcmp(si.name,name)=0) n=deletef(i); printf("n");if (n!=1) printf("对不起,该书不存在nn");system("pause");return 1;int deletef(int local) int i; dk=slocal; k+;for(i=local;i<length;i+) strcpy(si.id,si+1.id);strcpy(si.daihao,si+1.daihao);strcpy(si.name,si+1.name); strcpy(si.zz,si+1.zz);si.sj=si+1.sj;si.dj=si+1.dj;si.kc=si+1.kc;si.jc=si+1.jc;length-; printf("n删除成功n");printf("n删除结果如下:n");display();return 1;int add () printf("ID号:");scanf("%s",&slength.id);printf("书名:");scanf("%s",&slength.name); printf("作者:");scanf("%s",&slength.zz);printf("时间:");scanf("%d",&slength.sj);printf("单价:");scanf("%f",&slength.dj);printf("库存:");scanf("%d",&slength.kc);printf("借出");scanf("%d",&slength.jc);printf("n");+length; printf("n添加后结果如下:n");display(); return 1; int save()FILE *fout;printf("n请为您保存的文件命名:");scanf("%s",fname);fout=fopen(fname,"wb"); fwrite(s,sizeof(BOOK),length,fout);fclose(fout);printf("n保存成功nn");system("pause");return 1;int open()FILE *fout;char fname210;int i,n,j;printf("n请输入您想打开的文件名:"); scanf("%s",fname2);if (fout=fopen(fname2,"rb")!=NULL)if (length=0) for (j=0;j<10;j+)fread(&allj,sizeof(BOOK),1,fout);if (allj.dj!=0) length+;fclose(fout); n=1;elsefread(all,sizeof(BOOK),length,fout); fclose(fout);n=1;elseprintf("n您输入的文件名不存在nn");system("pause");if (n=1)for (i=0;i<10;i+) si=alli;display(); return 1;int count ()int i;float sum1=0;int sum2=0,sum3=0,sum4=0;for(i=0;i<length;i+)sum1+=si.dj;sum2+=si.kc;sum3+=si.jc;sum4+=si.zs;printf("n");printf("总金额为%.1f",sum1);printf("总库存为%dnn",sum2);printf("总借出书数量为%d",sum3);printf("总数量为%dnn",sum4);system("pause");return 1;int recovery()char name30;int i,n;printf("n请输入要恢复的书的名字:");scanf("%s",name);for(i=0;i<k;i+)if(strcmp(di.name,name)=0) slength=di;length+;n=1;printf("n恢复成功n"); printf("n恢复后结果如下:n");display();printf("n");if (n!=1) printf("对不起,该书本不存在nn");system("pause");return 1;专心-专注-专业