没有合适的资源?快使用搜索试试~ 我知道了~
图书馆管理系统C++代码.doc
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 155 浏览量
2022-06-21
10:04:29
上传
评论
收藏 75KB DOC 举报
温馨提示
试读
15页
图书馆管理系统C++代码
资源推荐
资源详情
资源评论
#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("book.txt",ios::in); //打开文件
while (1)
{
file.read((char *)&b,sizeof(b));
if (!file) break;
top++;
btarray[top] = b;
}
file.close(); //关闭文件
}
~bdatabase() //析构函数, 将 btarray[]写到 book.txt 文件中
{
fstream file("book.txt",ios::out);
for (int i=0;i<=top;i++)
{
if (btarray[i].b_del==1)
file.write((char *)&btarray[i],sizeof(btarray[i]));
}
file.close();
}
void addbooks() //往图书数据库中加图书
{
book bk;
int no;
char bname[20];
cout<<"请输入书号: ";
cin>>no;
cout<<endl<<"请输入书名: ";
cin>>bname;
cout<<endl;
bk.b_flag=1;
bk.addbook(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,"借出");
剩余14页未读,继续阅读
资源评论
oligaga
- 粉丝: 50
- 资源: 2万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功