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