C 图书管理系统代码.doc

上传人:asd****56 文档编号:70337608 上传时间:2023-01-19 格式:DOC 页数:17 大小:45.50KB
返回 下载 相关 举报
C 图书管理系统代码.doc_第1页
第1页 / 共17页
C 图书管理系统代码.doc_第2页
第2页 / 共17页
点击查看更多>>
资源描述

《C 图书管理系统代码.doc》由会员分享,可在线阅读,更多相关《C 图书管理系统代码.doc(17页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。

1、#includeiostream.h#includeconio.h#includefstream.h#includeiomanip.h #includestring.hconst 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; /int onshelf; / 1: 2: public: Book(); char *getname()/ return na

2、me; char *getauthorname() / return author; char *getcbsname()/ return cbs; int getno()/ return no; int gettag()/ return tag; void setname(char na) / strcpy(name,na); void setonshelf(int oa) onshelf=oa; void delbook()/ tag=1; void addbook(int n,char *na,char *aa,char *ca,int oa) / tag=0; no=n; strcpy

3、(name,na); strcpy(author,aa); strcpy(cbs,ca); onshelf=oa; int borrowbook() / if (onshelf0) onshelf-; return 1; return 0; void retbook()/ onshelf+; void disp() / coutsetw(6)nosetw(18)namesetw(10)authorsetw(10)cbssetw(10)onshelfendl; ; class BDatabase / private: int top; /Book bookMaxb; /public: BData

4、base() /book.txtbook Book b; top=-1; fstream file(book.txt,ios:in); while (1) file.read(char *)&b,sizeof(b); if (!file) break; top+; booktop=b; file.close(); void clear() / top=-1; int addbook(int n,char *na,char *aa,char *ca,int oa) / Book *p=query1(n); if (NULL=p) top+; booktop.addbook(n,na,aa,ca,

5、oa); return 1; return 0; Book *query1(int bookid) / for(int i=0;i=top;i+) if(booki.getno()=bookid &booki.gettag()=0) return &booki; return NULL; Book *query2(char a) / Book *e; int r=0; for(int i=0;i=top;i+) if(strcmp(booki.getname(),a)=0 &booki.gettag()=0) if(r=0) coutsetw(6)setw(18)setw(10)setw(10

6、)setw(10)disp(); r+; if(r=0) cout!endl; return NULL; Book *query3(char a) / Book *e; int r=0; for(int i=0;i=top;i+) if(strcmp(booki.getauthorname(),a)=0 &booki.gettag()=0) if(r=0) coutsetw(6)setw(18)setw(10)setw(10) setw(10)disp(); r+; if(r=0) cout!endl; return NULL; Book *query4(char a) / Book *e;

7、int r=0; for (int i=0;i=top;i+) if (strcmp(booki.getcbsname(),a)=0 &booki.gettag()=0) if(r=0)coutsetw(6)setw(18)setw(10)setw(10)setw(10)disp(); r+; if(r=0) cout!endl; return NULL; void bookdata(); /void disp() for(int i=0;i=top;i+) if(booki.gettag()=0) booki.disp(); BDatabase() /bookbook.txt fstream

8、 file(book.txt,ios:out); for(int i=0;i=top;i+) if(booki.gettag()=0) file.write(char *)&booki,sizeof(booki); file.close(); ; void BDatabase:bookdata() char choice3; char bname40;char auname40;char cname40;char ch;int choice4;int bookid;int bookod;Book *b; while (choice3!=0) coutnttt* *nendl; coutttt*

9、 1. *endl; coutttt* 2. *endl; coutttt* 3. *endl; coutttt* 4. *endl; coutttt* 5. *endl; coutttt* 6. *endl; coutttt* 0. *endl; coutchoice3; switch(choice3) case 1: coutbookid; b=query1(bookid); if(b!=NULL) cout!endl; break; coutbname; coutauname; coutcname; coutbookod; addbook(bookid,bname,auname,cnam

10、e,bookod); cout!; getch(); break; case 2: coutbookid; b=query1(bookid); if(b=NULL) cout! endl; break; coutendl; coutsetw(6)setw(18)setw(10)setw(10) setw(10)disp(); coutch; if(ch=y) coutbname; coutauname; coutcname; coutbookod; b-setname(bname); b-setonshelf(bookod); cout!; getch(); break; case 3: co

11、utbookid; b=query1(bookid); if(b=NULL) cout!delbook(); cout!; getch(); break; case 4: coutttt* 1. *endl; coutttt* 2. *endl; coutttt* 3. *endl; coutttt* 4.*endl; coutttt* 0. *endl; coutchoice4; switch(choice4) case 1: coutbookid; b=query1(bookid); if(b=NULL) cout!; break; coutsetw(6)setw(18)setw(10)s

12、etw(10)setw(10)disp(); break; case 2: coutbname; b=query2(bname); break; case 3: coutauname; b=query3(auname); break; case 4: coutcname; b=query4(cname); break; case 0: break; break; case 5: coutsetw(6)setw(18)setw(10)setw(10) setw(10)endl; disp(); getch(); break; case 6: clear(); break; default: br

13、eak; class Reader/ private: int tag; / 1 0 int no; /char name10; / int borbookMaxbor; / public: Reader() ; char *getname() / return name; int gettag() / return tag; int getno() / return no; void setname(char na) / strcpy(name,na); void delbook() / 1: 0: tag=1; void addreader(int n,char *na) / tag=0;

14、 no=n; strcpy(name,na); for(int i=0;iMaxbor;i+) borbooki=0; void borrowbook(int bookid) / for(int i=0;iMaxbor;i+) if (borbooki=0) borbooki=bookid; return ; int retbook(int bookid) / for(int i=0;iMaxbor;i+) if(borbooki=bookid) borbooki=0; cout!endl; return 1; cout!endl; return 0; void disp() / int ha

15、ve=0; int bz=0; coutsetw(5)nosetw(21)namesetw(15); for(int i=0;iMaxbor;i+) if(borbooki!=0) if(bz=0) have=1; coutborbookittendl; bz+; else coutrtttttborbookittsetw(15)endl; if(have=0) coutt endl;class RDatabase / private: int top; / Reader readMaxr; / public: RDatabase() /reader.txtread Reader s; top

16、=-1; fstream file(reader.txt,ios:in); / while (1) file.read(char *)&s,sizeof(s); if (!file) break; top+; readtop=s; file.close(); / reader.txt void clear() / top=-1; int addreader(int n,char *na) / Reader *p=queryid(n); if (p=NULL) top+; readtop.addreader(n,na); return 1; else cout!; return 0; Reade

17、r *queryid(int readerid) / for (int i=0;i=top;i+) if (readi.getno()=readerid&readi.gettag()=0) return &readi; return NULL;Reader *queryname(char readername10) / for (int i=0;i=top;i+) if (strcmp(readi.getname(),readername)=0 & readi.gettag()=0) return &readi; return NULL; void disp() / for(int i=0;i

18、=top;i+) readi.disp(); void readerdata(); /RDatabase() /readreader.txt fstream file(reader.txt,ios:out); for (int i=0;i=top;i+) if (readi.gettag()=0) file.write(char *)&readi,sizeof(readi); file.close(); ;void RDatabase:readerdata() char choice1; char rname20; int readerid;char readername10;int choi

19、ce2;Reader *r; while(choice1!=0) coutnttt* *nendl; coutttt* 1. *endl; coutttt* 2. *endl; coutttt* 3. *endl; coutttt* 4. *endl; coutttt* 5. *endl; coutttt* 6. *endl; coutttt* 0. *endl; coutchoice1; switch(choice1) case 1: coutreaderid; coutrname; addreader(readerid,rname); cout!endl; getch(); break;

20、case 2: coutreaderid; r=queryid(readerid); if(r=NULL) cout! endl; break; coutrname; r-setname(rname); cout!endl; getch(); break; case 3: coutreaderid; r=queryid(readerid); if(r=NULL) cout! delbook(); cout!endl; getch(); break; case 4: coutttt* 1. *endl; coutttt* 2. *endl; coutttt* 0. *endl; coutchoi

21、ce2; switch(choice2) case 1: coutreaderid; r=queryid(readerid); if(r=NULL) cout! endl; break; coutsetw(10)setw(17)setw(20)disp(); break; case 2: coutreadername; r=queryname(readername); if(r=NULL) cout!endl; break; coutsetw(10)setw(17)setw(20)disp(); break; case 0: break; break; case 5: coutsetw(10)

22、setw(17)setw(20)endl; disp(); getch(); break; case 6: clear(); break; default: break; void main() / char choice5; int bookid,readerid; RDatabase ReaderDB; Reader *r; BDatabase BookDB; Book *b;coutttt !endl;while(choice5!=0) coutnttt* *nn; coutttt* 1. *endl; coutttt* 2. *endl; coutttt* 3. *endl; cout

23、ttt* 4. *endl; coutttt* 0. *endl; coutchoice5; switch (choice5) case 1: BookDB.bookdata(); break; case 2: ReaderDB.readerdata(); break; case 3: coutttttendl; coutreaderid; r=ReaderDB.queryid(readerid); if(NULL=r) / cout!endl; break; coutbookid; b=BookDB.query1(bookid); if(b=NULL) / cout!borrowbook()=0) cout!endl; break; cout!borrowbook(b-getno(); break; case 4: coutttttendl; coutreaderid; r=ReaderDB.queryid(readerid); if(r=NULL) coutendl; break; coutbookid; b=BookDB.query1(bookid); if(b=NULL) coutretbook(); r-retbook(b-getno(); br

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 技术资料 > 其他杂项

本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知淘文阁网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

工信部备案号:黑ICP备15003705号© 2020-2023 www.taowenge.com 淘文阁