• 图书管理系统(C++).

    define StrNum 20 #define Type 20 #include <iostream> #include <iomanip> #include <string> #include <fstream> //输入/输出文件流类 using namespace std; const int Maxb=100; //最多可存储的图书 class Book { private: int tag; //删除标记 int num; //图书编号 int add; //增加标记 char number[StrNum]; //编号 char name[StrNum]; //书名 char kind[Type]; //图书类型 public: Book(){} char getkind() //获取图书类型 { return kind[Type]; } char getname() //获取书名 { return name[StrNum]; } int getnum() //获取图书编号 { return num; } int gettag() //获取删除标记 { return tag; } void setname(char na[]) //设置书名 { strcpy(name,na); } void setkind(char kin[]) //设置类型 { strcpy(kind,kin); } void delbook() //删除图书 { tag=1; } void addbook(int n,char *na,char *kin) //增加图书 { tag=0; num=n; strcpy(name,na); strcpy(kind,kin); } void disp() //输出图书 { cout.flags (ios::left); //设置对齐的标志位为左 cout<<setw(15)<<num<<setw(20)<<name<<setw(15)<<kind<<endl; } }; /*****************************************************************************************/ class BDatabase { private: int top; //图书记录指针 Book book[Maxb]; //图书记录 public: BDatabase() //构造函数,将book.txt读到book[]中 { Book b; top=-1; fstream file("book.txt",ios::in); while (1) { file.read((char *)&b,sizeof(b)); if (!file) break; top++; book[top]=b; } file.close(); } void clear() //全删 { top=-1; } int addbook(int n,char *na,char *kin) //增加图书 { Book *p=query(n); if(NULL==p) { top++; book[top].addbook(n,na,kin); return 1; } return 0; } Book *query(int bookid) //查找图书 { for (int i=0;i<=top;i++) if (book[i].getnum()==bookid &&book[i].gettag()==0) { return &book[i]; } return NULL;

    4
    211
    255KB
    2013-06-21
    10
上传资源赚积分or赚钱