文档介绍:图书馆管理系统C++代码
2
———————————————————————————————— 作者:
———————————————————————————————— 日期:
个人收集整理 勿做商业用途
个人收集整理 勿做商业用途
个人收集整理 勿做商业用途
#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[]) //增加图书功能
{
3
个人收集整理 勿做商业用途
个人收集整理 勿做商业用途
个人收集整理 勿做商业用途
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)
{
file。read((char *)&b,sizeof(b));
if (!file) break;
top++;
btarray[top] = b;
}
(); //关闭文件
}
~bdatabase() //析构函数, 将btarray[]
{
fstream file("book。txt",ios::out);
for (int i=0;i〈=top;i++)
{
if (btarray[i]。b_del==1)