这边有!
#include
#include
#include
#include
struct bookData
{
int booknumber;
char bookname[30];
int store;
};
struct Person
{
char name[20];
char studynumber[10];
int count;
bookData Rbook[2];
//bookData Rbook;
};
class History
{
public:
History(fstream& a){readerbook=a;}
void writehistory();
void readhistory(fstream&);
private:
fstream readerbook;
};
class Liberian;
void Find(fstream&);
void CreateTxt(fstream&);
class Reader
{
friend Liberian;
public:
Reader(fstream&);
void print();
void handlebook(fstream&);
void change();
bool findreader();
void Addreader();
void deletereader();
private:
fstream file;
Person person;
};
class Liberian
{
public:
Liberian(char *,char *);
void changeReader(Reader&);
void selfprint();
void Append(fstream&);
private:
char workname[20];
char worknumber[20];
};
int main()
{
fstream bookRecord(" book.dat",ios::in| ios::out);
if(!bookRecord)
{
cerr<<" Can't open,try again!"<
}
fstream readerRecord("reader.dat",ios::in|ios::out);
if(!readerRecord)
{
cerr<<" Can't open,try again!"<
}
int choice;
int key; Reader reader(readerRecord);//读者管理系统
Liberian liberian("李天","123456");//图书管理员
History rec(readerRecord);//声明显示历史记录类
while(1)
{
cout<<" 请输入您的选择:\n\n"
<<"1--图书管理员\n"
<<"2--读者系统\n"
<<"0--结束程序\n";
cin>>choice;
switch(choice)
{
case 1:
{
cout<<" Hello,图书管理员:\n";
liberian.selfprint();cout<
<<"2-- 改变读者的属性\n"
<<"3-- 显示历史记录\n"
<<"0-- 返回\n";
cin>>key;
switch(key)
{
case 1:
liberian.Append(bookRecord);
break;
case 2:
liberian.changeReader(reader);
break;
case 3:
rec.readhistory(readerRecord);
case 0:
break ;
}
}
break;
case 2:
{
cout<<"学生读者\n"; int iflag=1;
//reader.findreader();
cout<<"1-- 借书与还书信息\n"
<<"2-- 修改个人信息\n"
<<"0-- 返回\n";
cin>>key;
switch(key)
{
case 1:
reader.handlebook(bookRecord);
break;
case 2:
reader.change();
break;
case 0:
break;
}
}
break;
default:
return 0;
}
}
return 0;
}
//增加书籍
void Liberian::Append(fstream& storef)
{
bookData book;
int choice;
int key;
int num;
storef.seekp(0,ios::end);
int posEnd=storef.tellp();
cout<<"*************书籍入库***************"<
{
cout<<" Please enter your choice:"<
cin>>choice;
switch(choice)
{
case 1:
cout<<" 书号, 书名, 数量?"<
storef.write(reinterpret_cast
break;
case 2:
storef.seekg(0,ios::beg);
cout<<"Booknumber?\n";
cin>>key;
do{
storef.read(reinterpret_cast
}while(book.booknumber!=key&&storef.tellg()!=posEnd);
if(book.booknumber==key)
{
cout<
if(num>0)
book.store+=num;
else
{
cout<<" Invalid input"<
storef.seekp(-long(sizeof(bookData)),ios::cur);////////////////////
storef.write(reinterpret_cast
cout<<"现在书籍: "<
else
cout<<"找不到此书,请重新查阅书号是否正确!"<
case 0:
return ;
}
}
}
//书籍查询
void Find(fstream & f)
{
bookData book;
int key;
int choice;
f.seekg(0,ios::end);
int posEnd=f.tellp();
cout<<"*************书籍查询***************"<
{
cout<<" 请输入您的选择\n"
<<" 1-- 检索一本书\n"
<<"2-- 显示全部书籍\n"
<<"0-- 返回\n";
cin>>choice;
switch(choice)
{
case 1:
f.seekg(0,ios::beg);
cout<<"输入你想检索书的书号"<
do{
f.read(reinterpret_cast
}while(book.booknumber!=key&&f.tellg()!=posEnd);
if(book.booknumber==key)
cout<
cout<<"找不到此书,请重新确认!"<
case 2:
f.seekg(0,ios::beg);
do{
f.read(reinterpret_cast
cout<
break;
case 0:
return ;
}
}
}
Reader::Reader(fstream& c)
{
file=c;
Person person={"0","0",0,{{0,"0",0}, {0,"0",0}}};
}
void Reader::print()
{
cout<<"Name"<<"---"<
//操作书籍??????????????????????
void Reader::handlebook(fstream &filee)
{
int key; int choice;
bookData book; bool iflag;int num=0;
filee.seekp(0,ios::end);
int posEnd=filee.tellp();
while(!(iflag=findreader()))
{
num++;
if(num>=3)
return;
}
//cout<
{
cout<<"1-- 借书\n"
<<"2-- 还书\n"
<<"3-- 查找一本书\n"
<<"0-- 返回"<<'\n';
cin>>choice;
switch(choice)
{
case 1:
{
filee.seekp(0,ios::end);
int posEnd=filee.tellp();
if(person.count<=1)
{
cout<<" 输入你要借阅图书的书号:"<
filee.seekg(0);
do{
filee.read(reinterpret_cast
}while(book.booknumber!=key&&filee.tellp()!=posEnd);
//cout<
{
//cout<<" 找到你想借阅的图书,成功借阅!"<
if(book.store>0)
{
person.Rbook[person.count]=book;
person.count+=1;
book.store-=1;
filee.seekp(-long(sizeof(bookData)),ios::cur);
filee.write(reinterpret_cast
cout<<" 找到你想借阅的图书,成功借阅!"<
}
else
cout<<" 现在此图书已经被借完了,请耐心等待几天!"<
}
else
cout<<" 找不到你想要的图书"<
}
else
cout<<"你最多只能借2本\n\n";
}
break;
case 2:
{
bookData blankbook={0,"0",0};
//if(person.count>0)
//{
int iflag=0;
filee.seekg(0);
cout<<" 输入你想要还的书的书号:"<
for(int i=0;i<2;i++)
{
if(key==person.Rbook[i].booknumber)
{
person.Rbook[i]=blankbook;
cout<<"成功归还此书!";
iflag=1;
person.count--;
do{
filee.read(reinterpret_cast
}while(book.booknumber!=key&&filee.tellp()!=posEnd);
if(book.booknumber==key)
{
book.store+=1;
filee.seekp(-long(sizeof(bookData)),ios::cur);
filee.write(reinterpret_cast
cout<<"书籍 :"<
}
}
if(!iflag)
{
cout<<" 你没有借阅那本书,请确认!"<
// }
// else
// cout<<"你没有借书,请重新确认!\n\n";
}
break;
case 3:
Find(filee);
break;
case 0:
return;
}
}
}
void Reader::change()
{
char newname[20]; char newnumber[10];
int choice;
file.seekp(0,ios::cur);
int Posend=file.tellp(); bool iflag;int num=0;
while(!(iflag=findreader()))
{
num++;
if(num>=3)
return;
}
cout<<" 请输入你的选择!"<
<<"2--修改学号r\n"
<<"0--返回\n";
cin>>choice;
switch(choice)
{
case 1:
cout<<"输入你的新名字!\n";
cin>>newname;
strcpy(person.name,newname);
break;
case 2:
cout<<"输入你的信学号?\n";
cin>>newnumber;
strcpy(person.studynumber,newnumber);
break;
default:
break;;
}
file.seekp(-long(sizeof(Person)),ios::cur);
file.write(reinterpret_cast
cout<<"信息修改成功!"<
void Liberian::selfprint()
{
cout<<" 图书管理员 :\n"
<
Liberian::Liberian(char *a,char*b)
{
strcpy(workname,a);
strcpy(worknumber,b);
}
void Liberian::changeReader(Reader& a)
{
int choice; char newname[20];char newnumber[10];
cout<<"修改读者的数据信息!\n";
cout<<"1-- 增加一个读者\n"
<<"2-- 删除一个读者\n"
<<"0-- 结束程序\n";
cin>>choice;
switch(choice)
{
case 1:
a.Addreader();
break;
case 2:
a.deletereader();
break;
case 0:
return;
}
}
void Reader::Addreader()
{
Person temp;bookData book={0,"0",0};
file.seekp(0,ios::end);
int Posend=file.tellp();
cout<<"输入你想要增加的读者的名字"<
cout<<"新读者的学号:"<
temp.Rbook[1]=book; temp.Rbook[0]=book; temp.count=0;
file.write(reinterpret_cast
cout<<" 成功添加!"<
void Reader::deletereader()
{
file.seekp(0,ios::end);
int Posend=file.tellp();
Person person;
char name[20];
cout<<"输入要删除的读者的名字!"<
file.seekg(0);
do{
file.read(reinterpret_cast
}while(strcmp(name,person.name)&&file.tellp()!=Posend);
if(!strcmp(name,person.name))
{
bookData blankbook={0,"0",0};
Person guest={"0","0",0,{{0,"0",0},{0,"0",0}}};
file.seekp(-long(sizeof(Person)),ios::cur);
file.write(reinterpret_cast
cout<<"成功删除!"<
else
cout<<"查无此人!"<
bool Reader::findreader()
{
file.seekp(0,ios::end);
int Posend=file.tellp();
char name[20];
Person guest={"0","0",0,{{0,"0",0},{0,"0",0}}};
cout<<"输入查找人的名字!";
cin>>name;
file.seekg(0);
do{
file.read(reinterpret_cast
}while(strcmp(name,person.name)&&file.tellp()!=Posend);
if(!strcmp(name,person.name))
{
cout<<"查到此人:"<
}
else
{
cout<<"找不到此人,请重新确认!"<
}
}
//借阅历史
void History::readhistory(fstream& a)
{
readerbook=a;
char name[10]="0";
readerbook.seekp(0,ios::end);
int Posend=readerbook.tellp();
Person guest; int iflag=1;
cout<<" 书籍借阅信息如下:"<
do{
readerbook.read(reinterpret_cast
if(strcmp(guest.Rbook[1].bookname,name) || strcmp(guest.Rbook[1].bookname,name))
{
cout<
if(strcmp(guest.Rbook[i].bookname,name))
cout<
}
}while(readerbook.tellp()!=Posend);
if(iflag)
cout<<"没有读者借阅图书!"<
}
美女你很漂亮