文档详情

C++图书管理系统代码.pdf

发布:2019-01-22约1.86万字共27页下载文档
文本预览下载声明
一些基本的功能: 1:添加图书以及图书编号 2:能够实行基本的借书还还书的功能。 3: 删除图书信息等 #include iostream #include iomanip #include string #include fstream//输入输出文件流类/ using namespace std; const int Maxr 100;//最多的读者 const int Maxb 100;//最多的图书 const int Maxzf 5;//每位读者最多借五本书 //读者类实现对读者的信息的描述, class Reader { private: int tag; //删除标记 1:已删 0:未删 int no; //读者编号 char name[10]; //读者姓名 int zfbook[Maxzf];//所借图书 public: Reader() {} char*getname(){return name;} //获取姓名 int gettag() {returntag;} //获取删除标记 int getno(){return no;} //获取读者编号 void setname(char na[]) //设置姓名 { strcpy(name,na); - 1- } void delbook(){ tag 1; }//设置删除标记 1:已删 0:未删 void addreader(int n,char*na)//增加读者 { tag 0; no n; strcpy(name,na); for(int i 0;iMaxzf;i++) zfbook[i] 0; } void zfrowbook(int bookid)//借书操作 { for(int i 0;iMaxzf;i++) { if (zfbook[i] 0) { zfbook[i] bookid; return; } } } int retbook(int bookid)//还书操作 { for(int i 0;iMaxzf;i++) { if(zfbook[i] bookid) { zfbook[i] 0; 2 return 1; } } return 0; } void disp()//读出读者信息 { cout setw(5) no setw(10) name借书编号:[; for(int i 0;iMaxzf;i++) if(zfbook[i]! 0) cout zfbook[i] |; cout ]endl; } }; //读者类库,实现建立读者的个人资料 class RDatabase { private: int top; //读者记录指针 Reader read[Maxr];//读者记录 public: RDatabase() //构造函数,将reader.txt 读到read[]中 { Readers; top -1; fstreamfile(reader.txt,ios::in);//打开一个输入文件 while (1) { 3 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; } Reade
显示全部
相似文档