C++编程题目:
声明一个抽象类 CMed 作为基类,其中
1)包含一个 string 类型数据成员 title(名称)和两个纯虚函数 print( )和 id( )。
2)派生出 CBook 类、CCD 类和 CMag 类。
3)在 CBook 类中,包含 3 个 string 类型数据成员 author(作者)、pub(出版
社)、isbn(书号)和函数成员 print( )及 id( )。
4)在 CCD 类中,包含 3 个 string 类型数据成员 composer(制作者)、make(介
质形式)、number(编号)和函数成员 print( )及 id( )。
5)在 CMag 类中,包含 2 个 string 类型数据成员 issn(杂志编号)、pub(出版
社),两个整型数据成员 volume(卷)、number(号)和函数成员 print( )及 id( )。
6)派生类的 print( )和 id( )函数功能请自行设计。
基类和派生类的定义与初始化我已经完成,请问函数体部分和主函数内容怎么写。
#include <iostream>
using namespace std;
class CMed {
public:
CMed(string title);
virtual void ptint() = 0;
virtual void id() = 0;
private:
string _title;
};
CMed::CMed(string title) {
_title = title;
}
class CBook:public CMed {
public:
CBook(string author, string pub, string isbn, string title);
void print() {}
void id() {}
private:
string _author;
string _pub;
string _isbn;
string _title;
};
CBook::CBook(string author, string pub, string isbn, string title):CMed(title)
{
_author = author;
_pub = pub;
_isbn = isbn;
_title = title;
}
class CCD:public CMed {
public:
CCD(string composer, string make, string number, string title);
void print() {}
void id(){}
private:
string _composer;
string _make;
string _number;
string _title;
};
CCD::CCD(string composer, string make, string number, string title):CMed(title)
{
_composer = composer;
_make = make;
_number = number;
_title = title;
}
//在 CMag 类中,包含 2 个 string 类型数据成员 issn(杂志编号)、pub(出版社),两个整型数据成员 volume(卷)、number(号)和函数成员 print()及 id()。
class CMag :public CMed {
public:
CMag(string issn, string pub, int volume, int number,string title);
void print(){}
void id(){}
private:
string _issn;
string _pub;
int _number;
int _volume;
};
CMag::CMag(string issn, string pub, int volume, int number, string title) :CMed(title)
{
_issn = issn;
_pub = pub;
_number = number;
_volume = volume;
}
int main()
{
return 0;
}