1、#include#include /控制台数 据输入输出的函数#include/文件流#include /控制数据 输出格式#includeconst int Maxr=100 ;/最多的 读者数 const int Maxb=100; /最多的图书数const int Maxbor=5; /每位读者 最多借的书class Book /图书类,实现对图书的描述, 图书的分类号,书名, 借出,还入等功能private: int tag; /删除标记 1:已删 0:未删int no; /图书分类号char name20; /书名 char author20;/作者char cbs20; /出版社i
2、nt cbtime;/出 版时间double bookprice;/图书价格int onshelf; /是否再架 1:再架 2:已借 public: Book(); char *getname()/获取书名return name; char *getauthorname() /获 取作者名return author; char *getcbsname()/获取出版社名 return cbs; int getcbtime()/获 取出版时间return cbtime;double getbookprice()/获 取图书价格return bookprice;int getno()/获取图书分类号
3、return no; int gettag()/获取删除标记 return tag; void setname(char na) /设置书名strcpy(name,na); void setauthorname(char aa)/设置作者名strcpy(author,aa);void setcbs(char ca)/设置出版社strcpy(cbs,ca);void setcbtime(int time) /设置时间cbtime=time; void setbookprice(double price)/设置图书价格bookprice=price;void setonshelf(int oa)
4、onshelf=oa; void delbook()/删除图书char i;couti;if(i=y|i=Y)tag=1; void addbook(int n,char *na,char *aa,char *ca,int time,double price,int oa) /增加图书 tag=0; no=n; strcpy(name,na);strcpy(author,aa);strcpy(cbs,ca);cbtime=time;bookprice=price;onshelf=oa; int borrowbook() /借书操作 if (onshelf0) onshelf-;return 1
5、; return 0; void retbook()/还书操作onshelf+; void disp() /输出图书 couti;if(i=y|i=Y)top=-1; int addbook(int n,char *na,char *aa,char *ca,int time, double price,int oa) /增加图书 Book *p=query1(n); if (NULL=p) top+; booktop.addbook(n,na,aa,ca,time,price,oa); return 1; return 0; Book *query1(int bookid) /按分类号查找图书
6、 for(int i=0;idisp();r+; if(r=0)coutdisp();r+; if(r=0)coutdisp();r+; if(r=0)coutchoice3; switch(choice3) case 1: coutbookid;b=query1(bookid); if(b!=NULL) coutbname;coutauname;coutcname;couttime;coutprice;coutbookod;addbook(bookid,bname,auname,cname,time,price,bookod);coutbookid; b=query1(bookid); if
7、(b=NULL) coutdisp();coutch;if(ch=y|ch=Y)int a;couta; switch(a)case 1: coutbname; b-setname(bname); break;case 2: coutauname; b-setauthorname(auname); break;case 3: coutcname; b-setcbs(cname); break;case 4: couttime;b-setcbtime(time); break;case 5: coutprice; b-setbookprice(price); break;case 6: cout
8、bookod; b-setonshelf(bookod); break;case 0: break;coutbookid; b=query1(bookid); if(b=NULL) coutdelbook();coutchoice4;switch(choice4)case 1: coutbookid;b=query1(bookid);if(b=NULL) coutdisp(); break; case 2: coutbname;b=query2(bname);break;case 3: coutauname;b=query3(auname);break;case 4: coutcname;b=
9、query4(cname);break;case 0: break;break;case 5: couti;if(i=y|i=Y)tag=1; void addreader(int n,char *na) /增加读者 tag=0; no=n; strcpy(name,na); for(int i=0;ii;if(i=y|i=Y)top=-1; int addreader(int n,char *na) /添加读者时先查找是否存在 Reader *p=queryid(n); if (p=NULL)top+; readtop.addreader(n,na); return 1; elsecoutc
10、hoice1; switch(choice1) case 1: coutreaderid;coutrname;addreader(readerid,rname);coutreaderid; r=queryid(readerid); if(r=NULL) coutrname; r-setname(rname); coutreaderid; r=queryid(readerid); if(r=NULL) coutdelbook();coutchoice2;switch(choice2)case 1: coutreaderid;r=queryid(readerid); if(r=NULL) cout
11、disp();break; case 2: coutreadername; r=queryname(readername); if(r=NULL) coutdisp();break;case 0: break;break;case 5:coutchoice5; switch (choice5) case 1: BookDB.bookdata(); break; case 2: ReaderDB.readerdata(); break; case 3:coutreaderid;r=ReaderDB.queryid(readerid); if(NULL=r) /按分类号查找是否有该 读者 cout
12、bookid; b=BookDB.query1(bookid); if(b=NULL) /按分类号查找是否有该图 书 coutborrowbook()=0) coutborrowbook(b-getno();break; case 4: coutreaderid;r=ReaderDB.queryid(readerid);if(r=NULL) coutbookid; b=BookDB.query1(bookid); if(b=NULL) coutretbook(); r-retbook(b-getno();break; default: break; ;void main() /主函数maindesk yourDesk;yourDesk.enterdesk();cout“ttGAME OVER !“endl;