#include<iostream>
#include<fstream>
#include<stdio.h>
#include<conio.h>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
using namespace std;
struct book
{
int idnum;//图书检索号
int BorrowCount;//图书借阅量
string name;//书名
string kind;//图书种类;
double price;//图书价格
int sum;//图书总库存量
int nowsum;//图书现库存量
int appointment;
string author;//图书作者
bool ok;//是否可借
string borrowdate;//图书最近一次借出时间
string returndate;//图书馆最近一次归还时间
string room;//馆藏地
};
struct student
{
int id;//读者编号
string name;//读者姓名
int borrowsum;//你已经借阅多少本书
int number;//你现在还有多少本书没有还
string borrowday;//上次借阅时间
int b[10];//你所借书的编号,最多10本
};
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>betolli;//预约书到馆
public:
library();
void ShowAllBook();
int SearchBookPosWithid(int id);
void AddBook(book NewBook);
void Save();
void DeleteBook(string name,string author);
int SearchBookPosWithAB(string thename,string theauthor);
void printbook(book a);
void Borrowbook(string bookname,string bookauthor);
void SortBook(int ca);
void SortStudent(int id);
};
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();
}
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();
}
}
void library::printbook(book a)
{
cout<<setw(8)<<a.idnum;
cout<<setw(14)<<a.name;
cout<<setw(14)<<a.author;
cout<<setw(14)<<fixed<<setprecision(2)<<a.price;
cout<<setw(14)<<a.kind;
cout<<setw(14)<<a.room;
cout<<setw(14)<<a.sum;
cout<<setw(14)<<a.nowsum;
cout<<setw(14)<<a.BorrowCount;
cout<<setw(10)<<(a.ok==0?"不可借":"可借");
cout<<setw(14)<<a.appointment;
cout<<setw(14)<<a.borrowdate;
cout<<setw(14)<<a.returndate<<endl;
}
void library::ShowAllBook()
{
cout<<setw(14)<<"检索号"<<setw(14)<<"书名"<<setw(14)<<"作者"<<setw(14)<<"价格"<<setw(14)<<"种类"<<setw(14)<<"馆藏地"<<setw(14)<<"总库存量"<<setw(14)<<"在馆量"<<setw(14)<<"借阅量"<<setw(10)<<"是否可借"<<setw(14)<<"预约量";
cout<<setw(14)<<"借出时间"<<setw(14)<<"归还时间"<<endl;
for(int i=0;i<data.size();++i)
{
printbook(data[i]);
}
}
int library::SearchBookPosWithid(int id)
{
for(int i=0;i<data.size();i++)
{
if(data[i].idnum==id)
{
return i;
}
}
return -1;
}
void library::AddBook(book NewBook)
{
data.push_back(NewBook);
}
void library::Save()
{
ofstream qq("book.txt");
if(qq)
{
qq<<data.size()<<endl;
for(int i=0;i<data.size();i++)
{
qq<<data[i].idnum<<" "<<data[i].name<<data[i].author<<" "<<data[i].price<<" "<<data[i].kind<<" "<<data[i].room<<" "<<data[i].nowsum<<" "<<data[i].BorrowCount<<endl;
}
qq.close();
}
}
int library::SearchBookPosWithAB(string thename,string theauthor)
{
for(int i=0;i<data.size();++i)
{
if(data[i].author==theauthor&&data[i].name==thename)
{
printbook(data[i]);
return i;
}
cout<<"查无此书";
return -1;
}
}
void library::DeleteBook(string name,string author)
{
int Pos;
Pos=SearchBookPosWithAB(name,author);
if(Pos!=-1)
{
data.erase(data.begin()+Pos);
return;
}
else
cout<<"没有找到此书"<<endl;
}
void library::Borrowbook(string bookname,string bookauthor)
{
string BorrowDate;
string BackDate;
char c;
int flag=0;
}
void library::SortBook(int ca)
{
if(ca==0)//按照借阅量排序
{
sort(data.begin(),data.end(),cmpByCount);
}
if(ca==1)//按照检索号排序
{
sort(data.begin(),data.end(),cmpByidnum);
}
}
void library::SortStudent(int id)
{
if(id==0)//按照借阅量排序
{
sort(data1.begin(),data1.end(),cmpByBorrowsum);
}
else
{
sort(data1.begin(),data1.end(),cmpByid);
}
}
int main()
{
cout.setf(ios::left);
library mybook;
char mm[6];
cout<<"欢迎使用图书馆登录系统"<<endl;
cout<<"请选择你的登录选项:\n";
cout<<"1.管理员登录"<<endl;
cout<<"2.学生登录"<<endl;
int cho,start, kk=1;
cin>>start;
switch(start)
//***************************管理员情况呀呀呀呀呀呀呀呀呀呀呀***************************************************·
case 1:
{
char password[]="425425";
cout<<"请输入管理员口令:";
do
{
kk=1;
for(int i=0;i<6;i++)
{
mm[i]=getch();
cout<<"*";
}
cout<<endl;
for(int i=0;i<6;i++)
{
if(mm[i]!=password[i])
{
cout<<"请输入正确密码!"<<endl;
kk=0;
break;
}
}
}while(!kk);
do
{
cin.clear();
cin.sync();
cout<<" 1.所有图书目录"<<endl;
cout<<" 2.查询图书"<<endl;
cout<<" 3.增加图书"<<endl;
cout<<" 4.删除图书"<<endl;
cout<<" 5.借阅图书"<<endl;
cout<<" 6.归还图书"<<endl;
cout<<" 7.修改图书信息"<<endl;
cout<<" 8.本月借还统计"<<endl;
cout<<" 9.预约书到馆情况"<<endl;
cout<<" 10.退出"<<endl;
cout<<"----------------------------------------------------------------------------------------"<<endl;
cout<<" 请选择功能,输入指令 "<<endl;
cin>>cho;
switch(cho)
{
case 1:
{
int cho2;
do
{
mybook.ShowAllBook();
cout<<"---------------------------------------------------------"<<endl;
cout<<"0.按照借阅量排序, 2.按照索引号排序, 3.退出"<<endl;
cin>>cho2;
switch(cho2);
{
case 0:
mybook.SortBook(0);
break;
case 2:
mybook.SortBook(1);
break;
}
}
while(cho2<3);
break;
}
/*case 2:
{
cout<<
}*/
case 3://**********增加图书***(*******************************************************
{
book temp;
cout<<"请输入检索号:";
cin>>temp.idnum;
while(mybook.SearchBookPosWithid(temp.idnum)>-1)
{
cout<<"检索号重复了"<<endl;
}
cin.clear();
cin.sync();
cout<<"书名:";
cin>>temp.name;
cout<<"作者:";
cin>>temp.author;
cout<<"价格:";
cin>>temp.price;
cout<<"种类:";
cin>>temp.kind;
cout<<"馆藏地址:";
cin>>temp.room;
cout<<"数量:";
cin>>temp.sum;
temp.nowsum=temp.sum;
temp.BorrowCount=0;
temp.ok=true;
temp.appointment=0;
temp.borrowdate="0000.00.00";
temp.returndate="0000.00.00";
mybook.AddBook(temp);
mybook.Save();
cout<<"信息保存成功"<<endl;
break;
}
case 4://删除图书*******************************************************************************************
{
string bookname,bookauthor;
cout<<"请输入你想删除的书的书名和作者名"<<endl;
cin>>bookname>>bookauthor;
mybook.DeleteBook(bookname,bookauthor);
mybook.Save();
break;
}
case 5://借阅图书**********************************************************
{
string bookname,bookauthor;
cout<<"请输入你要借阅图书的书名和作者名"<<endl;
cin>>bookname>>bookauthor;
mybook.Borrowbook(bookname,bookauthor);
/* mybook.Save();*/
break;
}
/*case 6:
case 7:
case 8:
case 9:*/
}
}while(cho<10);
}
/* case 2:*/
return 0;
}
图书管理系统
最新推荐文章于 2024-10-12 09:00:00 发布