file_reader.read((char*)&readerzlk[r], sizeof(readerzlk[r]));
if (r >= 50)
{
cout<<"读者库已满!"<<endl;
break;
}
}
cout<<"初始化读者库成功……"<<endl;
}
file_reader.close();
}
void CSHbook() //初始化书籍库函数(注释同读者库一样)
{
file_book.open("bookfile.txt", ios::in);
file_book.read((char*)&library[0], sizeof(library[0]));
if (strlen(library[0].getcode()) == 0)
{
cout<<"书籍库信息为空,请建立书籍信息。"<<endl;
}
else
{
while(!file_book.eof())
{
b++;
file_book.read((char*)&library[b], sizeof(library[b]));
if (b >= 100)
{
cout<<"书籍库已满!"<<endl;
break;
}
}
cout<<"初始化书籍库成功……"<<endl;
}
file_book.close();
}
void CSHrbb() //初始化借书库
{
file_rbb.open("rbb.txt", ios::in);
file_rbb.read((char*)&rbb[0], sizeof(rbb[0]));
if (strlen(rbb[0].readercode) == 0)
{
cout<<"借书库信息为空,暂时无借书情况。"<<endl;
}
else
{
while (!file_rbb.eof())
{
t++;
file_rbb.read((char*)&rbb[t], sizeof(rbb[t]));
if (t >= 100)
{
cout<<"借书库已满,请速让读者归还书籍。"<<endl;
break;
}
}
cout<<"初始化借书库成功……"<<endl;
}
file_rbb.close();
}
void borrowbook() //借书函数
{
int d = 0; //逻辑判断值
int i = 0;
char flag = 'y';
readerborrowbook temp;
while (flag == 'y' || flag == 'Y')
{
temp.borrowbook();
for (i = 0; i < r; i++)//判断有无此读者编号
{
if (strcmp(temp.readercode, readerzlk[i].getcode()) == 0)
{
d = 1; //为1则有此编号,否则无此编号
break;
}
}
if (d == 0)
{
cout<<"对不起!您的编号不存在!"<<endl;
return;
}
d = 0; i = 0; //恢复初始值,进行书的编号的判断
for (i = 0; i < b; i++) //判断有无此书籍编号
{
if (strcmp(temp.bookcode, library[i].getcode()) == 0)
{
d = 1; //同上
break;
}
}
if (d == 0)
{
cout<<"对不起!我们这里没有此书籍!"<<endl;
return;
}
//判断书籍是否借出,本意是想通过".flag"是否等于'Y'或'y'来判断书是否借出的,可是总是判断不成功。
//本意是if (library[i].flag == 'Y' || library[i].flag == 'y')
// {cout<<"非常抱歉,此书已经租出。"<<endl;return;}
int j = 0;
for (j = 0; j < t; j++)
{
if (strcmp(temp.bookcode, rbb[j].bookcode) == 0)
{
cout<<"非常抱歉,此书已经租出。"<<endl;
return;
}
}
library[i].getflag();
if (library[i].flag == 'Y' || library[i].flag == 'y')
{
file_rbb.open("rbb.txt", ios::app);
library[i].print();
rbb[t] = temp;
file_rbb.write((char*)&rbb[t], sizeof(rbb[t]));
t++;
cout<<"借书成功!请按时归还!"<<endl;
file_rbb.close();
}
else
{
cout<<"您不中意此书吗?借书未成功。"<<endl;
}
cout<<"要继续租书吗?[Y/N]";
cin>>flag;
}
}
void Printborrowbook() //查看借书情况函数
{
int i = 0;
for (i = 0; i < t; i++)
{
rbb[i].print();
cout<<endl;
}
}
void borrow()
{
char ch;
cout<<"1.凭证借书 2.查看借书情况 3.退出"<<endl;
cout<<"请输入功能代码:";
cin>>ch;
switch (ch)
{
case '1':
borrowbook();
break;
case '2':
Printborrowbook();
break;
case '3':
return;
break;
default:
cout<<"输入错误,请重新输入:"<<endl;
}
}
void replacebook() //还书模块
{
char bookcode[4];
int i = 0, d = 0;
cout<<"您要还的书籍的编号是:";
cin>>bookcode;
for (i = 0; i < t; i++)
{
if (strcmp(bookcode, rbb[i].bookcode) == 0)
{
d = 1; //逻辑判断,为1则租出,否则没有租出
break; //因为书籍编号具有唯一性,故退出循环