1、图书管理系统实现代码c+语言 图书管理系统代码(供大家参考)/* * Name : Bookmanage.h * Author: 彭天越 * Description: Bookmanage类的声明,用来实现管理图书的相关功能 * Date:2012-4-032012-4-12 * Copyright: HNS University */#pragma once#include#include#include Book.husing namespace std;class Bookmanage private: vectorbooks;/*声明一个存放Book类的向量,用于数据操作*/ int
2、count; public: Bookmanage(void); void addBooks();/*图书的添加函数*/ void findBook(); void lendbook(); void returnbook(); void changbook();/*修改书籍的相关信息*/ Bookmanage(void);/* * Name : Book.h * Author: 彭天越 * Description: Book类的定义 * Date:2012-4-022012-4-10 * Copyright: HNS University */#include Book.h#include#i
3、ncludeusing namespace std;Book:Book(string newname,string newnum,string newwri,string newpub,int state)/*构造函数重载的定义*/ BookName=newname; Booknum=newnum; Writer=newwri; Publisher=newpub; Bookstate=state;void Book:displayInfo()const cout图书的名字是tBookNameendl; cout图书的书号是tBooknumendl; cout图书的作者tWriterendl;
4、cout图书的出版社tPublisherendl; if(Bookstate=0) cout 在馆 endl; else cout 已借出 endl; cin.get();void Book:setname(string newname) BookName=newname; void Book:setnum(string newnum) Booknum=newnum; void Book:setwriter(string newwri) Writer=newwri;void Book:setpub(string newpub) Publisher=newpub;string Book:getn
5、ame() return BookName;string Book:getnum() return Booknum;string Book:getwriter() return Writer;string Book:getpub() return Publisher;void Book:setstate(int state) Bookstate=state;void Book:Borrowbooks() Bookstate=LENDSTATUE;void Book:returnbooks() Bookstate=NORMALSTATUE;int Book:getstate() return B
6、ookstate;Book:Book(void)/* * Name : Bookmanage.h * Author: 彭天越 * Description: Bookmanage类的声明,用来实现管理图书的相关功能 * Date:2012-4-032012-4-12 * Copyright: HNS University */#pragma once#include#include#include Book.husing namespace std;class Bookmanage private: vectorbooks;/*声明一个存放Book类的向量,用于数据操作*/ int count;
7、 public: Bookmanage(void); void addBooks();/*图书的添加函数*/ void findBook(); void lendbook(); void returnbook(); void changbook();/*修改书籍的相关信息*/ Bookmanage(void);/* * Name : Bookmanage.cpp * Author: 彭天越 * Description: Bookmanage类的声明,用来实现管理图书的相关功能 * Date:2012-4-032012-4-7,2012-5-28进行修改添加tag * Copyright: HN
8、S University */#include Bookmanage.h#include Book.h#include#include#includeusing namespace std;/*实现将books.txt文本文件中的book读取到vector向量中,以便对图书的相关操作*/Bookmanage:Bookmanage(void) count =0; ifstream fin(books.txt); while(true) string name; string number; string writer; string publisher; int state; if(fin.eo
9、f()break; finnamenumberwriterpublisherstate; if(name!=) Book book(name,number,writer,publisher,state); books.push_back(book); count +;/*用来获得文件中所存放的book的数目*/ fin.close(); void Bookmanage:addBooks() string name; string number; string writer; string publisher; coutt*请输入图书的书名*name; cin.get(); coutt*请输入图
10、书的书号ISBN*number; cin.get(); coutt*请输入图书的作者*writer; cin.get(); coutt*请输入图书的出版社*publisher; cin.get(); coutt*确定输入的信息是否正确,Y/N*k; if(k=Y) Book book(name,number,writer,publisher,0); books.push_back(book);/*将book存放push_back到books向量中*/ count +; coutt*添加图书成功,此本书为图书馆中的第 count 本书*endl; else coutt*添加图书失败*endl;/
11、*实现查找图书的功能*/void Bookmanage:findBook() char choice; string want; int i; int tag;/*标记以便确认是否查找到图书*/ coutt*选择您要查找图书的方式* endla:t书名tb:tISBMtc:t书名作者td:t出版社choice; cin.get(); switch(choice) case a: coutt*请输入图书的书名*want; cin.get(); for(i=tag=0;icount;i+) if(books.at(i).getname()=want) tag=1;/*当图书馆中存在图书是讲tag赋
12、值为1*/ if(books.at(i).getstate()=0) books.at(i).displayInfo(); coutt*很高兴您所查找的图书在图书库中!*endl t*为图书库中的第 i+1 本图书!*endl t*请记住此本图书的位置以方便您的借阅*endlendlendl; system(pause); else coutt*很抱歉您所查找的图书已经不在图书馆了!*endl; if(tag=0)/*如果图书馆中原本就不存在查找的图书的tag是0*/ coutt*很抱歉您所查找的图书不存在!*endl; system(pause); break; case b: coutt*
13、请输入图书的书号ISBN*want; cin.get(); for( int i=tag=0;icount;i+) if(books.at(i).getnum()=want) tag=1; if(books.at(i).getstate()=0) books.at(i).displayInfo(); coutt*很高兴您所查找的图书在图书库中!*endl t*为图书库中的第 i+1 本图书!*endl/*方便图书的借阅*/ t*请记住此本图书的位置以方便您的借阅*endlendlendl; system(pause); else coutt*很抱歉您所查找的图书已经不在图书馆了!*endl;
14、if(tag=0) coutt*很抱歉您所查找的图书不存在!*endl; system(pause); break; case c: coutt*请输入图书的作者t*want; cin.get(); for( int i=tag=0;icount;i+) if(books.at(i).getwriter()=want) tag=1; if(books.at(i).getstate()=0) books.at(i).displayInfo(); coutt*很高兴您所查找的图书在图书库中!*endl t*为图书库中的第 i+1 本图书!*endl t*请记住此本图书的位置以方便您的借阅*endl
15、endlendl; system(pause); else coutt*很抱歉您所查找的图书已经不在图书馆了!*endl; if(tag=0) coutt*很抱歉您所查找的图书不存在!*endl; system(pause); break; case d: coutt*请输入图书的出版社t*want; cin.get(); for( int i=tag=0;icount;i+) if(books.at(i).getpub()=want) tag=1; if(books.at(i).getstate()=0) books.at(i).displayInfo(); coutt*很高兴您所查找的图书
16、在图书库中!*endl t*为图书库中的第 i+1 本图书!*endl t*请记住此本图书的位置以方便您的借阅*endlendlendl; system(pause); else coutt*很抱歉您所查找的图书已经不在图书馆了!*endl; if(tag=0) coutt*很抱歉您所查找的图书不存在!*endl; system(pause); break; default: coutt*%d为非法选项!*nchoice; system(pause); /*实现图书的借出*/void Bookmanage:lendbook() int i=0; coutt*请输入您需要借阅的图书的编号*endl t*即为第几本书,比如 2 *i; cin.get(); if(i=count) Book&temp=books.at(i-1); temp.displayInfo(); if(temp.getstate()=0) coutt*是否为你想要的图书,确定是否借阅 Y/N *c; if(c=Y) temp.Borrowbooks(); coutt*恭喜
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1