欢迎来到淘文阁 - 分享文档赚钱的网站! | 帮助中心 好文档才是您的得力助手!
淘文阁 - 分享文档赚钱的网站
全部分类
  • 研究报告>
  • 管理文献>
  • 标准材料>
  • 技术资料>
  • 教育专区>
  • 应用文书>
  • 生活休闲>
  • 考试试题>
  • pptx模板>
  • 工商注册>
  • 期刊短文>
  • 图片设计>
  • ImageVerifierCode 换一换

    C 图书管理系统代码.doc

    • 资源ID:70337608       资源大小:45.50KB        全文页数:17页
    • 资源格式: DOC        下载积分:15金币
    快捷下载 游客一键下载
    会员登录下载
    微信登录下载
    三方登录下载: 微信开放平台登录   QQ登录  
    二维码
    微信扫一扫登录
    下载资源需要15金币
    邮箱/手机:
    温馨提示:
    快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。
    如填写123,账号就是123,密码也是123。
    支付方式: 支付宝    微信支付   
    验证码:   换一换

     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
    5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

    C 图书管理系统代码.doc

    #include"iostream.h"#include"conio.h"#include"fstream.h"#include"iomanip.h" #include"string.h"const 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 name; 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(name,na); strcpy(author,aa); strcpy(cbs,ca); onshelf=oa; int borrowbook() /½èÊé²Ù×÷ if (onshelf>0) onshelf-; return 1; return 0; void retbook()/»¹Êé²Ù×÷ onshelf+; void disp() /Êä³öͼÊé cout<<setw(6)<<no<<setw(18)<<name<<setw(10)<<author<<setw(10)<<cbs<<setw(10)<<onshelf<<endl; ; class BDatabase /ͼÊé¿âÀ࣬ʵÏÖ¶ÔͼÊéµÄά»¤£¬²éÕÒ£¬É¾³ýµÈ private: int top; /ͼÊé¼Ç¼ָÕëBook bookMaxb; /ͼÊé¼Ç¼public: BDatabase() /¹¹Ô캯Êý£¬½«book.txt¶Áµ½bookÖÐ 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,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) cout<<setw(6)<<"±àºÅ"<<setw(18)<<"ÊéÃû"<<setw(10)<<"×÷Õß"<<setw(10)<<"³ö°æÉç"<<setw(10)<<"´æÁ¿"<<endl; e=&booki; e->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) cout<<setw(6)<<"±àºÅ"<<setw(18)<<"ÊéÃû"<<setw(10)<<"×÷Õß"<<setw(10)<<"³ö°æÉç"<< setw(10)<<"´æÁ¿"<<endl; e=&booki; e->disp(); r+; if(r=0) cout<<"ÕÒ²»µ½¸ÃÊé!"<<endl; return NULL; Book *query4(char a) /°´³ö°æÉç²éÕÒͼÊé Book *e; int r=0; for (int i=0;i<=top;i+) if (strcmp(booki.getcbsname(),a)=0 &&booki.gettag()=0) if(r=0)cout<<setw(6)<<"±àºÅ"<<setw(18)<<"ÊéÃû"<<setw(10)<<"×÷Õß"<<setw(10)<<"³ö°æÉç"<<setw(10)<<"´æÁ¿"<<endl; e=&booki; e->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() /Îö¹¹º¯Êý£¬½«bookдµ½book.txtÎļþÖÐ fstream 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') cout<<"nttt*ͼ Êé ЊϢ*n"<<endl; cout<<"ttt* 1.РÔö *"<<endl; cout<<"ttt* 2.¸ü ¸Ä *"<<endl; cout<<"ttt* 3.ɾ ³ý *"<<endl; cout<<"ttt* 4.²é ÕÒ *"<<endl; cout<<"ttt* 5.ÏÔ Ê¾ *"<<endl; cout<<"ttt* 6.È« ɾ *"<<endl; cout<<"ttt* 0.·µ »Ø *"<<endl; cout<<"ttt ÇëÑ¡Ôñ£º" cin>>choice3; switch(choice3) case '1': cout<<"ÇëÊäÈëÐÂÊé±àºÅ:" cin>>bookid; b=query1(bookid); if(b!=NULL) cout<<"¸Ã±àºÅÒѾ­´æÔÚ£¬²»ÄÜÌí¼Ó!"<<endl; break; cout<<"ÇëÊäÈëÐÂÊéÊéÃû:" cin>>bname; cout<<"ÇëÊäÈëÐÂÊé×÷ÕßÃû:" cin>>auname; cout<<"ÇëÊäÈëÐÂÊé³ö°æÉç:" cin>>cname; cout<<"ÇëÊäÈëÐÂÊéÊýÁ¿:" cin>>bookod; addbook(bookid,bname,auname,cname,bookod); cout<<"Ìí¼ÓͼÊé³É¹¦!" getch(); break; case '2': cout<<"ÇëÊäÈëͼÊé±àºÅ:" cin>>bookid; b=query1(bookid); if(b=NULL) cout<<"¸ÃͼÊé²»´æÔÚ! "<<endl; break; cout<<"¸ÃͼÊéµÄÐÅÏ¢ÊÇ£º"<<endl; cout<<setw(6)<<"±àºÅ"<<setw(18)<<"ÊéÃû"<<setw(10)<<"×÷Õß"<<setw(10)<<"³ö°æÉç"<< setw(10)<<"´æÁ¿"<<endl; b->disp(); cout<<"ÊÇ·ñÐÞ¸Ä?( y/n ):" cin>>ch; if(ch='y') cout<<"ÇëÊäÈëеÄÊéÃû:" cin>>bname; cout<<"ÇëÊäÈëеÄ×÷Õß:" cin>>auname; cout<<"ÇëÊäÈëÐÂÊé³ö°æÉç:" cin>>cname; cout<<"ÇëÊäÈëеĴæÁ¿:" cin>>bookod; b->setname(bname); b->setonshelf(bookod); cout<<"ÐÞ¸ÄͼÊé³É¹¦!" getch(); break; case '3': cout<<"ÇëÊäÈëͼÊé±àºÅ:" cin>>bookid; b=query1(bookid); if(b=NULL) cout<<"¸ÃͼÊé²»´æÔÚ£¬ÎÞ·¨É¾³ý!"<<endl; break; b->delbook(); cout<<"ɾ³ý³É¹¦!" getch(); break; case '4': cout<<"ttt* 1.°´Í¼Êé±àºÅ²éÕÒ *"<<endl; cout<<"ttt* 2.°´Í¼ÊéÊéÃû²éÕÒ *"<<endl; cout<<"ttt* 3.°´Í¼Êé×÷Õß²éÕÒ *"<<endl; cout<<"ttt* 4.°´Í¼Êé³ö°æÉç²éÕÒ*"<<endl; cout<<"ttt* 0.·µ »Ø *"<<endl; cout<<"ttt ÇëÑ¡Ôñ:" cin>>choice4; switch(choice4) case 1: cout<<"ÇëÊäÈëͼÊé±àºÅ:" cin>>bookid; b=query1(bookid); if(b=NULL) cout<<"¸ÃͼÊé²»´æÔÚ!" break; cout<<setw(6)<<"±àºÅ"<<setw(18)<<"ÊéÃû"<<setw(10)<<"×÷Õß"<<setw(10)<<"³ö°æÉç"<<setw(10)<<"´æÁ¿"<<endl; b->disp(); break; case 2: cout<<"ÇëÊäÈëͼÊéÊéÃû:" cin>>bname; b=query2(bname); break; case 3: cout<<"ÇëÊäÈëͼÊé×÷Õß:" cin>>auname; b=query3(auname); break; case 4: cout<<"ÇëÊäÈëͼÊé³ö°æÉç:" cin>>cname; b=query4(cname); break; case 0: break; break; case '5': cout<<setw(6)<<"±àºÅ"<<setw(18)<<"ÊéÃû"<<setw(10)<<"×÷Õß"<<setw(10)<<"³ö°æÉç"<< setw(10)<<"´æÁ¿"<<endl; disp(); getch(); break; case '6': clear(); break; default: break; 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; no=n; strcpy(name,na); for(int i=0;i<Maxbor;i+) borbooki=0; void borrowbook(int bookid) /½èÊé²Ù×÷ for(int i=0;i<Maxbor;i+) if (borbooki=0) borbooki=bookid; return ; int retbook(int bookid) /»¹Êé²Ù×÷ for(int i=0;i<Maxbor;i+) if(borbooki=bookid) borbooki=0; cout<<"»¹Êé³É¹¦!"<<endl; return 1; cout<<"δ½è¸ÃÊ飬»¹Êéʧ°Ü!"<<endl; return 0; void disp() /¶Á³ö¶ÁÕßÐÅÏ¢ int have=0; int bz=0; cout<<setw(5)<<no<<setw(21)<<name<<setw(15); for(int i=0;i<Maxbor;i+) if(borbooki!=0) if(bz=0) have=1; cout<<""<<borbooki<<"tt"<<endl; bz+; else cout<<"rttttt"""<<borbooki<<"tt"<<setw(15)<<endl; if(have=0) cout<<"t »¹Î´½èÊé"<<endl;class RDatabase /¶ÁÕßÀà¿â£¬ÊµÏÖ½¨Á¢¶ÁÕߵĸöÈË×ÊÁÏ private: int top; /¶ÁÕ߼ǼָÕë Reader readMaxr; /¶ÁÕ߼Ǽ public: RDatabase() /¹¹Ô캯Êý£¬½«reader.txt¶Áµ½readÖÐ Reader s; top=-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; Reader *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<=top;i+) readi.disp(); void readerdata(); /¶ÁÕß¿âÐÅÏ¢RDatabase() /Îö¹¹º¯Êý£¬½«readдµ½reader.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 choice2;Reader *r; while(choice1!='0') cout<<"nttt* ¶Á Õß ÐŠϢ *n"<<endl; cout<<"ttt* 1.РÔö *"<<endl; cout<<"ttt* 2.¸ü ¸Ä *"<<endl; cout<<"ttt* 3.ɾ ³ý *"<<endl; cout<<"ttt* 4.²é ÕÒ *"<<endl; cout<<"ttt* 5.ÏÔ Ê¾ *"<<endl; cout<<"ttt* 6.È« ɾ *"<<endl; cout<<"ttt* 0.·µ »Ø *"<<endl; cout<<"ttt ÇëÑ¡Ôñ£º" cin>>choice1; switch(choice1) case '1': cout<<"ÇëÊäÈë¶ÁÕß±àºÅ:" cin>>readerid; cout<<"ÇëÊäÈë¶ÁÕßÐÕÃû:" cin>>rname; addreader(readerid,rname); cout<<"Ìí¼Ó¶ÁÕ߳ɹ¦!"<<endl; getch(); break; case '2': cout<<"ÇëÊäÈë¶ÁÕß±àºÅ:" cin>>readerid; r=queryid(readerid); if(r=NULL) cout<<"¸Ã¶ÁÕß²»´æÔÚ! "<<endl; break; cout<<"ÇëÊäÈëеÄÐÕÃû:" cin>>rname; r->setname(rname); cout<<"Ð޸ĶÁÕ߳ɹ¦!"<<endl; getch(); break; case '3': cout<<"ÇëÊäÈë¶ÁÕß±àºÅ:" cin>>readerid; r=queryid(readerid); if(r=NULL) cout<<"¸Ã¶ÁÕß²»´æÔÚ!" << endl; break; r->delbook(); cout<<"ɾ³ý³É¹¦!"<<endl; getch(); break; case '4': cout<<"ttt* 1.°´¶ÁÕß±àºÅ²éÕÒ *"<<endl; cout<<"ttt* 2.°´¶ÁÕßÐÕÃû²éÕÒ *"<<endl; cout<<"ttt* 0.·µ »Ø *"<<endl; cout<<"ttt ÇëÑ¡Ôñ:" cin>>choice2; switch(choice2) case 1: cout<<"ÇëÊäÈë¶ÁÕß±àºÅ:" cin>>readerid; r=queryid(readerid); if(r=NULL) cout<<"¸Ã¶ÁÕß²»´æÔÚ!"<< endl; break; cout<<setw(10)<<"¶ÁÕß±àºÅ"<<setw(17)<<"¶ÁÕßÐÕÃû"<<setw(20)<<"ÒѽèÊé±àºÅ"<<endl; r->disp(); break; case 2: cout<<"ÇëÊäÈë¶ÁÕßÐÕÃû:" cin>>readername; r=queryname(readername); if(r=NULL) cout<<"¸Ã¶ÁÕß²»´æÔÚ!"<<endl; break; cout<<setw(10)<<"¶ÁÕß±àºÅ"<<setw(17)<<"¶ÁÕßÐÕÃû"<<setw(20)<<"ÒѽèÊé±àºÅ"<<endl; r->disp(); break; case 0: break; break; case '5': cout<<setw(10)<<"¶ÁÕß±àºÅ"<<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;cout<<"ttt »¶Ó­¹âÁÙͼÊé¹Ý¹ÜÀíϵͳ!"<<endl;while(choice5!='0') cout<<"nttt* ͼ Êé ¹Ü Àí ϵ ͳ*nn" cout<<"ttt* 1.ͼ Êé ЊϢ *"<<endl; cout<<"ttt* 2.¶Á Õß ÐŠϢ *"<<endl; cout<<"ttt* 3.½è ÔÄ Í¼ Êé *"<<endl; cout<<"ttt* 4.¹é »¹ ͼ Êé *"<<endl; cout<<"ttt* 0.ÍË ³ö *"<<endl; cout<<"ttt ÇëÑ¡Ôñ£º" cin>>choice5; switch (choice5) case '1': BookDB.bookdata(); break; case '2': ReaderDB.readerdata(); break; case '3': cout<<"tttt½èÊé²Ù×÷"<<endl; cout<<"ÇëÊäÈë½èÊé¶ÁÕß±àºÅ:" cin>>readerid; r=ReaderDB.queryid(readerid); if(NULL=r) /°´±àºÅ²éÕÒÊÇ·ñÓиöÁÕß cout<<"²»´æÔڸöÁÕߣ¬²»ÄܽèÊé!"<<endl; break; cout<<"ÇëÊäÈëÒª½èͼÊé±àºÅ:" cin>>bookid; b=BookDB.query1(bookid); if(b=NULL) /°´±àºÅ²éÕÒÊÇ·ñÓиÃͼÊé cout<<"²»´æÔÚ¸ÃͼÊ飬²»ÄܽèÊé!"<<endl; break; if(b->borrowbook()=0) cout<<"¸ÃͼÊéÒѽèÍ꣬²»ÄܽèÊé!"<<endl; break; cout<<"¶ÁÕß½èÊé³É¹¦!"<<endl; r->borrowbook(b->getno(); break; case '4': cout<<"tttt»¹Êé²Ù×÷"<<endl; cout<<"ÇëÊäÈ뻹Êé¶ÁÕß±àºÅ:" cin>>readerid; r=ReaderDB.queryid(readerid); if(r=NULL) cout<<"²»´æÔڸöÁÕߣ¬²»ÄÜ»¹Êé"<<endl; break; cout<<"ÇëÊäÈëÒª¹é»¹Í¼Êé±àºÅ:" cin>>bookid; b=BookDB.query1(bookid); if(b=NULL) cout<<"²»´æÔÚ¸ÃͼÊ飬²»ÄÜ»¹Êé"<<endl; break; b->retbook(); r->retbook(b->getno(); br

    注意事项

    本文(C 图书管理系统代码.doc)为本站会员(asd****56)主动上传,淘文阁 - 分享文档赚钱的网站仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知淘文阁 - 分享文档赚钱的网站(点击联系客服),我们立即给予删除!

    温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载不扣分。




    关于淘文阁 - 版权申诉 - 用户使用规则 - 积分规则 - 联系我们

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

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

    收起
    展开