肇庆学院oj c++习题代码 代码仅供参考请勿照搬 否则你和我oj账号都得被封号三周
Description
定义哺乳动物类 Mammal,有 age(int)和 weight(double)两个数据成员,再由此派生出狗类 Dog,有 color(string)。创建一个 Dog 类的对象
Input
你写的代码放在这里
int main() {
Dog d;
d.setAge( 4 );
d.setWeight( 12 );
d.setColor( "Black" );
cout << d.getAge() << endl;
cout << d.getWeight() << endl;
cout << d.getColor() << endl;
d.speak();
return 0;
}
Output
见输出样例
Sample Input
NULL
Sample Output
Constructor in Mammal. <---- 这行由基类输出
Constructor in Dog. <---- 这行由派生类输出
4
12
Black
Dog sound wang,wang,wang!
Destructor in Dog. <---- 这行由派生类输出
Destructor in Mammal. <---- 这行由基类输出
#includeusing namespace std; class Mammal{ protected: int age; double weight; public: Mammal(){ cout<< "Constructor in Mammal."<



