图书管理系统(含代码)课程设计报告_第1页
图书管理系统(含代码)课程设计报告_第2页
图书管理系统(含代码)课程设计报告_第3页
图书管理系统(含代码)课程设计报告_第4页
图书管理系统(含代码)课程设计报告_第5页
已阅读5页,还剩34页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

中南大学C++课程设计实践报告题目:学生信息管理系统专业班级:城地1502指导老师:蒋冲姓名:杨帆学号:0202150222完成时间:2023年7月13日中南大学课程设计报告目录成员设计内容简介 1第一章系统概述 11.1功能简介 21.2设计思路 3第二章第二章系统功能的分析和简要框图 32.1主函数42.2初始化文件42.3主菜单52.4查询72.5借书操作82.6还书操作92.7新增图书102.8删除图书112.9新增读者122.10读者信息132.11借阅记录14第三章调试及运行结果 153.1主菜单 153.2查询图书信息 163.3归还图书 163.4借阅图书: 173.5读者注册: 183.6图书信息修改 193.7新书采编入库 193.8删除图书信息 203.9借阅记录 203.10读者信息: 21总结 214.1遇到的问题及解决方法 214.2收获和体会 234.3致谢23第五章源代码235.1book.h235.2head.h235.3addbook.cpp245.4addreader.cpp265.5brbook.cpp285.6checkbr.cpp325.7checkreader.cpp325.8delbook.cpp335.9findbook.cpp355.10main.cpp425.11mainmenu.cpp425.11return.cpp445.11setfile.cpp46前言图书管理在生活中运用非常广泛,因此需要用许多的程序来对它们进行管理。此程序包含了图书信息的录入、图书信息的浏览、图书的查询和排序、图书信息的删除与借书,还书等。通过编译一个C++语言函数,其中包含一个主函数,多个子函数,主函数调用其余的子函数实现人们能够简易、快捷的了解并找到自己所想要的信息的功能。该图书信息管理系统记录了图书馆中图书的图书号、书名、作者姓名、出版社名、图书的现存量和总库存量等书籍数据,同时有对书籍数据以及借阅者的信息进行管理,可以实现对书籍和借阅者进行添加和管理。成员设计内容简介一、题目及要求题目三:图书管理系统设计图书管理信息包括:图书名称、图书编号、单价、作者、存在状态、借书人姓名、性别、学号等功能描述1、新进图书根本信息的输入。2、图书根本信息的查询。3、对撤消图书信息的删除。4、为借书人办理注册。5、办理借书手续。6、办理还书手续要求:使用二进制文件方式存储数据,系统以菜单方式工作二、目的与意义《C++语言课程设计》课程设计是计算机科学与技术专业实践性环节之一,要求明确课程设计的目的,能根据课程设计的要求,查阅相关文献,为完成设计准备必要的知识;通过课程设计的综合训练可以使学生进一步理解和掌握面向对象程序设计课程的根本知识;掌握面向对象程序设计的思路和方法;根本具有利用面向对象的方法以及C++的编程思想来完成系统设计的能力提高学生用高级语言进行程序设计的能力,重点提高用C语言进行文件操作和绘图应用的编程技术水平。三、小组成员及小组分工小组成员:杨帆、余华龙、姚翔宇杨帆:brkook()findbook()addbook()delbook()姚翔宇:checkreader(),checkbr(),returnbook();mainmenu(),余华龙:头文件,main(),setfile(),addreader()四、主要参考文献《C++语言程序设计〔第三版〕》,郑莉,清华大学出版社,2004《C++PrimerPlus〔第六版〕》,StephenPrata,人民邮电出版社,2023总体设计功能简介本软件是一个简单的图书管理系统,软件为win32控制应用台程序。完成以下功能:1. 新进图书根本信息的输入2. 图书根本信息的查询3. 对撤销图书信息的删除4. 为借书人办理注册5. 办理借书手续〔非注册会员不能借书〕6. 办理还书手续补充要求:使用二进制文件方式存储数据系统以菜单方式工作1.2设计思路根本功能:主菜单〔1〕新书采编入库:新购入一种书,登记到图书信息中去。如果这种书在帐中已有,那么只将总库存量增加。〔3〕删除图书:某种书已无保存价值,将它从图书帐目中删除。〔4〕查询已在图书库中的图书信息。〔5〕对读者的信息进行管理:新增,查询。〔6〕查看借阅记录查询图书信息:a)按书名查询:如查找所有书名为“数据结构〞的图书。b)按作者姓名查询:如查找所有“张三〞编写的图书。c)按出版社名查询:如查找所有“机械工业出版社〞出版的图书。d)按书籍编号查询:如查找书籍编号为“978-7-115-27946-0〞的图书。e) 组合查询:如查找所有“张三〞编写的、由“机械工业出版社〞出版的图书。〔2〕借阅:如果一种书的现存量大于零,那么借出一本,登记借阅者的信息,改变该书的现存量。〔3〕归还:注销对借阅者的登记,改变该书的现存量。整个程序的主函数由以下局部构成:头文件head.h、头文件book.h、setfile、mainmenu1.头文件head.h、book.h实现两个类的定义bookdate图书类,实现对图书的描述:图书根本信息如图书编号、书名、作者、出版社、单价等;图书的管理信息如查找图书及新增图书、删除图书〔通过书的现存量、书的总库存量描述〕等;Readerdata读者及图书管理类,公有继承图书类,实现对读者信息的描叙:读者的个人资料如借阅者姓名、学号、性别、登陆密码等;读者借阅信息如借还图书本数等;类的数据成员和各函数的功能描述classbookdata//数据成员:charbookisn[50]//图书编号,bookname[50]//书名writer[50]//作者publishing[50]//出版社;、、、nowstore,//书的现存量allstore,书//的总库存量price//单价classmanagebook数据成员:reader[50]//借阅者姓名,rdID[50]//学号gender[50]//性别password[50]//登陆密码num//借还图书本数各个功能函数:voidsetfile();//初始化数据文件voidmainmenu();//主菜单函数voidfindbook(char*file);//查询图书voidbrbook(char*file);//借阅图书voidreturnbook();//归还图书voidreturnf(char*file,readerdatap);voidaddbook();//新书采编入库voidadd(char*file,bookdatap);voiddelbook();//去除库存,删除图书信息voiddel(char*file,bookdatap);voidaddreader();//新增读者信息voidcheckreader();//查询读者信息voidcheckbr();//查看借阅记录系统功能的分析和简要框图算法分析:在本程序中,头文件定义了两个类:classbookdata和classmanagebook,以及各个功能函数。运行程序,首先执行voidsetfile();函数,该函数初始化数据文件,将在exe程序所在文件夹生成所有数据文件,假设该文件夹没有数据文件,那么生成空的数据文件,数据文件记录图书馆管理系统的所有数据。然后由voidmainmenu();生成主菜单,主菜单运用switch语句区分指令进行执行功能,其他菜单亦雷同形成。1.查询图书信息2.归还图书3.图书信息修改4.读者注册5.读者信息6.借阅记录0.退出系统分别调用相应函数直接在数据文件上对图书执行相应功能。在让借阅者执行查询,借阅,归还图书等操作之前,首先要在初始化的数据文件中添加图书信息,整个图书馆管理系统大体结构就如上所述,大概可分为图书信息管理和借阅者信息管理2个模块,外加一个借阅记录那么构成图书馆管理系统。本程序对数据文件中数据的编辑是通过将数据文件中的数据编辑后转移至中转文件中,再将中转文件的数据复制回清空了的数据文件当中,即可完成编辑。//主函数包含三个局部:建立数据文件setfile();设置背景为紫色字体亮白色//修改窗口名称2.2setfile.cpp//初始化数据文件初始化数据文件,将在exe程序所在文件夹生成所有数据文件,假设该文件夹没有数据文件,那么生成空的数据文件,数据文件记录图书馆管理系统的所有数据。包括:中转文件.datReaderdata.datrecord.datbookdata.dat中转文件1.dat通过将数据文件中的数据编辑后转移至中转文件中,再将中转文件的数据复制回清空了的数据文件当中,完成编辑。2.3mainmenu.cpp//主菜单\2.4findbook.cpp//查询图书2.5brbook.cpp//借阅图书是是是否否否是否继续查询图书本数缺乏,请重新输入成功借阅本此图书!!!Nowstore<0?是否请输入要借阅此图书的本数是k=Y,k=y或k=N,k=n?i=1?该图书现存量为0,无法借阅按要求输入读者信息nowstore=o?输出图书信息确定要借阅此书是否否输入错误请重新输入work=y或work=Y?结束开始是是是否否否是否继续查询图书本数缺乏,请重新输入成功借阅本此图书!!!Nowstore<0?是否请输入要借阅此图书的本数是k=Y,k=y或k=N,k=n?i=1?该图书现存量为0,无法借阅按要求输入读者信息nowstore=o?输出图书信息确定要借阅此书是否否输入错误请重新输入work=y或work=Y?结束开始bookname;reader;rdID;num;图书是否存在?bookname;reader;rdID;num;图书是否存在?修改借阅记录图书信息修改借阅记录图书信息是否继续归还?mainmenuTrueTrueFalseFalse开始结束booknamebooknamewriterpublishingbookisnnowstore是否添加新书?调用addbookname、writer、publishing相同?TrueFalse开始TrueFalse该书籍已存在输入新增加的本数并通过中传文件写入数据文件直接将新书籍信息写入数据文件继续添加新书?FalseTruemainmenu结束2.7addbook.cpp//新书采编入库2.8delbook.cpp\//去除库存,删除图书信息否输错请重试结束否K=1?是K=1或k=2?请根据下面提示输入所要注销的书籍的信息是是否是否继续删除图书本数缺乏,请重新输入请输入注销本书是否是W=1或w=0?该图书信息不存在!!!w=o?否输入错误,请重新输入!!!开始否输错请重试结束否K=1?是K=1或k=2?请根据下面提示输入所要注销的书籍的信息是是否是否继续删除图书本数缺乏,请重新输入请输入注销本书是否是W=1或w=0?该图书信息不存在!!!w=o?否输入错误,请重新输入!!!开始2.9addreader.cpp//新增读者信息reader;num;读者信息是否存在?是否要继续查询借阅者信息?mainmenuTreader;num;读者信息是否存在?是否要继续查询借阅者信息?mainmenuTrueTrueFalseFalse以读的方式翻开数据文件进行查询readergenderrdIDnum;该借阅者信息不存在!!!num;结束开始2.11checkbr.cpp//查看借阅记录开始开始findbook借阅记录:bookisnbooknamereaderrdIDnum结束mainmenu从借阅记录〔record.dat〕中直接读取第三章调试及运行结果3.1主菜单3.2查询图书信息3.3归还图书3.4借阅图书:3.5读者注册:3.6图书信息修改3.7新书采编入库3.8删除图书信息3.9借阅记录3.10读者信息:第四章总结4.1遇到的问题及解决方案问题一:常出现没有与这些操作符匹配的运算符解决方案是:引入适宜的头文件,并重新输入#include内容,编译器的报错就会消失。问题二:不懂得对数据文件的操作解决方案:通过对模板程序的模仿,并了解自学fstream常用方法的使用。问题三:程序常因错误输入而崩溃解决方案:运用一些可以容错的语句来防止多余的输入,并能返回重新输入。也可以运用提示词来减少用户的非法输入。问题四:运用二进制文件读写解决方案:意我们不再使用插入和提取操作符(译者注:<<和>>操作符).你可以这么做,但它不会用二进制方式读写。你必须使用read()和write()方法读取和写入二进制文件.创立一个二进制文件,看下一行。ofstreamfout("file.dat",ios::binary);这会以二进制方式翻开文件,而不是默认的ASCII模式。问题五:文件结构的混乱解决方案:在书写时保持良好的书写习惯,并在适当的地方增加注释4.2收获和体会虽然在这个学期中,我们已经学习了《C++语言程序设计》这门课,但是知识的运用完全是一个更高水平的要求。这次设计,不仅稳固了我以前所学的知识,还让我对c++语言有了更深一步的了解,掌握了更多的技巧和技能。在这次课程设计中,我们首先对系统的整体功能进行了构思,然后用结构化分析方法进行分析,将整个系统清楚的划分为几个模块,再根据每个模块的功能编写代码。而且尽可能的将模块细分,最后在进行函数的调用。我们在函数的编写过程中,我们不仅用到了for循环、while循环和switch语句,还用到了函数之间的调用〔包括递归调用〕。编写一个完整并且有严密逻辑,以及抗非法输入的程序对于初学者来说还是有相当的挑战性的,我们在编写的过程中遇到了重重困难,有些克服了进步了。然而更多地是感受到自己知识储藏的缺乏与实现按想法之间的矛盾。当然,我们的程序还有很多不完善的地方,比方说,我们试图以二进制的方式保存文件,最终也是心有余而力缺乏没有做到,程序在调试中不断的冒出bug,大晚上面对电脑debug到生无可恋。总之,这次设计程序让我受益良多,我好好珍惜了这种难得的时机,并且在这个过程中深刻认识到了自己的缺乏。4.3致谢为期半个月的课设总算是结束了,特此向在这短时间指导过我们的老师,还有机房和蔼可亲的管理老师,一起写报告的同学,深夜debug的自己,道一声谢谢。第五章源代码Book.h#pragmaonce#include<iostream>#include"head.h"#include<vector>#include<fstream>#include<windows.h>usingnamespacestd;voidsetfile();//初始化数据文件voidmainmenu();//主菜单函数voidfindbook(char*file);//查询图书voidbrbook(char*file,readerdatap);//借阅图书voidreturnbook();//归还图书voidreturnf(char*file,readerdatap);voidaddbook();//新书采编入库voidadd(char*file,bookdatap);voiddelbook();//去除库存,删除图书信息voiddel(char*file,bookdatap);voidaddreader();//新增读者信息voidcheckreader();//查询读者信息voidcheckbr();//查看借阅记录Head.h#pragmaonce#include<iostream>#include<string.h>#include<iomanip>#include<fstream>#include<cstdlib>usingnamespacestd;//图书类classbookdata{public://构造函数 bookdata(char*bn="bookname\0",char*w="writer\0",char*p="publishing\0",char*bisn="bookisn\0",intn=0,inta=0,intpri=0) { strcpy_s(bookname,bn); strcpy_s(writer,w); strcpy_s(publishing,p); strcpy_s(bookisn,bisn); nowstore=n; allstore=a; price=pri; }bookdata*next;//数据成员charbookisn[50],bookname[50],writer[50],publishing[50];//图书编号、书名、作者、出版社intnowstore,allstore,price;//书的现存量、书的总库存量、单价};//读者及图书管理类,公有继承图书类classreaderdata:publicbookdata{public://构造函数 readerdata(char*rn="reader\0",char*id="0202150222\0",char*ge="男\0",char*p="password\0") { strcpy_s(reader,rn); strcpy_s(rdID,id); strcpy_s(gender,ge); strcpy_s(password,p); }charreader[50],rdID[50],gender[50],password[50];//借阅者姓名、学号、性别、登陆密码intnum;//借还图书本数};Addbook.cpp#include"head.h"#include"book.h"voidaddbook(){ system("cls");while(1) {bookdatap;charwork; cout<<"\t确定要添加新书?(y/n):"<<endl;while(1) { cin>>work;if(work=='Y'||work=='y')break;elseif(work=='N'||work=='n'){system("cls");return;}else{cout<<"\n\t输入错误,请重新输入!!!"<<endl;continue;} } system("cls"); cout<<endl<<"\t\t根据下面提示输入新书籍的信息"<<endl<<endl<<"\t书名:"; cin>>p.bookname; cout<<"\t"; cin>>p.writer; cout<<"\t出版社:"; cin>>p.publishing; cout<<"\t图书编号:"; cin>>p.bookisn; cout<<"\t单价:"; cin>>p.price; cout<<"\t数量:"; cin>>p.nowstore; add("bookdata.dat",p); system("cls");charch; cout<<"\t添加成功!!!\n\t是否要继续添加新书?(y/n):"<<endl;while(1) { cin>>ch;if(ch=='Y'||ch=='y') { system("cls");addbook(); }//函数嵌套调用,判断是否继续进行添加操作elseif(ch=='N'||ch=='n'){system("cls");return;}else{cout<<"\n\t输入错误,请重新输入!!!"<<endl;continue;} } }}voidadd(char*file,bookdatap){intc=0;bookdatat;intj=0;//标记书籍是否已经存在ofstreamf("中转文件.dat",ios::binary|ios::out);f.close();//清空中转文件ifstreamfa(file,ios::binary|ios::in); f.open("中转文件.dat",ios::binary|ios::app);while(fa>>t.bookname>>t.writer>>t.bookisn>>t.price>>t.publishing>>t.nowstore>>t.allstore) {if((!strcmp(t.bookname,p.bookname))&&(!strcmp(t.writer,p.writer))&&(!strcmp(t.publishing,p.publishing))) { cout<<"\t该书籍已存在,请输入新增加的本数:";//判断新添加的书籍是否已存在 cin>>c; t.nowstore=t.nowstore+c; t.allstore=t.allstore+c;j=1; }//新添加的书籍已存在,那么直接改动现存量和总库存量 f<<t.bookname<<"\t"<<t.writer<<"\t"<<t.bookisn<<"\t"<<t.price<<"\t"<<t.publishing<<"\t"<<t.nowstore<<"\t"<<t.allstore<<endl; }if(j){ fa.close();f.close(); f.open(file,ios::binary|ios::out);f.close(); fa.open("中转文件.dat",ios::binary|ios::in); f.open(file,ios::binary|ios::app);while(fa>>t.bookname>>t.writer>>t.bookisn>>t.price>>t.publishing>>t.nowstore>>t.allstore) { f<<t.bookname<<"\t"<<t.writer<<"\t"<<t.bookisn<<"\t"<<t.price<<"\t"<<t.publishing<<"\t"<<t.nowstore<<"\t"<<t.allstore<<endl; } fa.close(); f.close(); }else{ fa.close();f.close(); f.open(file,ios::binary|ios::app);p.allstore=p.nowstore;//新添加的书籍尚未存在,那么直接在数据文件中追加 f<<p.bookname<<"\t"<<p.writer<<"\t"<<p.bookisn<<"\t"<<p.price<<"\t"<<p.publishing<<"\t"<<p.nowstore<<"\t"<<p.allstore<<endl; f.close(); }}Addreader.cpp#include"head.h"#include"book.h"voidaddreader(){ system("cls");readerdatap,t;charwork; cout<<"\t确定要添加新的借阅者信息?(y/n):"<<endl;while(1)//询问添加新的借阅者与否 { cin>>work;if(work=='Y'||work=='y')break;elseif(work=='N'||work=='n'){system("cls");return;}else{cout<<"\n\t输入错误,请重新输入!!!"<<endl;continue;} } cout<<endl<<"\t\t根据下面提示输入新的借阅者的信息"<<endl<<endl<<"\t姓名:"; cin>>p.reader; cout<<"\t学号:"; cin>>p.rdID; cout<<"\t性别:"; cin>>p.gender; cout<<"\t密码:"; cin>>p.password;inti=0;ifstreamf("readerdata.dat",ios::binary|ios::in);while(f>>t.reader>>t.rdID>>t.gender>>t.password) {if((!strcmp(t.reader,p.reader))&&(!strcmp(t.rdID,p.rdID)))//判断新添加的借阅者是否已存在 { cout<<"\t该借阅者已记录在案!!!"<<endl;i=1;break; } } f.close();if(!i){ofstreamf1("readerdata.dat",ios::binary|ios::app); f1<<p.reader<<"\t"<<p.rdID<<"\t"<<p.gender<<"\t"<<p.password<<endl;//新添加的借阅者假设不存在,那么进行添加 f1.close(); } system("cls");charch; cout<<"\t添加成功!!!\n是否要继续添加新的借阅者信息?(y/n):"<<endl;while(1) {//函数嵌套调用,判断是否继续进行添加操作 cin>>ch;if(ch=='Y'||ch=='y') { system("cls");addreader(); }elseif(ch=='N'||ch=='n'){system("cls");mainmenu();}else{cout<<"\n\t输入错误,请重新输入!!!"<<endl;continue;} }}Brbook.cpp#include"head.h"#include"book.h"voidbrbook(char*file,readerdatap){intw=0;readerdatat,q;p.num=0;ofstreamf("中转文件.dat",ios::binary|ios::out);f.close();ifstreamfa(file,ios::binary|ios::in); f.open("中转文件.dat",ios::binary|ios::app);while(fa>>t.bookname>>t.writer>>t.bookisn>>t.price>>t.publishing>>t.nowstore>>t.allstore) {if(!strcmp(t.bookisn,p.bookisn)){ cout<<"\t\t================================================="<<endl; cout<<"\t该书信息:"<<endl; cout<<endl; cout<<"\t书名:"<<t.bookname<<endl; cout<<"\t"<<t.writer<<endl; cout<<"\t图书号:"<<t.bookisn<<endl; cout<<"\t图书单价:"<<t.price<<endl; cout<<"\t出版社:"<<t.publishing<<endl; cout<<"\t现存量:"<<t.nowstore<<endl; cout<<"\t总库存量:"<<t.allstore<<endl;chark;while(1) { cout<<"\n\t确定要借阅此图书?(y/n):"<<endl; cin>>k;if(k!='Y'&&k!='y'&&k!='N'&&k!='n') { cout<<"\t输入错误,请重新输入!!!"<<endl;continue; }elsebreak; }if(k=='Y'||k=='y') {while(1) {if(t.nowstore==0) { system("cls");cout<<"\t该图书现存量为0,无法借阅!!!"<<endl;mainmenu(); } system("cls"); cout<<"\t请输入你的姓名:"; cin>>p.reader; cout<<"\t请输入你的学号:"; cin>>p.rdID; cout<<"\t请输入密码:"; cin>>p.password;inti=0;ifstreamf("readerdata.dat",ios::binary|ios::in);while(f>>t.reader>>t.rdID>>t.gender>>t.password) {if((!strcmp(t.reader,p.reader))&&(!strcmp(t.rdID,p.rdID))) {if((!strcmp(t.password,p.password))) { i=1;break; }else { i=2;break; } }else { i=0; }//i为判断标志,该借阅者信息存在为1.不存在为0,密码输入错误为2,其它输入容错 } f.close();if(i==0){ system("cls"); cout<<"\n\t该借阅者信息不存在!!!\n"<<endl; brbook("bookdata.dat",p); }elseif(i==2) { system("cls"); cout<<"\n\t密码输入错误!!!\n"<<endl;brbook("bookdata.bat,",p); }while(1) { system("cls"); cout<<"\t请输入要借阅此图书的本数:"<<endl; cin>>p.num; t.nowstore=t.nowstore-p.num;//成功借阅后,对图书信息的现存量进行修改if(t.nowstore<0)//判断图书本数足够与否 { t.nowstore=t.nowstore+p.num; cout<<"\t图书本数缺乏,请重新输入!!!"<<endl;continue; }else{ w=1;//所借阅图书现存量足够时,w=1,否那么w=0inta=0;ofstreamf0("中转文件1.dat",ios::binary|ios::out);f0.close(); f0.open("中转文件1.dat",ios::binary|ios::app);ifstreamf("record.dat",ios::binary|ios::in);while(f>>q.bookisn>>q.bookname>>q.reader>>q.rdID>>q.num) {if((!strcmp(t.bookisn,q.bookisn))&& (!strcmp(t.bookname,q.bookname))&&(!strcmp(t.reader,q.reader))&& (!strcmp(t.rdID,q.rdID))&&!strcmp(t.password,q.password)) { q.num=q.num+p.num;a=1; }//a为判断标志,该借阅记录存在为1.不存在为0 f0<<q.bookisn<<"\t"<<q.bookname<<"\t"<<q.reader<<"\t"<<q.rdID<<"\t"<<q.num<<endl; } f0.close();f.close();if(a){ofstreamf0("record.dat",ios::binary|ios::out);f0.close(); f0.open("record.dat",ios::binary|ios::app);ifstreamf("中转文件1.dat",ios::binary|ios::in);//借阅记录存在时,直接修改借阅本数q.numwhile(f>>q.bookisn>>q.bookname>>q.reader>>q.rdID>>q.num) f0<<q.bookisn<<"\t"<<q.bookname<<"\t"<<q.reader<<"\t"<<q.rdID<<"\t"<<q.num<<endl; f0.close();f.close(); }else{ofstreamf1("record.dat",ios::binary|ios::app);//借阅记录不存在,直接添加新的记录 f1<<t.bookisn<<"\t"<<t.bookname<<"\t"<<p.reader<<"\t"<<p.rdID<<"\t"<<p.num<<endl; }break; } }break; } }elseif(k=='N'||k=='n')return; } f<<t.bookname<<"\t"<<t.writer<<"\t"<<t.bookisn<<"\t"<<t.price<<"\t"<<t.publishing<<"\t"<<t.nowstore<<"\t"<<t.allstore<<endl; } fa.close();f.close(); f.open(file,ios::binary|ios::out);f.close(); fa.open("中转文件.dat",ios::binary|ios::in); f.open(file,ios::binary|ios::app);//成功借阅后,对图书信息的现存量进行修改while(fa>>t.bookname>>t.writer>>t.bookisn>>t.price>>t.publishing>>t.nowstore>>t.allstore) { f<<t.bookname<<"\t"<<t.writer<<"\t"<<t.bookisn<<"\t"<<t.price<<"\t"<<t.publishing<<"\t"<<t.nowstore<<"\t"<<t.allstore<<endl; } fa.close(); f.close();if(!w) { cout<<"\t该图书不存在或库存缺乏!!!"<<endl; }else{ cout<<"\t成功借阅"<<p.num<<"本此图书!!!"<<endl; system("pause");return; }}Checkbr.cpp#include"head.h"voidcheckbr(){ system("cls");readerdatat; cout<<"\n\t借阅记录:\n"<<endl;ifstreamf("record.dat",ios::binary|ios::in);//直接输出借阅记录while(f>>t.bookisn>>t.bookname>>t.reader>>t.rdID>>t.num){ cout<<"\t图书号:"<<t.bookisn<<"\n"<<"\t书名:"<<t.bookname<<"\n"<<"\t借阅者:"<<t.reader<<"\n"<<"\t学号:"<<t.rdID<<"\n"<<"\t借阅数量:"<<t.num<<endl; cout<<"\t============================================"<<endl; } system("pause"); system("cls");}Checkreader.cpp#include"head.h"#include"book.h"voidcheckreader(){ system("cls");readerdatat,p;inti=0; cout<<"\n\t输入要查询的借阅者姓名:\n"<<endl; cin>>p.reader;ifstreamf("readerdata.dat",ios::binary|ios::in);//以读的方式翻开数据文件进行查询while(f>>t.reader>>t.rdID>>t.gender>>t.password) {if(!strcmp(t.reader,p.reader)) { cout<<"\n\t借阅者:"<<t.reader<<"\t"<<"性别:"<<t.gender<<"\n"<<"\t学号:"<<t.rdID<<endl; cout<<"\t============================================"<<endl; i=1; } }if(!i)cout<<"\t该借阅者信息不存在!!!"<<endl;charch1; cout<<"\n\t是否要继续查询借阅者信息?(y/n):"<<endl;while(1)//函数嵌套调用,判断是否继续进行查询操作 { cin>>ch1;if(ch1=='Y'||ch1=='y') checkreader();elseif(ch1=='N'||ch1=='n'){system("cls");return;}else{cout<<"\n\t输入错误,请重新输入!!!"<<endl;continue;} }}Delbook.cpp#include"head.h"#include"book.h"voiddelbook(){ system("cls");while(1) {bookdatap; cout<<endl<<"\t请根据下面提示输入所要注销的书籍的信息"<<endl<<endl<<"\t图书编号:"; cin>>p.bookisn;//调用删除函数对图书信息进行注销 del("bookdata.dat",p); }}voiddel(char*file,bookdatap){intc=0,w=0;bookdatat;ofstreamf("中转文件.dat",ios::binary|ios::out);f.close();ifstreamfa(file,ios::binary|ios::in); f.open("中转文件.dat",ios::binary|ios::app);while(fa>>t.bookname>>t.writer>>t.bookisn>>t.price>>t.publishing>>t.nowstore>>t.allstore) {if((!strcmp(t.bookisn,p.bookisn))) { cout<<"\t该书信息:"<<endl;w=1; cout<<"\t书名:"<<t.bookname<<endl; cout<<"\t"<<t.writer<<endl; cout<<"\t图书号:"<<t.bookisn<<endl; cout<<"\t图书单价:"<<t.price<<endl; cout<<"\t出版社:"<<t.publishing<<endl; cout<<"\t现存量:"<<t.nowstore<<endl; cout<<"\t总库存量:"<<t.allstore<<endl;chark;while(1) { cout<<"\t请选择:(1.完全删除此种图书)(2.只删除局部此种图书)"<<endl; cin>>k;if(k=='1'||k=='2')break;else{cout<<"\t输入错误,请重新输入!!!"<<endl;continue;} }if(k=='1')continue;elseif(k=='2') {while(1) { cout<<"\t请输入要注销的本数:"<<endl; cin>>c; t.nowstore=t.nowstore-c;t.allstore=t.allstore-c;if(t.nowstore<0||t.allstore<0) { t.nowstore=t.nowstore+c;t.allstore=t.allstore+c; cout<<"\t输入错误,请重新输入!!!"<<endl;continue; }elsebreak; } } } f<<t.bookname<<"\t"<<t.writer<<"\t"<<t.bookisn<<"\t"<<t.price<<"\t"<<t.publishing<<"\t"<<t.nowstore<<"\t"<<t.allstore<<endl; } fa.close();f.close(); f.open(file,ios::binary|ios::out);f.close(); fa.open("中转文件.dat",ios::binary|ios::in);//通过中转文件进行对图书信息删除 f.open(file,ios::binary|ios::app);while(fa>>t.bookname>>t.writer>>t.bookisn>>t.price>>t.publishing>>t.nowstore>>t.allstore) { f<<t.bookname<<"\t"<<t.writer<<"\t"<<t.bookisn<<"\t"<<t.price<<"\t"<<t.publishing<<"\t"<<t.nowstore<<"\t"<<t.allstore<<endl; } fa.close(); f.close();if(!w)cout<<"\n\t该图书信息不存在!!!\n\t是否要继续删除图书?(y/n):"<<endl;elsecout<<"\n\t成功对该图书进行了注销!!!\n\t是否要继续删除图书?(y/n):"<<endl;charch;while(1) {//函数嵌套调用,判断是否继续进行添加操作 cin>>ch;if(ch=='Y'||ch=='y') { system("cls");delbook(); }elseif(ch=='N'||ch=='n'){system("cls");mainmenu();}else{cout<<"\n\t输入错误,请重新输入!!!"<<endl;continue;} }}Findbook.cpp#include"head.h"#include"book.h"voidfindbook(char*file){ system("cls");while(1) { cout<<"\n\t\t============================================"<<endl; cout<<"\t\t\t请选择查询方式\t"<<endl; cout<<"\t\t\t1.按书名查询\t"<<endl; cout<<"\t\t\t2.按作者姓名查询\t"<<endl; cout<<"\t\t\t3.按出版社名查询\t"<<endl; cout<<"\t\t\t4.按书名与作者(组合)查询\t"<<endl; cout<<"\t\t\t5.按书名与出版社(组合)查询\t"<<endl; cout<<"\t\t\t6.按作者与出版社(组合)查询\t"<<endl; cout<<"\t\t\t7.按图书编号查询\t"<<endl; cout<<"\t\t\t8.输出所有图书\t"<<endl; cout<<"\t\t\t0.返回上一层菜单\t"<<endl; cout<<"\t\t============================================"<<endl;//菜单chark; cin>>k;if(k=='0'){system("cls");mainmenu();}if(k!='1'&&k!='2'&&k!='3'&&k!='4'&&k!='5'&&k!='6'&&k!='7'&&k!='8'&&k!='0') { system("cls");cout<<"\t输入错误,请重新输入!!!"<<endl;continue; }//判断指令输入的对错 bookdatap,t; readerdatah;//已查询的图书信息保存inttag=0;if(k=='1') { system("cls"); cout<<"\t请输入要查询的书名:";cin>>p.bookname; ifstreamf(file,ios::binary|ios::in); cout<<"\t所查询的图书信息:"<<endl;while(f>>t.bookname>>t.writer>>t.bookisn>>t.price>>t.publishing>>t.nowstore>>t.allstore) {if(!strcmp(t.bookname,p.bookname)) { tag=1;//tag为判断标志,该图书信息存在为1.不存在为0 cout<<"\t书名:"<<t.bookname<<endl; cout<<"\t"<<t.writer<<endl; cout<<"\t图书号:"<<t.bookisn<<endl; cout<<"\t图书单价:"<<t.price<<endl; cout<<"\t出版社:"<<t.publishing<<endl; cout<<"\t现存量:"<<t.nowstore<<endl; cout<<"\t总库存量:"<<t.allstore<<endl; strcpy_s(h.bookisn,t.bookisn); } }if(tag==0){ cout<<"\n\t该书不存在!!!"<<endl; } }elseif(k=='2') { system("cls"); cout<<"\t请输入要查询的书籍作者姓名:";cin>>p.writer; ifstreamf(file,ios::binary|ios::in); cout<<"\t所查询的图书信息:"<<endl;while(f>>t.bookname>>t.writer>>t.bookisn>>t.price>>t.publishing>>t.nowstore>>t.allstore){if(!strcmp(t.writer,p.writer)) { tag=1; cout<<"\t书名:"<<t.bookname<<endl; cout<<"\t"<<t.writer<<endl; cout<<"\t图书号:"<<t.bookisn<<endl; cout<<"\t图书单价:"<<t.price<<endl; cout<<"\t出版社:"<<t.publishing<<endl; cout<<"\t现存量:"<<t.nowstore<<endl; cout<<"\t总库存量:"<<t.allstore<<endl; strcpy_s(h.bookisn,t.bookisn); } }if(tag==0){ cout<<"\n\t该书不存在!!!"<<endl; } }elseif(k=='3') { system("cls"); cout<<"\t请输入要查询的书籍出版社:";cin>>p.publishing; ifstreamf(file,ios::binary|ios::in); cout<<"\t所查询的图书信息:"<<endl;while(f>>t.bookname>>t.writer>>t.bookisn>>t.price>>t.publishing>>t.nowstore>>t.allstore) {if(!strcmp(t.publishing,p.publishing)) { tag=1; cout<<"\t书名:"<<t.bookname<<endl; cout<<"\t"<<t.writer<<endl; cout<<"\t图书号:"<<t.bookisn<<endl; cout<<"\t图书单价:"<<t.price<<endl; cout<<"\t出版社:"<<t.publishing<<endl; cout<<"\t现存量:"<<t.nowstore<<endl; cout<<"\t总库存量:"<<t.allstore<<endl; strcpy_s(h.bookisn,t.bookisn); } }if(tag==0){ cout<<"\n\t该书不存在!!!"<<endl; } }elseif(k=='4'){ system("cls"); cout<<"\t请输入要查询的书籍书名:"; cin>>p.bookname; cout<<"\t请输入要查询的书籍作者姓名:"; cin>>p.writer; ifstreamf(file,ios::binary|ios::in); cout<<"\t所查询的图书信息:"<<endl;while(f>>t.bookname>>t.writer>>t.bookisn>>t.price>>t.publishing>>t.nowstore>>t.allstore) {if(!strcmp(t.bookname,p.bookname)&&!strcmp(t.writer,p.writer)) { tag=1; cout<<"\t书名:"<<t.bookname<<endl; cout<<"\t"<<t.writer<<endl; cout<<"\t图书号:"<<t.bookisn<<endl; cout<<"\t图书单价:"<<t.price<<endl; cout<<"\t出版社:"<<t.publishing<<endl; cout<<"\t现存量:"<<t.nowstore<<endl; cout<<"\t总库存量:"<<t.allstore<<endl; strcpy_s(h.bookisn,t.bookisn); } }if(tag==0){ cout<<"\n\t该书不存在!!!"<<endl; } }elseif(k=='5') { system("cls"); cout<<"\t请输入要查询的书籍书名:";cin>>p.bookname; cout<<"\t请输入要查询的书籍出版社:";cin>>p.publishing; ifstreamf(file,ios::binary|ios::in); cout<<"\t所查询的图书信息:"<<endl;while(f>>t.bookname>>t.writer>>t.bookisn>>t.price>>t.publishing>>t.nowstore>>t.allstore) {if(!strcmp(t.bookname,p.bookname)&&!strcmp(t.publishing,p.publishing)) { tag=1; cout<<"\t书名:"<<t.bookname<<endl; cout<<"\t"<<t.writer<<endl; cout<<"\t图书号:"<<t.bookisn<<endl; cout<<"\t图书单价:"<<t.price<<endl; cout<<"\t出版社:"<<t.publishing<<endl; cout<<"\t现存量:"<<t.nowstore<<endl; cout<<"\t总库存量:"<<t.allstore<<endl; strcpy_s(h.bookisn,t.bookisn); } }if(tag==0) { cout<<"\n\t该书不存在!!!"<<endl; } }elseif(k=='6') { system("cls"); cout<<"\t请输入要查询的书籍作者姓名:";cin>>p.writer; cout<<"\t请输入要查询的书籍出版社:";cin>>p.publishing; ifstreamf(file,ios::binary|ios::in); cout<<"\t所查询的图书信息:"<<endl;while(f>>t.bookname>>t.writer>>t.bookisn>>t.price>>t.publishing>>t.nowstore>>t.allstore) {if(!strcmp(t.writer,p.writer)&&!strcmp(t.publishing,p.publishing)) { tag=1; cout<<"\t书名:"<<t.bookname<<endl; cout<<"\t"<<t.writer<<endl; cout<<"\t图书号:"<<t.bookisn<<endl; cout<<"\t图书单价:"<<t.price<<endl; cout<<"\t出版社:"<<t.publishing<<endl; cout<<"\t现存量:"<<t.nowstore<<endl; cout<<"\t总库存量:"<<t.allstore<<endl; strcpy_s(h.bookisn,t.bookisn); } }if(tag==0)cout<<"\n\t该书不存在!!!"<<endl; }elseif(k=='7') { system("cls"); ifstreamf(file,ios::binary|ios::in); cout<<"\t请输入要查询的书籍编号:"<<endl; cin>>p.bookisn;while(f>>t.bookname>>t.writer>>t.bookisn>>t.price>>t.publishing>>t.nowstore>>t.allstore){if(!strcmp(t.bookisn,p.bookisn)) { tag=1; cout<<"\t书名:"<<t.bookname<<endl; cout<<"\t"<<t.writer<<endl; cout<<"\t图书号:"<<t.bookisn<<endl; cout<<"\t图书单价:"<<t.price<<endl; cout<<"\t出版社:"<<t.publishing<<endl; cout<<"\t现存量:"<<t.nowstore<<endl; cout<<"\t总库存量:"<<t.allstore<<endl; strcpy_s(h.bookisn,t.bookisn); } }if(tag==0)cout<<"\n该书不存在!!!"<<endl; }elseif(k=='8') { system("cls"); ifstreamf(file,ios::binary|ios::in); cout<<"\t所有图书信息:"<<endl;while(f>>t.bookname>>t.writer>>t.bookisn>>t.price>>t.publishing>>t.nowstore>>t.allstore){ tag=1; cout<<"\t============================================"<<endl; cout<<"\t\t书名:"<<t.bookname<<endl; cout<<"\t\t"<<t.writer<<endl; cout<<"\t\t图书号:"<<t.bookisn<<endl; cout<<"\t\t图书单价:"<<t.price<<endl; cout<<"\t\t出版社:"<<t.publishing<<endl; cout<<"\t\t现存量:"<<t.nowstore<<endl; cout<<"\t\t总库存量:"<<t.allstore<<endl; cout<<"\t============================================"<<endl; }charch1; cout<<"\n\t是否要继续查询图书?(y/n):"<<endl;while(cin>>ch1) {if(ch1=='Y'||ch1=='y') { system("cls");return; }elseif(ch1=='N'||ch1=='n'){ system("cls");mainmenu(); }else{cout<<"\n\t输入错误,请重新输入!!!"<<endl;continue

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

最新文档

评论

0/150

提交评论