大佬们能不能帮忙看一下这个程序哪里还不对??
题目
补充程序 :
1、实现Mammal类的方法
2、由Mammal类派生出Dog类,在Dog类中增加itsColor成员(COLOR类型)
3、Dog类中增加以下方法:
constructors: Dog()、Dog(int age)、Dog(int age, int weight)、Dog(int age, COLOR color)、 Dog(int age, int weight, COLOR color)、~Dog()
accessors: GetColor()、SetColor()
Other methods: WagTail()、BegForFood() ,并实现以上这些方法 。
提示:类似Speak()、WagTail()这些动作,函数体可以是输出一句话。比如:Mammal is spaeking... , The Dog is Wagging its tail...
4、补充主函数的问号部分,并运行程序,检查输出是否合理。
我的程序
#include<iostream>
using namespace std;
enum COLOR{ WHITE, RED, BROWN, BLACK, KHAKI };
class Mammal
{
public:
int n,m;
//constructors
Mammal();
Mammal(int age);
~Mammal();
//accessors
int GetAge() const
{
return n;
}
void SetAge(int n)
{
this->itsAge =n;
}
int GetWeight() const
{
return m;
}
void SetWeight(int m)
{
this->itsWeight=m;
}
//Other methods
void Speak() const;
void Sleep() const;
protected:
int itsAge;
int itsWeight;
};
void Mammal::Speak()const
{
cout<<"Mammal is speaking..."<<endl;
}
class Dog:public Mammal
{
public:
Dog();
Dog(int age);
Dog(int age, int weight);
Dog(int age, COLOR color)
{
SetAge(n);
this->itsAge =age;
}
Dog(int age, int weight, COLOR color)
{
this->itsWeight =weight;
}
~Dog();
void WagTail()
{
cout<<"The dog is wagging its tail..."<<endl;
}
private:
COLOR itsColor;
};
int main()
{
Dog Fido;
Dog Rover(5);
Dog Buster(6, 8);
Dog Yorkie(3, RED);
Dog Dobbie(4, 20, KHAKI);
Fido.Speak();
Rover.WagTail();
cout << "Yorkie is " <<Yorkie.GetAge ()<< " years old." << endl;
cout << "Dobbie weighs " <<Dobbie.GetWeight() << " pounds." << endl;
return 0;
}
补充程序 :
1、实现Mammal类的方法
2、由Mammal类派生出Dog类,在Dog类中增加itsColor成员(COLOR类型)
3、Dog类中增加以下方法:
constructors: Dog()、Dog(int age)、Dog(int age, int weight)、Dog(int age, COLOR color)、 Dog(int age, int weight, COLOR color)、~Dog()
accessors: GetColor()、SetColor()
Other methods: WagTail()、BegForFood() ,并实现以上这些方法 。
提示:类似Speak()、WagTail()这些动作,函数体可以是输出一句话。比如:Mammal is spaeking... , The Dog is Wagging its tail...
4、补充主函数的问号部分,并运行程序,检查输出是否合理。
我的程序
#include<iostream>
using namespace std;
enum COLOR{ WHITE, RED, BROWN, BLACK, KHAKI };
class Mammal
{
public:
int n,m;
//constructors
Mammal();
Mammal(int age);
~Mammal();
//accessors
int GetAge() const
{
return n;
}
void SetAge(int n)
{
this->itsAge =n;
}
int GetWeight() const
{
return m;
}
void SetWeight(int m)
{
this->itsWeight=m;
}
//Other methods
void Speak() const;
void Sleep() const;
protected:
int itsAge;
int itsWeight;
};
void Mammal::Speak()const
{
cout<<"Mammal is speaking..."<<endl;
}
class Dog:public Mammal
{
public:
Dog();
Dog(int age);
Dog(int age, int weight);
Dog(int age, COLOR color)
{
SetAge(n);
this->itsAge =age;
}
Dog(int age, int weight, COLOR color)
{
this->itsWeight =weight;
}
~Dog();
void WagTail()
{
cout<<"The dog is wagging its tail..."<<endl;
}
private:
COLOR itsColor;
};
int main()
{
Dog Fido;
Dog Rover(5);
Dog Buster(6, 8);
Dog Yorkie(3, RED);
Dog Dobbie(4, 20, KHAKI);
Fido.Speak();
Rover.WagTail();
cout << "Yorkie is " <<Yorkie.GetAge ()<< " years old." << endl;
cout << "Dobbie weighs " <<Dobbie.GetWeight() << " pounds." << endl;
return 0;
}
...全文
相关推荐
电压不对称度计算程序的开发和应用
本文主要探讨了电压不对称度计算程序的开发与应用,旨在通过提升检验流程的速度和检测效率。电压不对称度是电力系统中衡量三相电能质量的重要指标,它反映了电源或线路在正常运行时,各相电压之间的不平衡程度。传统
C# 中的??操作符浅谈
Name`也会是null,然后`??`操作符会返回"Unknown"。`??`操作符的一个重要特性是它只会在左操作数为null时才检查右操作数。
程序_对称短路不对称短路基本程序_
本文详细介绍了电力系统中三相短路和不对称短路的计算方法。首先定义了节点阻抗和导纳矩阵,然后计算了短路点的自阻抗和互阻抗,以及短路电流。接着,通过节点电压和阻抗计算了支路电流。在不对称短路部分,分别计算
c# 操作符?? null coalescing operator
这个操作符允许程序员在表达式中优雅地处理null值,避免了冗长的条件检查。以下是关于`??`操作符的详细解释以及它在不同场景下的应用。1. **基本用法** `??
经典米散射(MIE散射)的MATLAB程序,计算散射系数、吸收系数、消光系数、后向散射系数、不对称因子。
**不对称因子**(g因子):不对称因子是衡量散射光分布对称性的参数,它描述了散射光强分布的偏斜程度。g值接近1表示散射主要发生在垂直于入射光的方向上,接近-1则表示主要在侧向。7.


