图书信息管理系统.docx
- 文档编号:27128728
- 上传时间:2023-06-27
- 格式:DOCX
- 页数:20
- 大小:18.68KB
图书信息管理系统.docx
《图书信息管理系统.docx》由会员分享,可在线阅读,更多相关《图书信息管理系统.docx(20页珍藏版)》请在冰豆网上搜索。
图书信息管理系统
图书信息包括:
登录号、书名、作者名、分类号、出版单位、出版时间、价格等。
试设计一图书信息管理系统,使之能提供以下功能:
系统以菜单方式工作?
图书信息录入功能(图书信息用文件保存)--输入?
图书信息浏览功能--输出?
查询和排序功能:
(至少一种查询方式)--算法?
?
按书名查询
?
按作者名查询
图书信息的删除与修改(可选项)
#include
#include
#include
#include
structbookData
{
intbooknumber;
charbookname[30];
intstore;
};
structPerson
{
charname[20];
charstudynumber[10];
intcount;
bookDataRbook[2];
//bookDataRbook;
};
classHistory
{
public:
History(fstream&a){readerbook=a;}
voidwritehistory();
voidreadhistory(fstream&);
private:
fstreamreaderbook;
};
classLiberian;
voidFind(fstream&);
voidCreateTxt(fstream&);
classReader
{
friendLiberian;
public:
Reader(fstream&);
voidprint();
voidhandlebook(fstream&);
voidchange();
boolfindreader();
voidAddreader();
voiddeletereader();
private:
fstreamfile;
Personperson;
};
classLiberian
{
public:
Liberian(char*,char*);
voidchangeReader(Reader&);
voidselfprint();
voidAppend(fstream&);
private:
charworkname[20];
charworknumber[20];
};
intmain()
{
fstreambookRecord("book.dat",ios:
:
in|ios:
:
out);
if(!
bookRecord)
{
cerr<<"Can'topen,tryagain!
"< exit (1); } fstreamreaderRecord("reader.dat",ios: : in|ios: : out); if(! readerRecord) { cerr<<"Can'topen,tryagain! "< exit (1); } intchoice; intkey;Readerreader(readerRecord);//读者管理系统 Liberianliberian("李天","123456");//图书管理员 Historyrec(readerRecord);//声明显示历史记录类 while (1) { cout<<"请输入您的选择: \n\n" <<"1--图书管理员\n" <<"2--读者系统\n" <<"0--结束程序\n"; cin>>choice; switch(choice) { case1: { cout<<"Hello,图书管理员: \n"; liberian.selfprint();cout< cout<<"1--增加新图书\n" <<"2--改变读者的属性\n" <<"3--显示历史记录\n" <<"0--返回\n"; cin>>key; switch(key) { case1: liberian.Append(bookRecord); break; case2: liberian.changeReader(reader); break; case3: rec.readhistory(readerRecord); case0: break; } } break; case2: { cout<<"学生读者\n";intiflag=1; //reader.findreader(); cout<<"1--借书与还书信息\n" <<"2--修改个人信息\n" <<"0--返回\n"; cin>>key; switch(key) { case1: reader.handlebook(bookRecord); break; case2: reader.change(); break; case0: break; } } break; default: return0; } } return0; } //增加书籍 voidLiberian: : Append(fstream&storef) { bookDatabook; intchoice; intkey; intnum; storef.seekp(0,ios: : end); intposEnd=storef.tellp(); cout<<"*************书籍入库***************"< while (1) { cout<<"Pleaseenteryourchoice: "< cout<<"1--添加新书\n"<<"2--已有书籍\n"<<"0--返回\n"; cin>>choice; switch(choice) { case1: cout<<"书号,书名,数量? "< cin>>book.booknumber>>book.bookname>>book.store; storef.write(reinterpret_cast break; case2: storef.seekg(0,ios: : beg); cout<<"Booknumber? \n"; cin>>key; do{ storef.read(reinterpret_cast }while(book.booknumber! =key&&storef.tellg()! =posEnd); if(book.booknumber==key) { cout< cout<<"输入已有书增加的数量: "< cin>>num; if(num>0) book.store+=num; else { cout<<"Invalidinput"< } storef.seekp(-long(sizeof(bookData)),ios: : cur);//////////////////// storef.write(reinterpret_cast cout<<"现在书籍: "< "< } else cout<<"找不到此书,请重新查阅书号是否正确! "< break; case0: return; } } } //书籍查询 voidFind(fstream&f) { bookDatabook; intkey; intchoice; f.seekg(0,ios: : end); intposEnd=f.tellp(); cout<<"*************书籍查询***************"< while (1) { cout<<"请输入您的选择\n" <<"1--检索一本书\n" <<"2--显示全部书籍\n" <<"0--返回\n"; cin>>choice; switch(choice) { case1: f.seekg(0,ios: : beg); cout<<"输入你想检索书的书号"< cin>>key; do{ f.read(reinterpret_cast }while(book.booknumber! =key&&f.tellg()! =posEnd); if(book.booknumber==key) cout< else cout<<"找不到此书,请重新确认! "< break; case2: f.seekg(0,ios: : beg); do{ f.read(reinterpret_cast cout< }while(f.tellg()! =posEnd); break; case0: return; } } } Reader: : Reader(fstream&c) { file=c; Personperson={"0","0",0,{{0,"0",0},{0,"0",0}}}; } voidReader: : print() { cout<<"Name"<<"---"< } //操作书籍? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? voidReader: : handlebook(fstream&filee) { intkey;intchoice; bookDatabook;booliflag;intnum=0; filee.seekp(0,ios: : end); intposEnd=filee.tellp(); while(! (iflag=findreader())) { num++; if(num>=3) return; } //cout< while (1) { cout<<"1--借书\n" <<"2--还书\n" <<"3--查找一本书\n" <<"0--返回"<<'\n'; cin>>choice; switch(choice) { case1: { filee.seekp(0,ios: : end); intposEnd=filee.tellp(); if(person.count<=1) { cout<<"输入你要借阅图书的书号: "< cin>>key; filee.seekg(0); do{ filee.read(reinterpret_cast }while(book.booknumber! =key&&filee.tellp()! =posEnd); //cout< if(book.booknumber==key) { //cout<<"找到你想借阅的图书,成功借阅! "< if(book.store>0) { person.Rbook[person.count]=book; person.count+=1; book.store-=1; filee.seekp(-long(sizeof(bookData)),ios: : cur); filee.write(reinterpret_cast cout<<"找到你想借阅的图书,成功借阅! "< cout<<"书籍: "< "< } else cout<<"现在此图书已经被借完了,请耐心等待几天! "< } else cout<<"找不到你想要的图书"< } else cout<<"你最多只能借2本\n\n"; } break; case2: { bookDatablankbook={0,"0",0}; //if(person.count>0) //{ intiflag=0; filee.seekg(0); cout<<"输入你想要还的书的书号: "< cin>>key; for(inti=0;i<2;i++) { if(key==person.Rbook[i].booknumber) { person.Rbook[i]=blankbook; cout<<"成功归还此书! "; iflag=1; person.count--; do{ filee.read(reinterpret_cast }while(book.booknumber! =key&&filee.tellp()! =posEnd); if(book.booknumber==key) { book.store+=1; filee.seekp(-long(sizeof(bookData)),ios: : cur); filee.write(reinterpret_cast cout<<"书籍: "< "< } } } if(! iflag) { cout<<"你没有借阅那本书,请确认! "< } //} //else //cout<<"你没有借书,请重新确认! \n\n"; } break; case3: Find(filee); break; case0: return; } } } voidReader: : change() { charnewname[20];charnewnumber[10]; intchoice; file.seekp(0,ios: : cur); intPosend=file.tellp();booliflag;intnum=0; while(! (iflag=findreader())) { num++; if(num>=3) return; } cout<<"请输入你的选择! "< cout<<"1--改变名字! \n" <<"2--修改学号r\n" <<"0--返回\n"; cin>>choice; switch(choice) { case1: cout<<"输入你的新名字! \n"; cin>>newname; strcpy(person.name,newname); break; case2: cout<<"输入你的信学号? \n"; cin>>newnumber; strcpy(person.studynumber,newnumber); break; default: break;; } file.seekp(-long(sizeof(Person)),ios: : cur); file.write(reinterpret_cast cout<<"信息修改成功! "< } voidLiberian: : selfprint() { cout<<"图书管理员: \n" < \n"; } Liberian: : Liberian(char*a,char*b) { strcpy(workname,a); strcpy(worknumber,b); } voidLiberian: : changeReader(Reader&a) { intchoice;charnewname[20];charnewnumber[10]; cout<<"修改读者的数据信息! \n"; cout<<"1--增加一个读者\n" <<"2--删除一个读者\n" <<"0--结束程序\n"; cin>>choice; switch(choice) { case1: a.Addreader(); break; case2: a.deletereader(); break; case0: return; } } voidReader: : Addreader() { Persontemp;bookDatabook={0,"0",0}; file.seekp(0,ios: : end); intPosend=file.tellp(); cout<<"输入你想要增加的读者的名字"< cin>>temp.name; cout<<"新读者的学号: "< cin>>temp.studynumber; temp.Rbook[1]=book;temp.Rbook[0]=book;temp.count=0; file.write(reinterpret_cast cout<<"成功添加! "< } voidReader: : deletereader() { file.seekp(0,ios: : end); intPosend=file.tellp(); Personperson; charname[20]; cout<<"输入要删除的读者的名字! "< cin>>name; file.seekg(0); do{ file.read(reinterpret_cast }while(strcmp(name,person.name)&&file.tellp()! =Posend); if(! strcmp(name,person.name)) { bookDatablankbook={0,"0",0}; Personguest={"0","0",0,{{0,"0",0},{0,"0",0}}}; file.seekp(-long(sizeof(Person)),ios: : cur); file.write(reinterpret_cast cout<<"成功删除! "< } else cout<<"查无此人! "< } boolReader: : findreader() { file.seekp(0,ios: : end); intPosend=file.tellp(); charname[20]; Personguest={"0","0",0,{{0,"0",0},{0,"0",0}}}; cout<<"输入查找人的名字! "; cin>>name; file.seekg(0); do{ file.read(reinterpret_cast }while(strcmp(name,person.name)&&file.tellp()! =Posend); if(! strcmp(name,person.name)) { cout<<"查到此人: "< returntrue; } else { cout<<"找不到此人,请重新确认! "< returnfalse; } } //借阅历史 voidHistory: : readhistory(fstream&a) { readerbook=a; charname[10]="0"; readerbook.seekp(0,ios: : end); intPosend=readerbook.tellp(); Personguest;intiflag=1; cout<<"书籍借阅信息如下: "< cout<<"姓名学号借书量书籍名"< readerbook.seekg(0,ios: : beg); do{ readerbook.read(reinterpret_cast if(strcmp(guest.Rbook[1].bookname,name)||strcmp(guest.Rbook[1].bookname,name)) { cout< for(inti=0;i<2;i++) if(st
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 图书 信息管理 系统
![提示](https://static.bdocx.com/images/bang_tan.gif)