最近想写一个MFC版本的图书馆管理系统,设计好界面后 发现无重下手,所以还是先写一个DOS版的,作为类似内核的东西,这个写好了 要弄出MFC版本的其实就好弄多了,下面是代码:
//书籍类
#ifndef _BOOK_H_
#define _BOOK_H_
#include <string>
using namespace std;
class Book
{
private:
string Book_name; //书名
string Book_num; //条形码
int Sum; //馆藏数量
public:
Book();
string Get_BName(); //返回书名
string Get_BNum(); //返回条形码
int Get_Sum(); //返回馆藏容量
void Set_BName(string name); //设置书名
void Set_BNum(string num); //设置条形码
void Set_BSum(int sum); //设置存量
bool Bro_Book(); //被借
void Re_Book(); //被还
void Add_Book(int num); //添加该书的总量
void Print(); //输出书本的信息
Book &operator = (const Book &book);//重载=运算符
};
#endif
//书籍类实现#include "book.h"#include <iostream>#include <string>using namespace std;Book::Book(){Book_name="0";Book_num="0";Sum=0;}string Book::Get_BName(){return Book_name;}string Book::Get_BNum(){return Book_num;}int Book::Get_Sum(){return Sum;}void Book::Set_BName(string name){Book_name=name;}void Book::Set_BNum(string num){Book_num=num;}void Book::Set_BSum(int sum){Sum=sum;}bool Book::Bro_Book(){if(Sum==0){cout<<"该书现在馆藏数为0,不可借阅"<<endl;return false;}Sum-=1;return true;}void Book::Re_Book(){Sum+=1;}void Book::Add_Book(int num){Sum+=num;}void Book::Print(){cout<<"书名:"<<Book_name<<" 条形码:"<<Book_num<<" 馆藏数目:"<<Sum<<endl;
}Book &Book::operator =(const Book &book){this->Book_name=book.Book_name;this->Book_num=book.Book_num;this->Sum=book.Sum;return *this;}
//书库类#ifndef BOOK_DBASE_H_#define BOOK_DBASE_H_#include "book.h"#include <string>using namespace std;#define BOOK_MAX_SUM 100 //书库可存储的书的种类的上限class Book_DBase{private:unsigned int max_sum; //书的总类上限unsigned int cur_sum; //当前书的总类Book *books; //书库public:Book_DBase();bool Search_Book(string name,Book &book,int &pos); //在书库中搜索指定书名的书籍bool Add_Book(string name); //添加书籍bool Del_Book(string name); //删除书籍void Print_All(); //输出书库中所有藏书信息bool Init_BookDabse(); //初始化书库void Write_into_file(); //将书库信息写入文件};#endif
//书库类实现
#include "bk_dbase.h"
#include <string>
#include <fstream>
#include <iostream>
using namespace std;
Book_DBase::Book_DBase()
{
max_sum=BOOK_MAX_SUM;
cur_sum=0;
books=new Book[BOOK_MAX_SUM];
}
bool Book_DBase::Search_Book(string name,Book &book,int &pos)
{
for(int i=0;i<cur_sum;i++)
if(books[i].Get_BName()==name)
{
book=books[i];
pos=i;
return true;
}
return false;
}
bool Book_DBase::Add_Book(string name)
{
Book book;
int pos=-1;
unsigned int sum=0;
if(Search_Book(name,book,pos))
{
cout<<"该书馆中已存,请输入添加的册数:";
cin>>sum;
book.Add_Book(sum);
return true;
}
else
{
if(cur_sum>BOOK_MAX_SUM)
{
cout<<"馆藏种类已达上限,无法再添加新书"<<endl;
return false;
}
string num;
cout<<"输入该书的条形码:";
cin>>num;
book.Set_BName(name);
book.Set_BNum(num);
cout<<"输入册数:";
cin>>sum;
book.Set_BSum(sum);
books[cur_sum]=book;
cur_sum++;
return true;
}
}
bool Book_DBase::Del_Book(string name)
{
Book book;
int pos=-1;
if(Search_Book(name,book,pos))
{
cout<<"你删除的书本信息如下:"<<endl;
book.Print();
for(int i=pos+1;i<cur_sum;i++)
books[i-1]=books[i];
cur_sum--;
return true;
}
else
{
cout<<"馆中无该书信息"<<endl;
return false;
}
}
void Book_DBase::Print_All()
{
for(int i=0;i<cur_sum;i++)
{
cout<<"第"<<i+1<<"本书的信息为:";
books[i].Print();
}
}
bool Book_DBase::Init_BookDabse()
{
string name,num;
int sum;
ifstream file;
file.open("books.txt");
int i=0;
if(!file)
{
cout<<"文件\"books.txt\"打开失败"<<endl;
return false;
}
else
{
while(!file.eof())
{
file>>name>>num>>sum;
books[i].Set_BName(name);
books[i].Set_BNum(num);
books[i].Set_BSum(sum);
i++;
}
cur_sum=i;
file.close();
return true;
}
}
void Book_DBase::Write_into_file()
{
ofstream file("books.txt");
if(!file)
{
cout<<"文件\"books.txt\"打开失败"<<endl;
}
else
{
for(int i=0;i<cur_sum-1;i++)
file<<books[i].Get_BName()<<" "<<books[i].Get_BNum()<<" "<<books[i].Get_Sum()<<endl;
file<<books[i].Get_BName()<<" "<<books[i].Get_BNum()<<" "<<books[i].Get_Sum();
file.close();
}
}
//读者类
#ifndef _READER_H_
#define _READER_H_
#include "book.h"
#include <string>
using namespace std;
#define Max_Bro 10
class Reader
{
private:
string Reader_Name; //读者名字
string Reader_Num; //学号
string Reader_Sex; //性别
string Reader_Pro; //专业
string Reader_Birthday; //出生年月日
string Zhang_Hao; //登录帐号
string Mi_ma; //登录密码
//Book *Bro_books; //导致我Debug了好几天的罪魁祸首
Book Bro_books[Max_Bro]; //借书名单
int cur_sum; //已借书本总量
public:
Reader();
Reader(const Reader& reader);
string Get_RZhangHao(); //Get_***函数都是返回相应变量值
string Get_RMima();
string Get_RName();
string Get_RNum();
string Get_RSex();
string Get_RBirthday();
string Get_RPro();
int Get_Cur_Sum();
void Set_RName(string name); //Set_***函数都是设置相应变量值
void Set_RNum(string num);
void Set_RSex(string sex);
void Set_RPro(string pro);
void Set_RBirth(string birth);
void Set_RZhanghao(string zhanghao);
void Set_RMima(string mima);
void Set_RCur_Sum();
bool Search_in_Bro(string name,int&); //在已借阅的书中搜索指定书名的书籍
bool Bro_Book(Book book); //借书
bool Re_Book(Book &book); //还书
void Print(); //输出读者信息
void Print_Bro_Book(); //输出已借书籍信息
Reader &operator = (Reader &reader); //重载=运算符
};
#endif
//读者类实现
#include "reader.h"
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
Reader::Reader()
{
Reader_Name="0";
Reader_Num="0";
Reader_Sex="0";
Reader_Pro="0";
Reader_Birthday="0";
Zhang_Hao="0";
Mi_ma="0";
cur_sum=0;
//Bro_books=new Book[10];
}
Reader::Reader(const Reader &reader)
{
this->Reader_Name=reader.Reader_Name;
this->Reader_Num=reader.Reader_Num;
this->Reader_Sex=reader.Reader_Sex;
this->Reader_Birthday=reader.Reader_Birthday;
this->Reader_Pro=reader.Reader_Pro;
this->Zhang_Hao=reader.Zhang_Hao;
this->Mi_ma=reader.Mi_ma;
this->cur_sum=reader.cur_sum;
}
string Reader::Get_RZhangHao()
{
return Zhang_Hao;
}
string Reader::Get_RMima()
{
return Mi_ma;
}
string Reader::Get_RName()
{
return Reader_Name;
}
string Reader::Get_RNum()
{
return Reader_Num;
}
string Reader::Get_RSex()
{
return Reader_Sex;
}
string Reader::Get_RBirthday()
{
return Reader_Birthday;
}
string Reader::Get_RPro()
{
return Reader_Pro;
}
int Reader::Get_Cur_Sum()
{
return cur_sum;
}
void Reader::Set_RName(string name)
{
Reader_Name=name;
}
void Reader::Set_RNum(string num)
{
Reader_Num=num;
}
void Reader::Set_RSex(string sex)
{
Reader_Sex=sex;
}
void Reader::Set_RPro(string pro)
{
Reader_Pro=pro;
}
void Reader::Set_RBirth(string birth)
{
Reader_Birthday=birth;
}
void Reader::Set_RZhanghao(string zhanghao)
{
Zhang_Hao=zhanghao;
}
void Reader::Set_RMima(string mima)
{
Mi_ma=mima;
}
void Reader::Set_RCur_Sum()
{
cur_sum=0;
}
bool Reader::Search_in_Bro(string name,int &pos)
{
for(int i=0;i<cur_sum;i++)
if(Bro_books[i].Get_BName()==name)
{
pos=i;
return true;
}
return false;
}
bool Reader::Bro_Book(Book book)
{
int pos=-1;
if(Search_in_Bro(book.Get_BName(),pos))
{
cout<<"该书你已借阅"<<endl;
return false;
}
else if(cur_sum>10)
{
cout<<"你的借阅数已达上限,要先还了书才可以借"<<endl;
return false;
}
else
{
if(book.Bro_Book())
{
Bro_books[cur_sum]=book;
cur_sum++;
return true;
}
}
}
bool Reader::Re_Book(Book &book)
{
int pos=-1;
if(Search_in_Bro(book.Get_BName(),pos))
{
book.Re_Book();
for(int i=pos+1;i<cur_sum;i++)
Bro_books[i-1]=Bro_books[i];
cur_sum--;
return true;
}
else
{
cout<<"你并未借阅该书"<<endl;
return false;
}
}
void Reader::Print()
{
cout<<"名字:"<<Reader_Name<<endl;
cout<<"学号:"<<Reader_Num<<endl;
cout<<"性别:"<<Reader_Sex<<endl;
cout<<"生日:"<<Reader_Birthday<<endl;
cout<<"专业:"<<Reader_Pro<<endl;
}
void Reader::Print_Bro_Book()
{
cout<<"你所借阅的书籍如下:"<<endl;
for(int i=0;i<cur_sum;i++)
cout<<Bro_books[i].Get_BName()<<" "<<Bro_books[i].Get_BNum()<<endl;
}
Reader &Reader::operator = (Reader& reader)
{
this->Reader_Name=reader.Reader_Name;
this->Reader_Num=reader.Reader_Num;
this->Reader_Sex=reader.Reader_Sex;
this->Reader_Birthday=reader.Reader_Birthday;
this->Reader_Pro=reader.Reader_Pro;
this->Zhang_Hao=reader.Zhang_Hao;
this->Mi_ma=reader.Mi_ma;
this->cur_sum=reader.cur_sum;
return *this;
}
//读者库类
#ifndef READER_DBASE_H_
#define READER_DBASE_H_
#include "reader.h"
#include <string>
using namespace std;
#define MAX_READER_NUM 100 //读者库可包含的读者总数
class Reader_DBase
{
private:
unsigned int max_sum; //读者上限
unsigned int cur_sum; //当前读者总数
Reader *readers; //读者库
public:
Reader_DBase();
bool Search_Reader(string name,Reader &reader,int &pos); //在库中搜索指定名字的读者,若找到用reader装载该读者相应信息
bool Search_ZhangHao(string zhanghao,Reader& reader); //在读者库中通过指定账号搜索某个读者的信息
bool Add_Reader(Reader reader); //添加读者到库中
void Del_Reader(Reader reader); //从库中删除读者
void Set_Reader_For_Adm(Reader &reader); //管理员修改读者相关信息
void Set_Reader_For_Stu(Reader &reader); //读者自己修改自己的相关信息
void Update_Info(Reader &reader,string zhanghao); //更新指定读者在库中的信息
void Print_All(); //输出库中全部读者信息
bool Init_ReaderDbase(); //初始化读者库
bool Write_into_file(); //将读者库信息写入文件
};
#endif
//读者库类实现
#include "rd_dbase.h"
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
Reader_DBase::Reader_DBase()
{
max_sum=MAX_READER_NUM;
cur_sum=0;
readers=new Reader[max_sum];
}
bool Reader_DBase::Search_Reader(string name,Reader &reader,int &pos)
{
for(int i=0;i<cur_sum;i++)
if(readers[i].Get_RName()==name)
{
reader=readers[i];
pos=i;
return true;
}
return false;
}
bool Reader_DBase::Search_ZhangHao(string zhanghao,Reader& reader)
{
for(int i=0;i<cur_sum;i++)
if(readers[i].Get_RZhangHao()==zhanghao)
{
reader=readers[i];
return true;
}
return false;
}
bool Reader_DBase::Add_Reader(Reader reader)
{
int pos;
if(Search_Reader(reader.Get_RName(),reader,pos))
{
cout<<"该读者已经库中,不可重复添加"<<endl;
return false;
}
else
{
if(cur_sum>max_sum)
{
cout<<"读者库读者数目已达上限,无法再添加新读者"<<endl;
return false;
}
readers[cur_sum]=reader;
cur_sum++;
return true;
}
}
void Reader_DBase::Del_Reader(Reader reader)
{
int pos=-1;
if(Search_Reader(reader.Get_RName(),reader,pos))
{
cout<<"删除的读者信息如下:";
reader.Print();
for(int i=pos+1;i<cur_sum;i++)
readers[i-1]=readers[i];
cur_sum--;
}
}
void Reader_DBase::Set_Reader_For_Adm(Reader &reader)
{
int pos=-1;
int flag;
string temp;
do
{
cout<<"输入你的选择"<<endl;
cout<<" |-------------------------|"<<endl;
cout<<" | 1:姓名 2:学号 3:性别 |"<<endl;
cout<<" | 4:专业 5:生日 6:退出 |"<<endl;
cout<<" |-------------------------|"<<endl;
cin>>flag;
switch(flag)
{
case 1:
cout<<"输入新的姓名:";
cin>>temp;
reader.Set_RName(temp);
cout<<"修改完成"<<endl;
break;
case 2:
cout<<"输入新的学号:";
cin>>temp;
reader.Set_RNum(temp);
cout<<"修改完成"<<endl;
break;
case 3:
cout<<"输入新的性别:";
cin>>temp;
reader.Set_RSex(temp);
cout<<"修改完成"<<endl;
break;
case 4:
cout<<"输入新的专业:";
cin>>temp;
reader.Set_RPro(temp);
cout<<"修改完成"<<endl;
break;
case 5:
cout<<"输入新的生日:";
cin>>temp;
reader.Set_RBirth(temp);
cout<<"修改完成"<<endl;
break;
case 6:
cout<<"修改结束"<<endl;
break;
default:
cout<<"选择无效"<<endl;
}
}while(flag!=6);
Update_Info(reader,reader.Get_RZhangHao());
Write_into_file();
}
void Reader_DBase::Set_Reader_For_Stu(Reader &reader)
{
int pos=-1;
int flag;
string temp;
do
{
cout<<"输入你的选择"<<endl;
cout<<" |---------------------------------|"<<endl;
cout<<" | 1:性别 2:专业 3:生日 4:退出 |"<<endl;
cout<<" |---------------------------------|"<<endl;
cin>>flag;
switch(flag)
{
case 1:
cout<<"输入新的性别:";
cin>>temp;
reader.Set_RSex(temp);
cout<<"修改完成"<<endl;
break;
case 2:
cout<<"输入新的专业:";
cin>>temp;
reader.Set_RPro(temp);
cout<<"修改完成"<<endl;
break;
case 3:
cout<<"输入新的生日:";
cin>>temp;
reader.Set_RBirth(temp);
cout<<"修改完成"<<endl;
break;
case 4:
cout<<"修改结束"<<endl;
break;
default:
cout<<"选择无效"<<endl;
}
}while(flag!=4);
Update_Info(reader,reader.Get_RZhangHao());
Write_into_file();
}
void Reader_DBase::Update_Info(Reader &reader,string zhanghao)
{
Reader temp_reader;
int pos=-1;
if(Search_ZhangHao(zhanghao,temp_reader))
{
if(Search_Reader(temp_reader.Get_RName(),temp_reader,pos))
{
readers[pos]=reader;
}
}
}
void Reader_DBase::Print_All()
{
for(int i=0;i<cur_sum;i++)
{
cout<<"第"<<i+1<<"个读者的信息如下:"<<endl;
readers[i].Print();
}
}
bool Reader_DBase::Init_ReaderDbase()
{
ifstream file;
file.open("reader.txt");
int i=0;
if(!file)
{
cout<<"文件\"reader.txt\"打开失败"<<endl;
return false;
}
else
{
string zhanghao,mima,name,num,birthday,sex,pro;
while(!file.eof())
{
file>>zhanghao>>mima>>name>>num>>sex>>birthday>>pro;
readers[i].Set_RZhanghao(zhanghao);
readers[i].Set_RMima(mima);
readers[i].Set_RName(name);
readers[i].Set_RNum(num);
readers[i].Set_RSex(sex);
readers[i].Set_RBirth(birthday);
readers[i].Set_RPro(pro);
readers[i].Set_RCur_Sum();
i++;
}
cur_sum=i;
file.close();
return true;
}
}
bool Reader_DBase::Write_into_file()
{
ofstream file("reader.txt");
int i=0;
if(!file)
{
cout<<"文件\"reader.txt\"打开失败"<<endl;
return false;
}
else
{
for(i;i<cur_sum-1;i++)
{
file<<readers[i].Get_RZhangHao()<<" "<<readers[i].Get_RMima()<<" "<<readers[i].Get_RName()<<" "
<<readers[i].Get_RNum()<<" "<<readers[i].Get_RSex()<<" "<<readers[i].Get_RBirthday()<<" "
<<readers[i].Get_RPro()<<endl;
}
file<<readers[i].Get_RZhangHao()<<" "<<readers[i].Get_RMima()<<" "<<readers[i].Get_RName()<<" "
<<readers[i].Get_RNum()<<" "<<readers[i].Get_RSex()<<" "<<readers[i].Get_RBirthday()<<" "
<<readers[i].Get_RPro();
file.close();
return true;
}
}
//辅助功能实现的主函数的头文件
#include "book.h"
#include "bk_dbase.h"
#include "reader.h"
#include "rd_dbase.h"
#include <string>
#include <fstream>
#include <iostream>
using namespace std;
//账户类
class Login
{
public:
string Zhang_Hao; //帐号
string Mi_Ma; //密码
public:
Login()
{
Zhang_Hao="";
Mi_Ma="";
}
Login(string zh,string mi)
{
Zhang_Hao=zh;
Mi_Ma=mi;
}
};
Login login[100];
Login Adminidtrator("Admin","123456"); //管理员帐号
int zh_sum=0; //当前账户总数
ofstream file_write;
ifstream file_read;
//初始化账户,将文件中的账户信息读入
void INit_Login()
{
int i=0;
file_read.open("login.txt");
if(!file_read)
{
cout<<"文件\"login.txt\"打开失败"<<endl;
}
else
{
while(!file_read.eof())
{
file_read>>login[i].Zhang_Hao>>login[i].Mi_Ma;
i++;
}
zh_sum=i;
file_read.close();
}
}
//更新login.txt中的内容
bool Update_login_file()
{
file_write.open("login.txt");
if(!file_write)
{
cout<<"文件\"login.txt\"打开失败"<<endl;
return false;
}
for(int i=0;i<zh_sum-1;i++)
file_write<<login[i].Zhang_Hao<<" "<<login[i].Mi_Ma<<endl;
file_write<<login[i].Zhang_Hao<<" "<<login[i].Mi_Ma;
return true;
}
//在账户类中搜索帐号,并保存其位置
bool Search_the_ZH(string zhanghao,int &pos)
{
for(int i=0;i<zh_sum;i++)
if(login[i].Zhang_Hao==zhanghao)
{
pos=i;
return true;
}
return false;
}
//密码匹配
bool Search_the_MM(int pos,string mima)
{
return (login[pos].Mi_Ma==mima);
}
//全局变量 书库与读者库
Book_DBase BDase;
Reader_DBase RDase;
void Student_Manager(Reader reader)
{
int flag,pos=-1,i;
string name,newmima;
Book book;
cout<<" __欢迎进入学生管理界面__"<<endl;
do
{
cout<<"请输入你的选择:"<<endl;
cout<<" |---------------------------------------------------|"<<endl;
cout<<" | 1:证件信息 2:已借书刊 3:检索书籍 4:借阅书籍 |"<<endl;
cout<<" | 5:归还书籍 6:修改信息 7:修改密码 8:退出 |"<<endl;
cout<<" |---------------------------------------------------|"<<endl;
cin>>flag;
switch(flag)
{
case 1:
cout<<"基本信息如下:"<<endl;
reader.Print();
break;
case 2:
if(reader.Get_Cur_Sum()==0)
cout<<"你的借阅列表为空"<<endl;
else
reader.Print_Bro_Book();
break;
case 3:
cout<<"输入要检索的书的名字:";
cin>>name;
if(BDase.Search_Book(name,book,pos))
{
cout<<"检索成功,该书的基本信息如下:"<<endl;
book.Print();
cout<<"是否借阅该书(Y/N):";
char ch;
cin>>ch;
if(ch=='Y'||ch=='y')
{
if(reader.Bro_Book(book))
cout<<"借阅成功"<<endl;
}
}
else
{
cout<<"检索的书籍不存在"<<endl;
}
break;
case 4:
cout<<"输入要借阅的书的名字:";
cin>>name;
if(BDase.Search_Book(name,book,pos))
{
if(reader.Bro_Book(book))
cout<<"借阅成功"<<endl;
else
cout<<"借阅失败"<<endl;
}
else
{
cout<<"该书不存在"<<endl;
}
//reader.Read();
break;
case 5:
cout<<"输入要归还的书的名字:";
cin>>name;
if(BDase.Search_Book(name,book,pos))
{
if(reader.Re_Book(book))
cout<<"归还成功"<<endl;
}
else
{
cout<<"该书不存在"<<endl;
}
break;
case 6:
RDase.Set_Reader_For_Stu(reader);
break;
case 7:
cout<<"输入新密码: ";
cin>>newmima;
reader.Set_RMima(newmima);
for(i=0;i<zh_sum;i++)
{
if(login[i].Zhang_Hao==reader.Get_RZhangHao())
{
login[i].Mi_Ma=newmima;
break;
}
}
RDase.Update_Info(reader,reader.Get_RZhangHao());
RDase.Write_into_file();
if(Update_login_file())
cout<<"修改成功"<<endl;
break;
default:
cout<<"操作无效"<<endl;
}
}while(flag!=8);
}
void Admin_Manager()
{
int flag,pos=-1,i;
string name;
Book book;
Reader reader;
cout<<" __欢迎进入管理员操作界面__"<<endl;
do
{
cout<<"请输入你的选择: "<<endl;
cout<<" |-----------------------------------------------------|"<<endl;
cout<<" | 1:初始化书库 2:添加新书 3:检索书籍 4:删除书籍 |"<<endl;
cout<<" | 5:初始化读者库 6:检索读者 7:修改信息 8:删除读者 |"<<endl;
cout<<" | 9:显示所有书籍信息 10:显示所有读者信息 0:退出 |"<<endl;
cout<<" |-----------------------------------------------------|"<<endl;
cin>>flag;
switch(flag)
{
case 1:
if(BDase.Init_BookDabse())
cout<<"初始化完成"<<endl;
else
cout<<"初始化失败"<<endl;
break;
case 2:
cout<<"输入要添加的新书的名字:";
cin>>name;
if(BDase.Add_Book(name))
{
cout<<"添加成功"<<endl;
if(BDase.Search_Book(name,book,pos))
{
file_write.open("books.txt",ios::app);
file_write<<endl<<book.Get_BName()<<" "<<book.Get_BNum()<<" "<<book.Get_Sum();
file_write.close();
}
}
break;
case 3:
cout<<"输入要检索的书籍的名字:";
cin>>name;
if(BDase.Search_Book(name,book,pos))
{
cout<<"检索成功,该书基本信息如下:"<<endl;
book.Print();
}
else
{
cout<<"检索的书籍不存在"<<endl;
}
break;
case 4:
cout<<"输入要删除的书籍的名字:";
cin>>name;
if(BDase.Del_Book(name))
{
cout<<"删除成功"<<endl;
BDase.Write_into_file();
}
break;
case 5:
if(RDase.Init_ReaderDbase())
cout<<"初始化成功"<<endl;
else
cout<<"初始化失败"<<endl;
break;
case 6:
cout<<"输入你要检索的读者的名字:";
cin>>name;
if(RDase.Search_Reader(name,reader,pos))
{
cout<<"检索成功,该读者基本信息如下:"<<endl;
reader.Print();
}
else
cout<<"该读者不在库中"<<endl;
break;
case 7:
cout<<"输入你要修改的读者的名字:";
cin>>name;
if(RDase.Search_Reader(name,reader,pos))
{
RDase.Set_Reader_For_Adm(reader);
}
else
{
cout<<"该读者不存在,修改操作失败"<<endl;
}
break;
case 8:
cout<<"输入要删除的读者的名字:";
cin>>name;
if(RDase.Search_Reader(name,reader,pos))
{
RDase.Del_Reader(reader);
if(RDase.Write_into_file())
cout<<"删除成功"<<endl;
}
else
{
cout<<"该读者不存在,删除操作失败"<<endl;
}
break;
case 9:
BDase.Print_All();
break;
case 10:
RDase.Print_All();
break;
case 0:
cout<<"谢谢使用"<<endl;
break;
default:
cout<<"操作无效"<<endl;
}
}while(flag!=0);
}
//注册函数
void Register()
{
char ch;
int pos;
string zhanghao,mima;
string name,num,birthday,sex,pro;
Reader reader;
lala:cout<<"请输入要注册的帐号:";
cin>>zhanghao;
if(Search_the_ZH(zhanghao,pos))
{
cout<<"该帐号已经存在,是否重新输入(Y/N)?"<<endl;
cin>>ch;
if(ch=='Y')
goto lala;
else
return;
}
else
{
if(zh_sum>100)
{
cout<<"帐号库满,不可再注册"<<endl;
return ;
}
cout<<"输入密码:";
cin>>mima;
login[zh_sum].Zhang_Hao=zhanghao;
login[zh_sum].Mi_Ma=mima;
file_write.open("login.txt",ios::app);
file_write<<endl<<login[zh_sum].Zhang_Hao<<" "<<login[zh_sum].Mi_Ma;
file_write.close();
zh_sum++;
reader.Set_RZhanghao(zhanghao);
reader.Set_RMima(mima);
cout<<"____接下来按照提示输入个人信息_____"<<endl;
cin.clear();
cout<<"输入你的名字:";
cin>>name;
reader.Set_RName(name);
cout<<"输入你的学号:";
cin>>num;
reader.Set_RNum(num);
cout<<"输入你的性别:";
cin>>sex;
reader.Set_RSex(sex);
cout<<"输入你的生日:";
cin>>birthday;
reader.Set_RBirth(birthday);
cout<<"输入你的专业:";
cin>>pro;
reader.Set_RPro(pro);
file_write.open("reader.txt",ios::app);
file_write<<endl<<zhanghao<<" "<<mima<<" "<<name<<" "<<num<<" "<<sex<<" "
<<birthday<<" "<<pro;
file_write.close();
RDase.Add_Reader(reader);
cout<<"注册完成"<<endl;
}
}
//主函数文件
#include <iostream>
#include <string>
using namespace std;
#include "book.h"
#include "reader.h"
#include "bk_dbase.h"
#include "rd_dbase.h"
#include "main.h"
int main()
{
int flag1,flag2;
int pos=-1;
char ch;
string zhanghao,mima;
Reader reader;
INit_Login();
do
{
cout<<"输入你的选择"<<endl;
cout<<" |||||||||||||||||||||||||||||||"<<endl;
cout<<" | 1:登录 2:学生注册 3:退出 |"<<endl;
cout<<" |||||||||||||||||||||||||||||||"<<endl;
cin>>flag1;
switch(flag1)
{
case 1:
lp:cout<<"选择登录身份:"<<endl;
cout<<" |||||||||||||||||||||||||||||"<<endl;
cout<<" | 1:学生 2:管理员 3:退出 |"<<endl;
cout<<" |||||||||||||||||||||||||||||"<<endl;
cin>>flag2;
switch(flag2)
{
case 1:
cout<<"输入帐号:";
cin>>zhanghao;
if(Search_the_ZH(zhanghao,pos))
{
loop:cout<<"输入密码:";
cin>>mima;
if(Search_the_MM(pos,mima))
{
if(RDase.Search_ZhangHao(zhanghao,reader))
Student_Manager(reader);
else
cout<<"拥有该该帐号的不存在"<<endl;
}
else
{
cout<<"密码错误,是否重新输入(Y/N)?"<<endl;
cin>>ch;
if(ch=='Y')
goto loop;
}
}
else
{
cout<<"账号不存在"<<endl;
}
break;
case 2:
cout<<"输入管理员专属帐号:";
cin>>zhanghao;
if(zhanghao != Adminidtrator.Zhang_Hao)
{
cout<<"帐号无效,88"<<endl;
}
else
{
lop:cout<<"输入管理员密码:";
cin>>mima;
if(mima != Adminidtrator.Mi_Ma)
{
cout<<"密码错误,是否重新输入(Y/N)?"<<endl;
cin>>ch;
if(ch=='Y')
goto lop;
}
else
{
Admin_Manager();
}
}
break;
case 3:
cout<<"谢谢使用"<<endl;
break;
default:
cout<<"选择无效"<<endl;
goto lp;
}
break;
case 2:
cout<<" |||||||||||||||||||||||||||"<<endl;
cout<<" | 欢迎进入注册界面 |"<<endl;
cout<<" |||||||||||||||||||||||||||"<<endl;
Register();
break;
case 3:
cout<<"谢谢使用"<<endl;
break;
default:
cout<<"操作无效"<<endl;
}
}while(flag1!=3);
return 0;
}