当前位置:文档之家› 图书管理系统(含源代码)c语言_数据结构课程设计报告

图书管理系统(含源代码)c语言_数据结构课程设计报告

数据结构大作业图书管理系统工程管理121279044 伍目录一、题目要求 (2)二、总体设计 (2)三、编码实现 (3)1) 定义图书结构体 (3)2) 登记操作 (3)3) 查看操作 (6)4) 删除操作 (7)5) Main函数 (13)四、调试与测试 (16)五、五心得体会 (18)六、用户手册 (18)一、题目要求1)目的要求本课程设计任务的目的是要求学生按照分析、设计、编码、调试和测试的软件开发过程独立完成管理系统设计,以及C语言算法的掌握,并能最终实现本系统的功能要求,通过这个程序可以学习到以前调试短程序没有的的经验。

2)题目要求实现图书管理信息系统的设计。

要现图书添加、显示全部图书、查询、借阅和归还。

主要考查利用文件的操作!二、总体设计三、编码实现1)定义图书结构体struct book{char bookname[20]; //书名int NO; //书编号char type[20]; //类型int date; //到书日期};struct person{char name[10]; //char classes[20]; //班级int number; //学号char telephone[12]; //联系int NO; //书编号char bookname[20]; //书名int borrowdate; //借书日期int returndate; //还书日期2)登记操作void new_book() //登记新书{FILE *fp;struct book b;int i,j;if((fp=fopen("shuku.txt","a"))==NULL){printf("File open error!\n");exit(0);}printf("请朱老师输入此次收到的书本总数:");scanf("%d",&i);for(j=0;j<i;j++){printf("请朱老师输入书名:");scanf("%s",b.bookname);fprintf(fp,"%s",b.bookname);printf("请朱老师输入书编号:");scanf("%d",&b.NO);fprintf(fp," %d",b.NO);printf("请朱老师输入类型:");scanf("%s",b.type);fprintf(fp," %s",b.type);printf("请朱老师输入到书日期:");scanf("%d",&b.date);fprintf(fp," %d",b.date);}if(fclose(fp)){printf("Can not close the file!\n");exit(0);}}void new_person() //登记借书{FILE *fp;struct person p;char choice;if((fp=fopen("jieshujilu.txt","a"))==NULL){printf("File open error!\n");exit(0);}printf("请朱老师输入借书人:");scanf("%s",);fprintf(fp,"%s",);printf("请朱老师输入借书人班级:");scanf("%s",p.classes);fprintf(fp," %s",p.classes);printf("请朱老师输入借书人学号:");scanf("%d",&p.number);fprintf(fp," %d",p.number);printf("请朱老师输入借书人联系:");scanf("%s",p.telephone);fprintf(fp," %s",p.telephone);printf("请朱老师输入书编号:");scanf("%d",&p.NO);fprintf(fp," %d",p.NO);printf("请朱老师输入书名:");scanf("%s",p.bookname);fprintf(fp," %s",p.bookname);printf("请朱老师输入借书日期:");scanf("%d",&p.borrowdate);fprintf(fp," %d",p.borrowdate);printf("请朱老师输入还书日期:");scanf("%d",&p.returndate);fprintf(fp," %d",p.returndate);printf("\n\t您想继续吗?(y/n)");scanf(" %c",&choice);if(choice=='Y'||choice=='y'){system("cls");new_person();}if(fclose(fp)){printf("Can not close the file!\n");exit(0);}}实现程序对文件的读取void Read(){int i=0;int j=0;ifstream in("Libra.txt",ios::out);in>>i;all=i;if(i>0&&i<=Max){for(j=1;j<=i;j++){in>>data[j].id>>data[j].name>>data[j].type>>data[j].status>>data[j].count;}}in.close();}3)查看操作v void see_book() //查看书库记录{FILE *fp;long NO;char bookname[20];char type[20];long date;if((fp=fopen("shuku.txt","r"))==NULL){printf("File open error!\n");exit(0);}while(!feof(fp)){fscanf(fp,"%s%ld%s%ld",bookname,&NO,type,&date);printf("%-10s %-10ld %-10s %ld\n",bookname,NO,type,date);};if(fclose(fp)){printf("Can not close the file!\n");exit(0);}}void see_person() //查看所有借书记录{FILE *fp;char name[10];char classes[20];int number;char telephone[20];int NO;char bookname[20];int borrowdate;int returndate;if((fp=fopen("jieshujilu.txt","r"))==NULL){printf("File open error!\n");exit(0);}while(!feof(fp)){fscanf(fp,"%s %s %ld %s %ld %s %ld %ld",name,classes,&number,telephone,&NO,bookn ame,&borrowdate,&returndate);printf("%-5s %-5s %ld %-5s %ld %-5s %ld %ld\n",name,classes,number,telephone,NO,b ookname,borrowdate,returndate);};if(fclose(fp)){printf("Can not close the file!\n");exit(0);}}4)删除操作void delete_books() //删除旧书{FILE *fp;struct book b;int number;void deletebooks();printf("请输入您要删除的书编号:");scanf("%d",&number);if((fp=fopen("shuku.txt","r"))==NULL){printf("不能打开此文件!\n");exit(0);}while(!feof(fp)){fscanf(fp,"%s %d %s %d",b.bookname,&b.NO,b.type,&b.date);if(b.NO==number){printf("\n\n\t***************图书信息*******************\n");printf("\n\t图书书名:%25s",b.bookname);printf("\n\t-----------------------------------------");printf("\n\t图书编号:%25d",b.NO);printf("\n\t-----------------------------------------");printf("\n\t图书类型:%23s",b.type);printf("\n\t-----------------------------------------");printf("\n\t到书日期:%25d",b.date);printf("\n\t-----------------------------------------");deletebooks();}}}void deletebooks(){FILE *fp,*fp1,*fp2,*fp3;int number;struct book b;printf("\n\n确认删除?请再次输入书编号:");scanf("%d",&number);if((fp=fopen("shuku.txt","r"))==NULL){printf("不能打开此文件!\n");exit(0);}if((fp1=fopen("tempshuku.txt","w"))==NULL){ //建立一个临时文件printf("不能打开此文件!\n");exit(0);}while(!feof(fp)){fscanf(fp,"%s %d %s %d",b.bookname,&b.NO,b.type,&b.date);if(b.NO==number)continue;elsefprintf(fp1,"%s %d %s %d",b.bookname,b.NO,b.type,b.date);}fclose(fp);fclose(fp1);if((fp2=fopen("tempshuku.txt","r"))==NULL){printf("不能打开此文件!\n");exit(0);}if((fp3=fopen("shuku.txt","w"))==NULL){ //清空书库printf("不能打开此文件!\n");exit(0);}while(!feof(fp2)){ //将临时文件的容写人源文件fscanf(fp2,"%s %d %s %d",b.bookname,&b.NO,b.type,&b.date);fprintf(fp3,"%s %d %s %d",b.bookname,b.NO,b.type,b.date);}fclose(fp2);fclose(fp3);printf("\n 删除成功!\n");}void delete_returnbook() //删除借书记录{FILE *fp;int numbers;struct person p;void deletereturnbook();char choice;printf("\n请输入所还书本的书编号:");scanf("%d",&numbers);if((fp=fopen("jieshujilu.txt","r"))==NULL){printf("不能打开此文件!\n");exit(0);}while(!feof(fp)){fscanf(fp,"%s %s %ld %s %ld %s %ld %ld",,p.classes,&p.number,p.telephone,&p.NO,p. bookname,&p.borrowdate,&p.returndate);if(p.NO==numbers){printf("\n\t***************图书信息*******************\n");printf("\n\t借书人:%20s",);printf("\n\t-----------------------------------------");printf("\n\t借书人班级:%20s",p.classes);printf("\n\t-----------------------------------------");printf("\n\t借书人学号:%20d",p.number);printf("\n\t-----------------------------------------");printf("\n\t借书人联系:%20s",p.telephone);printf("\n\t-----------------------------------------");printf("\n\t图书编号:%24d",p.NO);printf("\n\t-----------------------------------------");printf("\n\t图书名称:%23s",p.bookname);printf("\n\t-----------------------------------------");printf("\n\t借书日期:%25d",p.borrowdate);printf("\n\t-----------------------------------------");printf("\n\t还书日期:%25d",p.returndate);printf("\n\t-----------------------------------------");deletereturnbook();printf("\n\t您想继续吗?(y/n)");scanf(" %c",&choice);if(choice=='Y'||choice=='y'){system("cls");delete_returnbook();}}}fclose(fp);}void deletereturnbook(){FILE *fp,*fp1,*fp2,*fp3;struct person p;int numbers;printf("\n\n确认删除?请再次输入书编号:");scanf("%d",&numbers);if((fp=fopen("jieshujilu.txt","r"))==NULL){printf("不能打开此文件!\n");exit(0);}if((fp1=fopen("tempbook.txt","w"))==NULL){printf("不能打开此文件!\n");exit(0);}while(!feof(fp)){fscanf(fp,"%s %s %d %s %d %s %d %d",,p.classes,&p.number,p. telephone,&p.NO,p.bookname,&p.borrowdate,&p.returndate);if(p.NO==numbers)continue;elsefprintf(fp1,"%s %s %d %s %d %s %d %d",,p.classes,p.nu mber,p.telephone,p.NO,p.bookname,p.borrowdate,p.returndate);}fclose(fp);fclose(fp1);if((fp2=fopen("tempbook.txt","r"))==NULL){printf("不能打开此文件!\n");exit(0);}if((fp3=fopen("jieshujilu.txt","w"))==NULL){printf("不能打开此文件!\n");exit(0);}while(!feof(fp2)){ //将临时文件写人源文件fscanf(fp2,"%s %s %d %s %d %s %d %d",,p.classes,&p.number, p.telephone,&p.NO,p.bookname,&p.borrowdate,&p.returndate);fprintf(fp3,"%s %s %d %s %d %s %d %d",,p.classes,p.nu mber,p.telephone,p.NO,p.bookname,p.borrowdate,p.returndate);}fclose(fp2);fclose(fp3);printf("\n 删除成功!\n");}5)Main函数int main(void){int choice;char choice2;struct book;struct person;do{printf("\n\n\n 图书馆管理系统\n\a");printf(" *******************************************************\n");printf(" ***朱老师您好吖********功能选项:登记******请按1,******\n");printf(" ******************************* 查看/查询*请按2 ******\n");printf(" ******************************* 删除***** 请按3 ******\n");printf(" ******************************* 退出***** 请按0 ******\n");printf(" *******************************************************\n\n\n");printf(" 请选择功能:");scanf("%d",&choice);switch(choice){case 1:printf(" 登记选项:新书登记请按1,借书登记请按2,返回请按3\n");printf("请选择:");scanf("%d",&choice);switch(choice){case 1:system("cls"); //清屏printf("新书资料登记:\n\n");new_book(); //新书登记printf("登记完毕!\n");printf("\n");scanf(" %c",&choice2);system("cls");break;case 2:system("cls");printf("借书资料登记:\n\n");new_person(); //借书登记printf("\n press anykey ");scanf(" %c",&choice2);system("cls");break;case 3:system("cls");break;}break;case 2:printf(" 查看/查询选项:书库查看请按1,总借书记录查看请按2,到期记录查询请按3,返回请按4\n");printf("请选择:");scanf("%d",&choice);switch(choice){case 1:system("cls");printf("欢迎朱老师进入书库!\n\n");printf("书名书编号类型到书日期\n");printf("------------------------------------------\n");see_book(); //书库显示printf("\n press anykey ");scanf(" %c",&choice2);system("cls");break;case 2:system("cls");printf("欢迎朱老师进入借书记录!\n\n");printf(" 班级学号联系书编号书名借书日期到书日期\n");printf("--------------------------------------------------------\n");see_person(); //借书记录显示printf("\n press anykey ");scanf(" %c",&choice2);system("cls");break;case 3:system("cls");search_person(); //显示符合记录printf("\n press anykey ");scanf(" %c",&choice2);system("cls");break;case 4:system("cls");break;}break;case 3:printf(" 删除选项:旧书删除请按1,借书记录删除请按2,返回请按3\n");printf("请选择:");scanf("%d",&choice);switch(choice){case 1:system("cls");delete_books(); //删除ingprintf("\n press anykey ");scanf(" %c",&choice2);system("cls");break;case 2:system("cls");delete_returnbook(); //删除ingprintf("\n press anykey ");scanf(" %c",&choice2);system("cls");break;case 3:system("cls");break;}break;case 0:system("cls");}}while(choice != 0);return 0;}四、调试与测试主菜单登记查看删除生成的文件信息五、五心得体会经过这次大作业,我觉得代码的编写,最主要的的是编程思想,语言其实不是太重要,思路最重要!六、用户手册程序执行文件为lib sys.exe,打开执行文件后按提示操作即可。

相关主题