程序代码:
#include <iostream>
#include <windows.h>
#include <fstream>
#include <string>
#include <vector>
#include "book.h"
#include "user.h"
using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::ofstream;
extern std::vector<Book> books;
extern std::vector<User> users;
extern std::multimap< std::string,std::pair<string,Date> > Books;
extern std::multimap<std::string,std::string> Booking;
std::vector<Book>::iterator book_find_by_title(std::vector<Book> &x,string y);
std::vector<Book>::iterator book_find_by_isbn(std::vector<Book> &x,string y);
ostream& operator<<(ostream &os,const Date &date);
void output_book(Book &a);
void book_find(SYSTEMTIME);
void book_booking(SYSTEMTIME);
void aboutbooks(SYSTEMTIME);
void bookname(SYSTEMTIME time);
void bookisbn(SYSTEMTIME time);
int user_login(SYSTEMTIME time);
void to_book_booking(SYSTEMTIME time);
void to_book_back(SYSTEMTIME time);
void to_book_books(SYSTEMTIME time);
void select_books(SYSTEMTIME time);
void update_book(std::vector<Book>::iterator b,SYSTEMTIME time);
void to_edit_Title(std::vector<Book>::iterator b);
void to_edit_Category(std::vector<Book>::iterator b);
void to_edit_Press(std::vector<Book>::iterator b);
void to_edit_Responsible(std::vector<Book>::iterator b);
void to_edit_ISBN(std::vector<Book>::iterator b);
void to_edit_SeriesName(std::vector<Book>::iterator b);
void to_edit_Keywords(std::vector<Book>::iterator b);
void to_edit_Inventory(std::vector<Book>::iterator b);
void booking_deal_with(SYSTEMTIME time);
void be_ofstream();
void nouser();
std::vector<User>::iterator p;
void gotoxy(int x,int y){ //控制光标
COORD c;
c.X = x - 1;
c.Y = y - 1;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),c);
}
bool detection(string Name,string Password){
for(std::vector<User>::iterator iter=users.begin();iter!=users.end();++iter)
if(iter->userok(Name,Password)) {
p=iter;
return true;
}
return false;
}
void addbook(){
system("cls");
cout<<"\n\n\n\t\t书 名:\n"
<<"\t\t分 类:\n"
<<"\t\t出版社:\n"
<<"\t\t责任者:\n"
<<"\t\t ISBN :\n"
<<"\t\t丛书名:\n"
<<"\t\t主题词:\n"
<<"\t\t库 存:"<<endl;
string title;
string category;
string press;
string responsible;
string isbn;
string seriesname;
string keywords;
int inventory;
gotoxy(25,4);
cin>>title;
gotoxy(25,5);
cin>>category;
gotoxy(25,6);
cin>>press;
gotoxy(25,7);
cin>>responsible;
gotoxy(25,8);
cin>>isbn;
gotoxy(25,9);
cin>>seriesname;
gotoxy(25,10);
cin>>keywords;
gotoxy(25,11);
cin>>inventory;
books.push_back(Book(title,category,press,responsible,isbn,seriesname,keywords,inventory));
gotoxy(20,12);
cout<<" 录入成功!"<<endl;
system("PAUSE");
}
void adduser(){
system("cls");
cout<<"\n\n\n\t\t姓名:\n"
<<"\t\t性别:\n"
<<"\t\t学号:\n"
<< "\t\t密码:"<<endl;
string name,sex,stuid,password;
gotoxy(25,4);
cin>>name;
gotoxy(25,5);
cin>>sex;
gotoxy(25,6);
cin>>stuid;
gotoxy(25,7);
cin>>password;
users.push_back(User(name,sex,stuid,password));
gotoxy(20,8);
cout<<" 注册成功! 请返回重新登录! "<<endl;
system("PAUSE");
}
void menu(SYSTEMTIME time){
ostream& operator<<(ostream& os, std::multimap< std::string,std::pair<string,Date> >::iterator iter);
while(1){
system("cls");
void user(SYSTEMTIME time);
void admin(SYSTEMTIME time);
cout<<"\n\n"
<<"\t\t当前时间: "<<time.wYear<<"/"<<time.wMonth<<"/"<<time.wDay<<" "
<<time.wHour<<":"<<time.wMinute<<":"<<time.wSecond<<endl
<<"\t\t*****************************************************\n"
<<"\t\t*****************************************************\n"
<<"\t\t************* *************\n"
<<"\t\t************* 欢迎使用图书管理系统 *************\n"
<<"\t\t************* *************\n"
<<"\t\t*****************************************************\n"
<<"\t\t*****************************************************\n"
<<"\t\t************* *************\n"
<<"\t\t************* 1.用户模式 *************\n"
<<"\t\t************* 2.管理员模式 *************\n"
<<"\t\t************* *************\n"
<<"\t\t*****************************************************\n"
<<"\t\t*****************************************************\n"
<<"\t\t************* 输入其他任何数退出 *************\n"
<<"\t\t*****************************************************\n"
<<"\t\t*****************************************************\n"
<<"\t\t************* 请选择: *************\n"
<<"\t\t*****************************************************\n"
<<"\t\t*****************************************************"<<endl;
// for(std::multimap< std::string,std::pair<string,Date> >::iterator iter=Books.begin();iter!=Books.end();++iter){
// cout<<iter->first<<" "<<iter->second.first<<" "<<iter->second.second.Year<<" "<<iter->second.second.Months<<" "<<iter->second.second.Day<<endl;
//}
gotoxy(45,20);
int a;
cin>>a;
switch(a){
case 1:if(int x=user_login(time)!=0){if(x==1)user(time);else break;}else {nouser();adduser();}break;
case 2:admin(time);
default:be_ofstream();exit(0);
}
}
}
void user(SYSTEMTIME time){
while(1){
system("cls");
cout<<"\n\t\t"<<p->getname()<<",欢迎使用本系统!\n"
<<"\t\t当前时间: "<<time.wYear<<"/"<<time.wMonth<<"/"<<time.wDay<<" "
<<time.wHour<<":"<<time.wMinute<<":"<<time.wSecond<<endl
<<"\t\t**************************************************\n"
<<"\t\t**************************************************\n"
<<"\t\t*********** ***********\n"
<<"\t\t*********** 1.图书库存查询 ***********\n"
<<"\t\t*********** 2.已借图书查询 ***********\n"
<<"\t\t*********** 3.图 书 预 定 ***********\n"
<<"\t\t*********** 4.图 书 借 还 ***********\n"
<<"\t\t*********** 5. 退 出 ***********\n"
<<"\t\t*********** ***********\n"
<<"\t\t**************************************************\n"
<<"\t\t**************************************************\n"
<<"\t\t*********** 请选择: ***********\n"
<<"\t\t**************************************************\n"
<<"\t\t**************************************************"<<endl;
gotoxy(45,15);
int a;
cin>>a;
switch(a){
case 1:system("cls");book_find(time);break;
case 2:system("cls");p->output();system("PAUSE");break;
case 3:system("cls");book_booking(time);break;
case 4:system("cls");aboutbooks(time);break;
case 5:be_ofstream();exit(0);
default:gotoxy(45,18);cout<<"\n\n\t\t无效输入!请重新选择!"<<endl;system("PAUSE");
}
}
}
void admin(SYSTEMTIME time){
while(1){
system("cls");
cout<<"\n\n"
<<"\t\t当前时间: "<<time.wYear<<"/"<<time.wMonth<<"/"<<time.wDay<<" "
<<time.wHour<<":"<<time.wMinute<<":"<<time.wSecond<<endl
<<"\t\t**************************************************\n"
<<"\t\t**************************************************\n"
<<"\t\t*********** ***********\n"
<<"\t\t*********** 1.图书库存查询 ***********\n"
<<"\t\t*********** 2.图 书 录 入 ***********\n"
<<"\t\t*********** 3.图 书 更 新 ***********\n"
<<"\t\t*********** 4.图书预定处理 ***********\n"
<<"\t\t*********** 5. 退 出 ***********\n"
<<"\t\t*********** ***********\n"
<<"\t\t**************************************************\n"
<<"\t\t**************************************************\n"
<<"\t\t*********** 请选择: ***********\n"
<<"\t\t**************************************************\n"
<<"\t\t**************************************************"<<endl;
gotoxy(45,15);
int a;
cin>>a;
switch(a){
case 1:system("cls");book_find(time);break;
case 2:system("cls");addbook();break;
case 3:system("cls");select_books(time);break;
case 4:system("cls");booking_deal_with(time);break;
case 5:be_ofstream();exit(0);
default:gotoxy(45,18);cout<<"\n\n\t\t无效输入!请重新选择!"<<endl;system("PAUSE");
}
}
}
void book_find(SYSTEMTIME time){
while(1){
system("cls");
cout<<"\n\n"
<<"\t\t当前时间: "<<time.wYear<<"/"<<time.wMonth<<"/"<<time.wDay<<" "
<<time.wHour<<":"<<time.wMinute<<":"<<time.wSecond<<endl
<<"\t\t**************************************************\n"
<<"\t\t**************************************************\n"
<<"\t\t*********** ***********\n"
<<"\t\t*********** 本系统提供两种查询方式 ***********\n"
<<"\t\t*********** ***********\n"
<<"\t\t*********** 1.通过书名查询 ***********\n"
<<"\t\t*********** 2.通过ISBN查询 ***********\n"
<<"\t\t*********** 3. 返 回 ***********\n"
<<"\t\t*********** ***********\n"
<<"\t\t**************************************************\n"
<<"\t\t**************************************************\n"
<<"\t\t*********** 请选择: ***********\n"
<<"\t\t**************************************************\n"
<<"\t\t**************************************************"<<endl;
gotoxy(45,15);
int a;
cin>>a;
switch(a){
case 1: bookname(time);break;
case 2: bookisbn(time);break;
case 3: return;
default:gotoxy(45,18);cout<<"\n\n\t\t无效输入!请重新选择!"<<endl;system("PAUSE");
}
}
}
void book_booking(SYSTEMTIME time){
while(1){
system("cls");
cout<<"\n\n"
<<"\t\t当前时间: "<<time.wYear<<"/"<<time.wMonth<<"/"<<time.wDay<<" "
<<time.wHour<<":"<<time.wMinute<<":"<<time.wSecond<<endl
<<"\t\t**************************************************\n"
<<"\t\t**************************************************\n"
<<"\t\t*********** ***********\n"
<<"\t\t*********** 请选择需要的功能 ***********\n"
<<"\t\t*********** ***********\n"
<<"\t\t*********** 1.查询已预定图书 ***********\n"
<<"\t\t*********** 2.预 定 新 书 ***********\n"
<<"\t\t*********** 3. 返 回 ***********\n"
<<"\t\t*********** ***********\n"
<<"\t\t**************************************************\n"
<<"\t\t**************************************************\n"
<<"\t\t*********** 请选择: ***********\n"
<<"\t\t**************************************************\n"
<<"\t\t**************************************************"<<endl;
gotoxy(45,15);
int a;
cin>>a;
switch(a){
case 1: system("cls");p->output_booking();system("PAUSE");break;
case 2: system("cls");to_book_booking(time);break;
case 3: return;
default:gotoxy(45,18);cout<<"无效输入!请重新选择!"<<endl;system("PAUSE");
}
}
}
void aboutbooks(SYSTEMTIME time){
while(1){
system("cls");
cout<<"\n\n"
<<"\t\t当前时间: "<<time.wYear<<"/"<<time.wMonth<<"/"<<time.wDay<<" "
<<time.wHour<<":"<<time.wMinute<<":"<<time.wSecond<<endl
<<"\t\t**************************************************\n"
<<"\t\t**************************************************\n"
<<"\t\t*********** ***********\n"
<<"\t\t*********** 请选择需要的功能 ***********\n"
<<"\t\t*********** ***********\n"
<<"\t\t*********** 1.借 阅 图 书 ***********\n"
<<"\t\t*********** 2.归 还 图 书 ***********\n"
<<"\t\t*********** 3. 返 回 ***********\n"
<<"\t\t*********** ***********\n"
<<"\t\t**************************************************\n"
<<"\t\t**************************************************\n"
<<"\t\t*********** 请选择: ***********\n"
<<"\t\t**************************************************\n"
<<"\t\t**************************************************"<<endl;
gotoxy(45,15);
int a;
cin>>a;
switch(a){
case 1: system("cls");to_book_books(time);break;
case 2: system("cls");to_book_back(time);break;
case 3: return;
default:gotoxy(45,18);cout<<"\n\n\t\t无效输入!请重新选择!"<<endl;system("PAUSE");
}
}
}
void bookname(SYSTEMTIME time){
while(1){
system("cls");
cout<<"\n\n"
<<"\t\t当前时间: "<<time.wYear<<"/"<<time.wMonth<<"/"<<time.wDay<<" "
<<time.wHour<<":"<<time.wMinute<<":"<<time.wSecond<<endl
<<"\t\t**************************************************\n"
<<"\t\t**************************************************\n"
<<"\t\t*********** ***********\n"
<<"\t\t*********** 请输入书名: ***********\n"
<<"\t\t*********** 输入“返回”将返回 ***********\n"
<<"\t\t**************************************************\n"
<<"\t\t**************************************************"<<endl;
gotoxy(42,7);
string a;
cin>>a;
std::vector<Book>::iterator p;
if(a==string("返回")) return;
p=book_find_by_title(books,a);
if(p!=books.end()) {output_book(p);system("PAUSE");}
else {gotoxy(42,11);cout<<"\n\n\n\t\t书库中没有这本书!"<<endl;system("PAUSE");}
}
}