图书管理系统课程设计及代码

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

#includeiostream.h#includeconio.h#includefstream.h#includeiomanip.h#includestring.hconstintMaxr=100;//最多的读者数constintMaxb=100;//最多的图书数constintMaxbor=5;//每位读者最多借的书classBook{//图书类,实现对图书的描述,图书的编号,书名,借出,还入等功能private:inttag;//删除标记1:已删0:未删intno;//图书编号charname[20];//书名charauthor[20];//作者charcbs[20];//出版社intonshelf;//是否再架1:再架2:已借public:Book(){;}char*getname(){//获取书名returnname;}char*getauthorname(){//获取作者名returnauthor;}char*getcbsname(){//获取出版社名returncbs;}intgetno(){//获取图书编号returnno;}intgettag(){//获取删除标记returntag;}voidsetname(charna[]){//设置书名strcpy(name,na);}voidsetonshelf(intoa){onshelf=oa;}voiddelbook(){//删除图书tag=1;}voidaddbook(intn,char*na,char*aa,char*ca,intoa){//增加图书tag=0;no=n;strcpy(name,na);strcpy(author,aa);strcpy(cbs,ca);onshelf=oa;}intborrowbook(){//借书操作if(onshelf0){onshelf--;return1;}return0;}voidretbook(){//还书操作onshelf++;}voiddisp(){//输出图书coutsetw(6)nosetw(18)namesetw(10)authorsetw(10)cbssetw(10)onshelfendl;}};classBDatabase{//图书库类,实现对图书的维护,查找,删除等private:inttop;//图书记录指针Bookbook[Maxb];//图书记录public:BDatabase(){//构造函数,将book.txt读到book[]中Bookb;top=-1;fstreamfile(book.txt,ios::in);while(1){file.read((char*)&b,sizeof(b));if(!file)break;top++;book[top]=b;}file.close();}voidclear(){//全删top=-1;}intaddbook(intn,char*na,char*aa,char*ca,intoa){//增加图书Book*p=query1(n);if(NULL==p){top++;book[top].addbook(n,na,aa,ca,oa);return1;}return0;}Book*query1(intbookid){//按编号查找图书for(inti=0;i=top;i++)if(book[i].getno()==bookid&&book[i].gettag()==0){return&book[i];}returnNULL;}Book*query2(chara[]){//按书名查找图书Book*e;intr=0;for(inti=0;i=top;i++)if(strcmp(book[i].getname(),a)==0&&book[i].gettag()==0){if(r==0)coutsetw(6)编号setw(18)书名setw(10)作者setw(10)出版社setw(10)存量endl;e=&book[i];e-disp();r++;}if(r==0)cout找不到该书!endl;returnNULL;}Book*query3(chara[]){//按作者查找图书Book*e;intr=0;for(inti=0;i=top;i++)if(strcmp(book[i].getauthorname(),a)==0&&book[i].gettag()==0){if(r==0)coutsetw(6)编号setw(18)书名setw(10)作者setw(10)出版社setw(10)存量endl;e=&book[i];e-disp();r++;}if(r==0)cout找不到该书!endl;returnNULL;}Book*query4(chara[]){//按出版社查找图书Book*e;intr=0;for(inti=0;i=top;i++)if(strcmp(book[i].getcbsname(),a)==0&&book[i].gettag()==0){if(r==0)coutsetw(6)编号setw(18)书名setw(10)作者setw(10)出版社setw(10)存量endl;e=&book[i];e-disp();r++;}if(r==0)cout找不到该书!endl;returnNULL;}voidbookdata();//图书库信息voiddisp(){for(inti=0;i=top;i++)if(book[i].gettag()==0)book[i].disp();}~BDatabase(){//析构函数,将book[]写到book.txt文件中fstreamfile(book.txt,ios::out);for(inti=0;i=top;i++)if(book[i].gettag()==0)file.write((char*)&book[i],sizeof(book[i]));file.close();}};voidBDatabase::bookdata(){charchoice3;charbname[40];charauname[40];charcname[40];charch;intchoice4;intbookid;intbookod;Book*b;while(choice3!='0'){cout\n*******图书信息*******endl;cout*1.新增4.查找*endl;cout*2.更改5.显示*endl;cout*3.删除0.返回*endl;cout*************************endl;cout请选择:;cinchoice3;switch(choice3){case'1':cout请输入新书编号:;cinbookid;b=query1(bookid);if(b!=NULL){cout该编号已经存在,不能添加!endl;break;}cout请输入新书书名:;cinbname;cout请输入新书作者名:;cinauname;cout请输入新书出版社:;cincname;cout请输入新书数量:;cinbookod;addbook(bookid,bname,auname,cname,bookod);cout添加图书成功!;getch();break;case'2':cout请输入图书编号:;cinbookid;b=query1(bookid);if(b==NULL){cout该图书不存在!endl;break;}cout该图书的信息是:endl;coutsetw(6)编号setw(18)书名setw(10)作者setw(10)出版社setw(10)存量endl;b-disp();cout是否修改?(y/n):;cinch;if(ch=='y'){cout请输入新的书名:;cinbname;cout请输入新的作者:;cinauname;cout请输入新书出版社:;cincname;cout请输入新的存量:;cinbookod;b-setname(bname);b-setonshelf(bookod);}cout修改图书成功!;getch();break;case'3':cout请输入图书编号:;cinbookid;b=query1(bookid);if(b==NULL){cout该图书不存在,无法删除!endl;break;}b-delbook();cout删除成功!;getch();break;case'4':cout\n******查找图书*******endl;cout*1.按图书编号查找*endl;cout*2.按图书书名查找*endl;cout*3.按图书作者查找*endl;cout*4.按图书出版社查找*endl;cout*0.返回*endl;cout*********************endl;cout请选择:;cinchoice4;switch(choice4){case1:cout请输入图书编号:;cinbookid;b=query1(bookid);if(b==NULL){cout该图书不存在!;break;}coutsetw(6)编号setw(18)书名setw(10)作者setw(10)出版社setw(10)存量endl;b-disp();break;case2:cout请输入图书书名:;cinbname;b=query2(bname);break;case3:cout请输入图书作者:;cinauname;b=query3(auname);break;case4:cout请输入图书出版社:;cincname;b=query4(cname);break;case0:break;}break;case'5':coutsetw(6)编号setw(18)书名setw(10)作者setw(10)出版社setw(10)存量endl;disp();getch();break;case'6':clear();break;default:break;}}}classReader{//读者的信息描述private:inttag;//删除标记1表示已删0表示未删intno;//读者编号charname[10];//读者姓名intborbook[Maxbor];//所借图书public:Reader(){;}char*getname(){//获取姓名returnname;}intgettag(){//获取删除标记returntag;}intgetno(){//获取读者编号returnno;}voidsetname(charna[]){//设置姓名strcpy(name,na);}voiddelbook(){//设置删除标记1:已删0:未删tag=1;}voidaddreader(intn,char*na){//增加读者tag=0;no=n;strcpy(name,na);for(inti=0;iMaxbor;i++)borbook[i]=0;}voidborrowbook(intbookid){//借书操作for(inti=0;iMaxbor;i++){if(borbook[i]==0){borbook[i]=booki

1 / 16
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功