#include<iostream.h>
#include<conio.h> //控制台数据输入输出的函数
#include<fstream.h>//文件流
#include<iomanip.h> //控制数据输出格式
#include<string.h>
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
fenlei[20];
//分类号
char
cbs[20];
//出版社
int
cbtime;
//出版时间
double
bookprice;
//图书价格
int
onshelf;
//是否再架 1:再架 2:已借
public
:
Book(){;}
char
*getname()
{
//获取书名
return
name;
}
char
*getauthorname()
{
//获取作者名
return
author;
}
char
*getfenlei()
{
//获取分类号
return
fenlei;
}
char
*getcbsname()
{
//获取出版社名
return
cbs;
}
int
getcbtime()
{
//获取出版时间
return
cbtime;
}
double
getbookprice()
{
//获取图书价格
return
bookprice;
}
int
getno()
{
//获取图书编号
return
no;
}
int
gettag()
{
//获取删除标记
return
tag;
}
void
setname(
char
na[])
{
//设置书名
strcpy
(name,na);
}
void
setauthorname(
char
aa[])
{
//设置作者名
strcpy
(author,aa);
}
void
setfenlei(
char
fe[])
{
//设置分类号
strcpy
(fenlei,fe);
}
void
setcbs(
char
ca[])
{
//设置出版社
strcpy
(cbs,ca);
}
void
setcbtime(
int
time
)
{
//设置时间
cbtime=
time
;
}
void
setbookprice(
double
price)
{
//设置图书价格
bookprice=price;
}
void
setonshelf(
int
oa)
{
onshelf=oa;
}
void
delbook()
{
//删除图书
char
i;
cout<<
"确定删除吗?Y/N ?"
<<endl;
cin>>i;
if
(i==
'y'
||i==
'Y'
)
tag=1;
}
void
addbook(
int
n,
char
*na,
char
*aa,
char
*fe,
char
*ca,
int
time
,
double
price,
int
oa)
{
//增加图书
tag=0;
no=n;
strcpy
(name,na);
strcpy
(author,aa);
strcpy
(cbs,ca);
strcpy
(fenlei,fe);
cbtime=
time
;
bookprice=price;
onshelf=oa;
}
int
borrowbook()
{
//借书操作
if
(onshelf>0)
{
onshelf--;
return
1;
}
return
0;
}
void
retbook()
{
//还书操作
onshelf++;
}
void
disp()
{
//输出图书
cout<<setw(3)<<no<<setw(10)<<name<<setw(10)<<author<<setw(10)<<fenlei<<setw(15)<<cbs<<setw(10)<<cbtime<<setw(10)<<bookprice<<setw(10)<<onshelf<<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()
{
//全删
char
i;
cout<<
"确定全部删除吗?Y/N ?"
<<endl;
cin>>i;
if
(i==
'y'
||i==
'Y'
)
top=-1;
}
int
addbook(
int
n,
char
*na,
char
*aa,
char
*fe,
char
*ca,
int
time
,
double
price,
int
oa)
{
//增加图书
Book *p=query1(n);
if
(NULL==p)
{
top++;
book[top].addbook(n,na,aa,fe,ca,
time
,price,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(3)<<
"编号"
<<setw(10)<<
"书名"
<<setw(10)<<
"作者"
<<setw(10)<<
"分类号"
<<setw(15)<<
"出版社"
<<setw(10)<<
"出版时间"
<<setw(10)<<
"图书价格"
<<setw(10)<<
"存量"
<<endl;
e=&book[i];
e->disp();
r++;
}
if
(r==0)
cout<<