我想编一个图书管理系统:
我想编一个图书管理系统:
我设计里一个基类:object
book类:public object
可是编译为马说从定义类:object??
程序如下:
//object.h
/////////////////////////////////////////////////////////////////////////////////////
/////////////
/////// this is base class ! book class,reader class and librarian class from
lllllobject!!
///////Attribute: index,name!
///////operator: Getname,Setname!
///////
///////2004.5.7 zk
///////
/////////////////////////////////////////////////////////////////////////////////////
/////////////
#include<iostream>
#include<string>
using namespace std;
class object
{
private:
int index;
string name;
public:
object();
object(int,string);
// ~object();i can not write code !!so bad!!dont forget it!!
virtual string Getname();
virtual int Getindex();
virtual const object& Getobject();
virtual void Setname(string);
virtual void Setindex(int);
void Setobject(const object);
const object& operator=(const object& );
};
//object.cpp
#include<iostream>
#include<string>
#include"object.h"
using namespace std;
object::object()
{
index=-1;
name ="无";
}
object::object(int i,string n):index(i),name(n)
{}
int object::Getindex()
{return index;}
string object::Getname()
{return name;}
const object& object::Getobject()
{return *this;}
void object::Setindex(int i)
{index=i;}
void object::Setname(string n)
{name=n;}
void object::Setobject(const object o)
{*this=o;}
const object& object::operator=(const object& o)
{
index=o.index;
name=o.name;
return *this;
}
//book.h
/////////////////////////////////////////////////////////////////////////////////////
////////////
//////this is book class! public:object!
//////Attribute:index,bookname,writername,publishing company ,state
(borrow),remark,CDROM,Filename
//////operator:Checkout,ShowData,Setbookname,Setindex,Set..
//////Getbookename.........Get..
//////2004.5.7 zk
/////////////////////////////////////////////////////////////////////////////////////
////////////
#include<iostream>
#include<string>
#include"object.h"
using namespace std;
class book :public object
{
private:
// int index;
// string bname;
string wname;
string pubcomname;
bool state;
string remark;
bool CDROM;
//static const char FileName[15];
public:
book();
book(int i,string bookname,string writername,string publishcompany,bool
s,bool CDROM,string r);
book(int i,string bookname,string writername,string publishcompany,bool s,bool
CDROM);
//~book();
void Setindex(int);
void Setbookname(string);
void Setwritername(string);
void Setpublishcompany(string);
void Setstate(bool);
void SetCDROM(bool);
void Setremark(string);
int Getindex(void);
string Getbookname(void);
string Getwritername(void);
string Getpublishcompany(void);
bool Getstate(void);
bool GetCDROM(void);
string Getremark(void);
void CheckOut();
};
//const char book::FileName[15]="Book.txt";
//const char *book::GetFileName();
//book.cpp
#include<iostream>
#include<string>
#include"object.h"
#include"book.h"
using namespace std;
book::book()
{
object() ;
// index=-1;
// bname="无";
wname="无";
pubcomname="无";
state=0;
remark="三无";
CDROM=0;
}
book::book(int i,string bookname,
string writername,string publishcompany,
bool s,bool c,string r)
{
object(i,bookname) ;
//index=i;
// bname=bookname;
wname=writername;
pubcomname=publishcompany;
state=s;
remark=r;
CDROM=c;
}
book::book(int i,string bookname,string writername,string publishcompany,bool s,bool
c)
{
object(i,bookname) ;
// index=i;
// bname=bookname;
wname=writername;
pubcomname=publishcompany;
state=s;
remark="";
CDROM=c;
}
void book::Setindex(int i)
{object::Setindex(i);}
void book::Setbookname(string n)
{object::Setname(n);}
void book::Setwritername(string w)
{wname=w;}
void book::Setpublishcompany(string pc)
{pubcomname=pc;}
void book::Setstate(bool s)
{state=s;}
void book::SetCDROM(bool CD)
{CDROM=CD;}
void book::Setremark(string r)
{remark=r;}
int book::Getindex(void)
{return object::Getindex();}
string book::Getbookname(void)
{
//return bname;
return object::Getname();
}
string book::Getwritername(void)
{return wname;}
string book::Getpublishcompany(void)
{return pubcomname;}
bool book::Getstate(void)
{return state;}
bool book::GetCDROM(void)
{return CDROM;}
string book::Getremark(void)
{return remark;}
void book::CheckOut()
{
if (state==0)
throw("Book is not in library!");
state=0;
}