{ Reader s; top=-1;
fstream file(\打开一个输入文件 while (1) {
file.read((char *)&s,sizeof(s)); if (!file)break; top++; read[top]=s; }
file.close(); //关闭 reader.txt }
void clear()//删除所有读者信息 { top=-1; }
int addreader(int n,char *na)//添加读者时先查找是否存在 {
Reader *p=query(n); if (p==NULL) { top++;
read[top].addreader(n,na);
return 1; } return 0; }
Reader *query(int readerid)//按编号查找 {
for (int i=0;i<=top;i++)
if (read[i].getno()==readerid && read[i].gettag()==0) {
return &read[i]; }
return NULL; }
void disp() //输出所有读者信息 {
for (int i=0;i<=top;i++) read[i].disp(); }
void readerdata();//读者库维护
~RDatabase() //析构函数,将read[]写到reader.txt文件中 {
fstream file(\for (int i=0;i<=top;i++)
if (read[i].gettag()==0)
file.write((char *)&read[i],sizeof(read[i])); file.close(); } };
void RDatabase::readerdata() {
char choice; char rname[20]; int readerid; Reader *r;
while (choice!='0') {
cout <<\读 者 维 护\\n\\n\\n\\t\\t 1 新 增\\n\\n\\t\\t 2 更 改\\n\\n\\t\\t 3 删 除\\n\\n\\t\\t 4 查 找\\n\\n\\t\\t 5 显 示\\n\\n\\t\\t 6 全 删\\n\\n\\t\\t 0 退 出\cin >> choice; switch (choice) { case '1':
cout << \输入读者编号:\cin >> readerid;
cout << \输入读者姓名:\cin >> rname;
addreader (readerid,rname); break;
case '2':
cout << \输入读者编号:\cin >> readerid; r=query(readerid); if (r==NULL) {
cout << \该读者不存在 \break; }
cout << \输入新的姓名:\cin >> rname; r->setname(rname); break; case '3':
cout << \输入读者编号:\cin >> readerid; r=query(readerid); if (r==NULL) {
cout <<\该读者不存在\break; }
r->delbook(); break;
相关推荐: