1 / 23
文档名称:

C 图书管理.doc

格式:doc   页数:23页
下载后只包含 1 个 DOC 格式的文档,没有任何的图纸或源代码,查看文件列表

如果您已付费下载过本站文档,您可以点这里二次下载

分享

预览

C 图书管理.doc

上传人:xxj16588 2016/7/12 文件大小:0 KB

下载得到文件列表

C 图书管理.doc

相关文档

文档介绍

文档介绍:C 图书管理 C++ 求而不得, 舍而不能, 得而不惜, 这是人最大的悲哀。付出真心才能得到真心, 却也可能伤得彻底。保持距离也就能保护自己,却也注定永远寂寞。#include"" #include"" #include"" #include"" #include"" const int Maxr=100 ;// 最多的读者数 const int Maxb=100; // 最多的图书数 const int Maxbor=5; // 每位读者最多借的书 class Book {// 图书类,实现对图书的描述,图书的编号,书名,借出,还入等功能 private: int tag; // 删除标记 1: 已删 0: 未删 int no; // 图书编号 char name[20]; // 书名 char author[20];// 作者 char cbs[20]; // 出版社 int onshelf; // 是否再架 1: 再架 2: 已借 public: Book(){;} char *getname() {// 获取书名 return name; } char *getauthorname() {// 获取作者名 return author; } char *getcbsname() {// 获取出版社名 return cbs; } int getno() {// 获取图书编号 return no; } int gettag() {// 获取删除标记 return tag; } void setname(char na[]) {// 设置书名 strcpy(name,na); } void setonshelf(int oa) { onshelf=oa; } void delbook() {// 删除图书 tag=1; } void addbook(int n,char *na,char *aa,char *ca,int oa) {// 增加图书 tag=0; no=n; strcpy(name,na); strcpy(author,aa); strcpy(cbs,ca); onshelf=oa; } int borrowbook() {// 借书操作 if (onshelf>0) { onshelf--; return 1; } return 0; } void retbook() {// 还书操作 onshelf++; } void disp() {// 输出图书 cout<<setw(6)<<no<<setw(18)<<name<<setw(10)<<author<<setw(1 0)<<cbs<<setw(10)<<onshelf<<endl; } }; class BDatabase {// 图书库类,实现对图书的维护,查找,删除等 private: int top; // 图书记录指针 Book book[Maxb]; // 图书记录 public: BDatabase() {// 构造函数,将 读到 book[] 中 Book b; top=-1; fstream file("",ios::in); while (1) { ((char *)&b,sizeof(b)); if (!file) break; top++; book[top]=b; } (); } void clear() {// 全删 top=-1; } int addbook(int n,char *na,char *aa,char *ca,int oa) {// 增加图书 Book *p=query1(n); if (NULL==p) { top++; book[top].addbook(n,na,aa,ca,oa); return 1; } return 0; } Book *query1(int bookid) {// 按编号查找图书 for(int i=0;i<=top;i++) if(book[i].getno()==bookid &&book[i].gettag()==0) { return &book[i]; } return NULL; } Book *query2(char a[]) {// 按书名查找图书 Book *e; int r=0; for(int i=0;i<=top;i++) if(strcmp(book[i].getname(),a)==0 &&book[i].gettag()==0) { if(r==0) cout<<setw(6)<<"