#include
#include
using namespace std;
//把所有代码拷贝到vc6或者visual studio 2005中编译运行即可
//我已经编译运行成功了
//虚基类
class Med
{
protected:
string title; //名称
public:
virtual void print() const=0; //纯虚函数
virtual string id() const=0; //纯虚函数
};
//子类
class Book:public Med
{
private:
string author;//作者
string pub;//出版社
string isbn;//书号
public:
Book(){} //默认构造函数
Book(const char *pauthor,const char *ptitle,const char *ppub,const char *pisbn )
{
author=pauthor;
title=ptitle;
pub=ppub;
isbn=pisbn;
}
void print() const
{
cout<
string id() const
{
return isbn;
}
};
class CD:public Med
{
private:
string composer;//制作者
string make;//介质形式
string number;//编号
public:
CD(){};
CD(const char *ptitle,const char *pcomposer,const char *pmake,const char *pnumber)
{
title=ptitle;
make=pmake;
composer=pcomposer;
number=pnumber;
}
void print() const
{
cout<
string id() const
{
return make+number;
}
};
class Mag:public Med
{
private:
string issn;//杂志编号
string pub;//出版者
int volume;//卷
int number;//号
public:
Mag(){}
Mag(const char *ptitle,const char *ppub,const char *pissn,const int ivolume,const int inumber)
{
title=ptitle;
pub=ppub;
issn=pissn;
volume=ivolume;
number=inumber;
}
void print() const
{
cout<
string id() const
{
return issn;
}
};
int main()
{
Book book("张三", "C++ 语言程序设计", "清华大学出版社", "0-000-00000-1");
Mag mag("辨析C/C++编程模式", "清华大学出版社", "0000-000X", 020, 01);
CD cd("C++源代码", "清华大学出版社", "ARCHIV", "000001");
book.print();
cout << "\tid: " << book.id() << endl;
mag.print();
cout << "\tid: " << mag.id() << endl;
cd.print();
cout << "\tid: " << cd.id() << endl;
return 0;
}