《图书馆管理系统(代码)》由会员分享,可在线阅读,更多相关《图书馆管理系统(代码)(12页珍藏版)》请在金锄头文库上搜索。
1、/book.h(图书类 )#ifndef _book_h_#define _bool_h_#include using namespace std;#pragma onceclass Book /图书类private:int note; /删除标记(1 :已删,0:未删)int number; /图书编号char name10; /书名int onshelf; /上架标志public:Book()char *getname(); /获得书名int getnote(); /获得删除标志int getnumber(); /获得图书编号void setname(char na); /设置图书void
2、 delbook(); /删除图书void addbook(int n,char *na); /添加图书int borrowbook(); /借书操作void retbook(); /还书操作void list(); /输出图书;#pragma once#endif/book.cpp(图书类实现)/#include #include #include stdafx.h#include book.hchar *Book:getname() return name;int Book:getnote() return note;int Book:getnumber() return number;v
3、oid Book:setname(char na) strcpy(name,na);void Book:addbook(int n,char *na) note = 0;number = n;strcpy(name,na); onshelf = 1;void Book:delbook() note = 1;int Book:borrowbook() return onshelf;void Book:retbook() onshelf = 1;void Book:list()coutusing namespace std;#pragma onceconst int Maxbor = 5; /最大
4、借阅量class Reader /读者类private:int note; /删除标记(1 :已删,0:未删)int number; /读者编号 char name10; /读者姓名int borbookMaxbor; /所借图书public:Reader() char *getname(); /获得名字 int rgetnote(); /获得删除标记int rgetnumber(); /获得读者编号void setname(char na); /设置名字void delbook(); /设置删除标记void addreader(int n,char *na); /添加读者void borro
5、wbook(int bookid); /借书操作int retbook(int bookid); /还书操作void list(); /输出读者信息;#pragma once#endif/reader.cpp(读者类实现)/#include #include stdafx.h#include reader.h/const int Maxbor = 5; /最大借阅量#include using namespace std;char *Reader:getname() return name;int Reader:rgetnote() return note;int Reader:rgetnum
6、ber() return number;void Reader:setname(char na)strcpy(name,na);void Reader:addreader(int n,char *na)note = 0;number = n;strcpy(name,na);for (int i = 0;iusing namespace std;const int Maxb=100; /最大图书数量class BDatabase /图书库类private:int top; /图书记录指针Book bookMaxb; /图书记录public:BDatabase(); /构造函数初始化:读文件voi
7、d clear(); /全部删除int addbook(int n,char *na); /添加图书Book *query(int bookid); /查找图书void list(); /输出图书信息void bookdata(); /图书库维护BDatabase(); /析构函数:写文件;#endif/bdatabase.cpp(图书信息库类实现)#include stdafx.h#include #include #include bdatabase.husing namespace std;BDatabase:BDatabase()Book s;top = -1;ifstream fil
8、e (book.dat,ios:in|ios:binary);while(1)file.read(char *) if (!file) break;top+;booktop = s;file.close();void BDatabase:clear() top = -1;Book *BDatabase:query(int bookid)for (int i = 0;i choice;coutbookid;coutbookname;addbook(bookid,bookname);break;case 2:coutbookid;b = query(bookid);if (b = NULL)cou
9、tbookname;b-setname(bookname);break;case 3:coutbookid;b = query(bookid);if (b = NULL)coutbookid;b = query(bookid);if (b = NULL)coutlist();break;case 5:list();break;case 6:break;/end switchcoutchoice; /end while/rdatabase.h(读者信息库类)#ifndef _rdatabase_h_#define _rdatabase_h_#include reader.h#include us
10、ing namespace std;const int Maxr = 100; /最大读者数class RDatabase /读者库类private:int top; /读者记录指针Reader readMaxr; /读者记录public:RDatabase(); /构造函数初始化:读文件void clear(); /删除所有读者信息int addreader(int n,char *na);/ 添加读者记录时,/先确定他是否已经存在Reader *query(int readerid); /按编号查找void list(); /输出所有读者信息void readerdata(); /读者库维
11、护RDatabase(); /析构函数:写文件;#endif/rdatabase.cpp(读者信息库类实现 )#include stdafx.h#include #include #include rdatabase.h#include reader.husing namespace std;RDatabase:RDatabase()Reader s;top = -1;/ifsteam file;/file.open(reader.dat,ios:in|ios:binary);ifstream file (book.dat,ios:in|ios:binary);while(1)file.rea
12、d(char *) if(!file) break;top+;readtop = s;file.close();void RDatabase:clear() top = -1;Reader *RDatabase:query(int readerid)for (int i = 0;i choice;coutreaderid;coutreadername;addreader(readerid,readername);break;case 2:coutreaderid;r = query(readerid);if (r = NULL)coutreadername;r-setname(readerna
13、me);break;case 3:coutreaderid;r = query(readerid);if (r = NULL)coutreaderid;r = query(readerid);if (r = NULL)coutlist();break;case 5:list();break;case 6:break;/end switchcoutchoice;/end while/library.cpp(主函数实现)#include stdafx.h#include reader.h#include rdatabase.h#include book.h#include bdatabase.h#
14、include using namespace std;int main(int argc,char *argv)int choice = 1,bookid,readerid;RDatabase ReaderDB;BDatabase BookDB;Reader *r;Book *b;coutchoice;coutreaderid;coutbookid;r = ReaderDB.query(readerid);if (r = NULL)coutborrowbook() = 0) coutborrowbook(b-getnumber();break;case 2:coutreaderid;coutbookid;r = R