/*图书馆*/
//#pragma warning(disable:0461)
#include "global.h"
#include "date.h"
#include "bookdata.h"
#include "readerdata.h"
#include "database.h"
#include "librarian.h"
#include "reader.h"
#include<string>
#include<cstring>
int main()
{
DataBase<BookData>BookBase("books.dat");//打开书籍数据库
DataBase<ReaderData>ReaderBase("readers.dat");//打开读者数据库
char choice = 'X';
while (!(choice == 'E' || choice == 'e'))
{
cout << "(L)ibrarian entry,(R)eader entry,Re(t)urn book,(E)xit:";
cin >> choice;
Librarian* mgr = NULL;
Reader* rdr = NULL;
switch (choice)
{
//管理员登录
case 'l':case 'L':
mgr = new Librarian(101, "zs");
choice = mgr->login();//成功返回X,否则E
while (!(choice == 'E' || choice == 'e'))
{
cout << "(A)dd reader,Add (B)ook,(Q)uery Reader,(P)ut book to shelf.(E)xit:";
cin >> choice;
switch (choice)
{
long id;
char name[40];
case 'a':case 'A':
cout << "Give a reader PIN and input a name:";
cin >> id;
cin.ignore();
cin.get(name, 20, '\n');
ReaderBase.insert(ReaderData(id, name));
break;
case 'b':case 'B':
cout << "Input a book id and name:";
cin >> id;
cin.ignore();
cin.get(name, 40, '\n');
BookBase.insert(BookData(id, name));
break;
case 'q':case 'Q':
cout << "Input a reader's PIN:";
cin >> id;
if (ReaderBase.query(id) == NULL)
{
cout << "No such a reader!" << endl;
}else
{
ReaderBase.query(id)->showData();
}
break;
case 'p':case 'P':
cout << "Input a book id:";
cin >> id;
if (BookBase.query(id) == NULL)
{
cout << "No such a book!" << endl;
}
else {
BookBase.query(id)->setState(SHELF);
}
break;
case 's':case 'S':
ReaderBase.showAllData();
BookBase.showAllData();
break;
case 'e':case 'E':
break;
default:
cout << "Unavailable function!\n";
}
}
delete mgr;
choice = 'X';
break;//管理员退出
//读者登录
case 'r':case 'R':
long PIN, bookId;
int i, t1, t2;
char name[40];
for (i = 0; i < 3; i++)
{
cout << "Input PIN:";
cin >> PIN;
if (ReaderBase.query(PIN) != NULL)
{
rdr = new Reader(PIN);
break;
}
}
if (i == 3)
{
cout << "Check in failed!" << endl;//读者登录失败
choice = 'E';
}
while (!(choice == 'e' || choice == 'E'))
{
cout << "(A)dd book to cart,check (o)ut,(Q)uery book by name,(L)ist my books.(E)xit:";
cin >> choice;
switch (choice)
{
case 'a':case 'A':
cout << "Input a book id:";
cin >> bookId;
if((BookBase.query(bookId)!=NULL)&&(BookBase.query(bookId)->getState()==SHELF))
{
if (rdr->addBook(bookId))
{
BookBase.query(bookId)->setState(LIB);
}
}
break;
case 'o':case'O':
t1 = rdr->getNum();//在书车的图书编号
t2 = ReaderBase.query(PIN)->getNum();//在读者的图书编号
if (t1 > 0 && t2 < LIMIT)
{
cout << PIN << " " << ReaderBase.query(PIN)->getName() << " book list" << endl;
for (i = 0; i < t1 && i < (LIMIT - t2); i++)
{
bookId = ReaderBase.query(PIN)->borrowBook(rdr->checkOut());
BookBase.query(bookId)->setState(READER);
BookBase.query(bookId)->setPIN(PIN);
cout << i + 1 << "\t" << BookBase.query(bookId)->getName() << endl;
}
Date().display();
}
break;
case 'q':case 'Q':
cout << "Input a book name(part):";
cin.ignore();
cin.get(name,40,'\n');
if (BookBase.queryName(name) != NULL)
{
BookBase.queryName(name)->showData();
}
break;
case 'l':case 'L':
ReaderBase.query(PIN)->showData();
break;
case 'c':case 'C':
rdr->showCart();//显示书本在书车的图书编号
break;
case 'e':case 'E':
break;
default:
cout<< "Unavailable function!\n";
}
}
delete mgr;
choice = 'X';
break;//读者退出
//还书入口
case 't':case 'T':
cout << "Input a book id:";
cin >> bookId;
if (BookBase.query(bookId) != NULL)
{
BookBase.query(bookId)->setState(LIB);
if ((PIN = BookBase.query(bookId)->getPIN()) > 0)
{
ReaderBase.query(PIN)->returnBook(bookId);
}
}
break;//退出还书
case 'e':case 'E':
break;
default:
cout << "Unavailable function!\n";
}
}
return 0;
}
- 1
- 2
- 3
- 4
- 5
- 6
前往页