1 / 13
文档名称:

图书馆管理系统C++代码.doc

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

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

分享

预览

图书馆管理系统C++代码.doc

上传人:xgs758698 2016/3/16 文件大小:0 KB

下载得到文件列表

图书馆管理系统C++代码.doc

文档介绍

文档介绍:// : Defines the entry point for the console application. // #include <string>// 字符串头文件#include <fstream>// 文件头文件#include <iostream>// 是指标准库中输入输出流的头文件, cout 就定义在这个头文件里 using namespace std;// 使用名字空间 std const int BMAX=50; // 书最多个数// 图书管理模块// 图书类 class book { public: int no; // 图书编号 char name[20]; // 图书名称 int b_flag; //1 为在架, 2 为借出 int b_del; //1 为存在,2 为删除 public : book(){} // 构造函数 void setno(int n) { no=n; // 图书编号取值} int getno() { return no; // 返回图书编号值} void setname(char na[]) { strcpy(name, na); // 字符串复制} char* getname() { return name; // 返回图书名称} void borbook() { b_flag=2; // 借书标志} void delbook() { b_del=2; // 删除标志} void addbook(int no,char na[]) // 增加图书功能{ setno(no); setname(na); b_flag=1; b_del=1; }}; // 图书数据库类 class bdatabase { public: book btarray[BMAX]; // 图书集合 int top; public: bdatabase() { book b; top=-1; fstream file("",ios::in); // 打开文件 while (1) { ((char *)&b,sizeof(b)); if (!file) break; top++; btarray[top] = b; } (); // 关闭文件} ~bdatabase() // 析构函数, 将 btarray[] 写到 文件中{ fstream file("",ios::out); for (int i=0;i<=top;i++) { if (btarray[i].b_del==1) ((char *)&btarray[i],sizeof(btarray[i])); } (); } void addbooks() // 往图书数据库中加图书{ book bk; int no; char bname[20]; cout<<" 请输入书号: "; cin>>no; cout<<endl<<" 请输入书名: "; cin>>bname; cout<<endl; =1; (no, bname); top++; btarray[top]=bk; return; } int findbooks(int suffix) // 查找图书, 这个函数用于借书这书操作, suffix 是数组下标{ int no; cout<<" 请输入书号: "; cin>>no; for(int i=0; i<=top; i++) { if(btarray[i].no==no && btarray[i].b_del==1) { return i;}} return -1; } int findbooks() // 查找图书, 这个函数用于图书维护{ int no; char value[6]; cout<<" 请输入书号: "; cin>>no; for(int i=0; i<=top; i++) { if(btarray[i].no==no && btarray[i].b_del==1) { if(btarray[i].b_flag==1) strcpy(value," 在架"); if(btarray[i].b_flag==2) strcpy(value," 借出"); cout<<" 书号: "<<btarray[i].no<<" 书的名称: "<<btarray[i].name<<" 图书状态:"<<value<<endl; return i;}} return -1; } void editbooks() // 编辑图书{ int