图书管理系统c++

这是一个C++编写的图书管理系统,具备图书信息管理、借还、预约等功能。系统包括管理员和读者两种权限,管理员需要密码登录,读者可以注册账号并自主借还书,还能查看借阅排名和预约情况。管理员则能查看图书库存、预约状态和借还统计。
摘要由CSDN通过智能技术生成

问题描述                             

该系统要求建立设置的图书管理系统,具有对图书信息的存储、更新、查询、统计、排行、输出功能,和图书的借还及预约功能。通过此课题,熟练掌握高级程序设计语言的数据类型、程序设计语句、函数的定义和调用方法及模块化思想。

功能要求

(1)每种图书包含信息如:图书序号、图书名称、图书种类、图书总库存量、图书现库存量、作者、库存地点、借还状态等。

(2)需要实现的功能

1、该系统可用于对图书基本信息的存储、更新、查询、统计、排行、输出等操作,以实现对图书的管理。

2、其中更新功能包括:添加信息、删除信息、修改信息,可根据需要添加一个或多个图书信息,也可对个别图书信息进行适当的删除或修改,以便随时更新图书信息。

3、程序中设计的查询功能可根据需要从若干数据中查询某个图书信息,并且可根据四种不同的方法查询:按名称查询、按种类查询、按作者查询、按书名和作者查询,以满足不同的需要。

4、实时更新图书借还状态和图书库存现状。

(3)界面友好。

注:为了系统更加人性化,具有时代性,在咨询老师后,我们在以上基础上添加以下功能来丰富系统。

1、      增加读者权限,与管理员权限加以区别,管理员需要密码登录,读者需要读者号方可登录。

2、      读者可以自己注册读者账号,一个账号同时最多借10本书。

3、      读者可以自助还书,查看自己的借阅信息,以及预约书籍。

4、      读者可以查询书籍在馆情况,预约情况等。

5、      向读者推送书籍最高借阅和读者的借阅排名,读者可在自己的信息中查看。

6、      读者也可以通过管理员在借还总台还借书。

7、      管理员可以查看预约书到馆情况,以便向预约者通知。

8、      管理员可以查看借还书总次数

9、      可以对图书以借阅量以或检索号进行排序观察

注:读者可以自己编写测试文件,文件为txt格式,或者机子修改代码换为其他格式

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <fstream>
#include <cctype>
#include <iomanip>
#include <conio.h>
using namespace std;
struct student
{
    int id;//读者编号
    string name;//读者姓名
    int borrowsum;//你已借阅多少本书,默认为0
    int number;//现在还有多少本书未还,默认为0
    string borrowday;//上次借阅时间,默认为0000.00.00
    int b[10];//你所借书的的编号,最多10本
};
struct book
{
    int idnum;//图书检索号
    int BorrowCount;//图书借阅量,初始化为0
    string name;//书名
    string kind;//图书种类
    double price;//图书价格
    int sum;//图书总库存存量
    int nowsum;//图书现库存量
    string author;//图书作者
    int appointment;//图书预约量,初始化为0
    bool ok;//是否可借,初始为可以
    string borrowdate;//图书最近一次借出时间,默认为0000-00-00;
    string returndate;//图书最近一次归还时间,默认为0000-00-00;
    string room;//馆藏地
};
bool cmpByidnum(book a,book b)
{
    return a.idnum<b.idnum;
}
bool cmpByCount(book a,book b)
{
    return a.BorrowCount>b.BorrowCount;
}
bool cmpByBorrowsum(student a,student b)
{
    return a.borrowsum>b.borrowsum;
}
bool cmpByid(student a,student b)
{
    return a.id<b.id;
}
class Library
{
private:
    int borrownum;//每月借出书数量
    int returnnum;//每月还书数量
    vector<book> data;
    vector<student> data1;
    vector<int> betoli;//预约书到馆,储存其编号
public:
    Library();
    void AddBook(book NewBook);  //增加图书
    void DeleteBook(string bookname,string author);//删除图书
    void BorrowBook(string name,string author);//借阅图书
    void BackBook(string name,string author,int k);//归还图书
    void ShowAllBook(); //输出系统所有图书
    void  SearchBookPosWithname(string thebook); //按书名查询
    void  SearchBookPosWithAuthor(string theauthor);//按作者查询
    void  SearchBookPosWithKind(string kind);//按种类查询
    int  SearchBookPosWithAB(string theauthor,string thebook);//按作者和书名查询
    int  SearchBookPosWithid(int id); //按检索号搜寻
    void SortBook(int ca);  //排序
    void SortStudent(int ca);//按读者借阅量排序
    void Save();  //存入图书馆文件
    void Save1();//存入学生文件
    void Appointment(string bookname,string author);//预约图书
    void printbook(book a);//输出某本书的所有信息
    void revisebook(string name,string author);//修改某本书的信息
    int SerchStudent(int id);//查询某个读者
    //int SerchStudent1(int id);//查询某个读者
    void AddStudent(student a);//增加一个读者
    void PrintStudent(int kid);//输出读者信息
    int GetStudent();//返回读者总数
    int readsum(int id);//获取某个读者的借阅量
    int getborrownum();//获取本月外借量
    int getreturnnum();//获取本月还书量
    void PrintToLi();//输出到馆预约书
};
Library::Library()
{
    borrownum=0;
    returnnum=0;
    int AllBook,AllStudent;
    ifstream fin("book.txt");
    if(fin)
    {
        fin>>AllBook;
        for(int i=0; i<AllBook; i++)
        {
            book tem;
            fin>>tem.idnum>>tem.name>>tem.author>>tem.price>>tem.kind>>tem.room>>tem.sum>>tem.nowsum>>tem.BorrowCount>>tem.ok>>tem.appointment>>tem.borrowdate>>tem.returndate;
            data.push_back(tem);
        }
        fin.close();
    }
    //cin.clear();
    //cin.sync();
    ifstream tfin("student.txt");
    if(tfin)
    {
        tfin>>AllStudent;
        for(int i=0; i<AllStudent; i++)
        {
            student tem;
            tfin>>tem.id>>tem.name>>tem.borrowsum>>tem.number>>tem.borrowday;
            for(int j=0;j<10;j++)
            {
                tfin>>tem.b[j];
            }
            data1.push_back(tem);
        }
        tfin.close();
    }
}
int Library::readsum(int a)
{
    //SortStudent(1);
    return data1[a-1].borrowsum;
}
int Library::getborrownum()//获取本月外借量
{
    return borrownum;
}
int Library::getreturnnum()//获取本月还书量
{
    return returnnum;
}
int Library::GetStudent()
{
    int k=(int)data1.size();
    return k+1;
}
void Library::AddBook(book NewBook)
{
    data.push_back(NewBook);
}
void Library::AddStu
/*****************************************************************************************/#include #include #include #include //输入/输出文件流类using namespace std;const int Maxr=100;//最多的读者const int Maxb=100;//最多的图书const int Maxbor=5;//每位读者最多借五本书//读者类,实现对读者的信息的描述class Reader { private: int tag; //删除标记 1:已删 0:未删 int no; //读者编号 char name[10]; //读者姓名 int borbook[Maxbor];//所借图书 public: Reader() {} char *getname() {return name;} //获取姓名 int gettag() {return tag;} //获取删除标记 int getno() {return no;} //获取读者编号 void setname(char na[]) //设置姓名 { strcpy(name,na); } void delbook(){ tag=1; }//设置删除标记 1:已删 0:未删 void addreader(int n,char *na)//增加读者 { tag=0; no=n; strcpy(name,na); for(int i=0;i<Maxbor;i++) borbook[i]=0; } void borrowbook(int bookid)//借书操作 { for(int i=0;i<Maxbor;i++) { if (borbook[i]==0) { borbook[i]=bookid; return; } } } int retbook(int bookid)//还书操作 { for(int i=0;i<Maxbor;i++) { if(borbook[i]==bookid) { borbook[i]=0; return 1; } } return 0; } void disp()//读出读者信息 { cout << setw(5) << no <<setw(10) << name<<"借书编号:["; for(int i=0;i<Maxbor;i++) if(borbook[i]!=0) cout << borbook[i] << "|"; cout << "]"<<endl; }};//读者类库,实现建立读者的个人资料 class RDatabase{ private: int top; //读者记录指针 Reader read[Maxr];//读者记录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++; read[top]=s; } file.close(); //关闭 reader.txt } void clear()//删除所有读者信息 { top=-1; } int addreader(int n,char *na)//添加读者时先查找是否存在 { Reader *p=query(n); if (p==NULL) { top++; read[top].addreader(n,na); return 1; } return 0; } Reader *query(int readerid)//按编号查找 { for (int i=0;i<=top;i++) if (read[i].getno()==readerid && read[i].gettag()==0) { return &read[i]; } return NULL; } void disp() //输出所有读者信息 { for (int i=0;i<=top;i++) read[i].disp(); } void readerdata();//读者库维护 ~RDatabase() //析构函数,将read[]写到reader.txt文件中 { fstream file("reader.
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值