大佬们能不能帮忙看一下这个程序哪里还不对??

夜太美。 2019-04-17 01:42:28
题目
补充程序 :

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;
}
...全文
182 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
夜太美。 2019-04-18
  • 打赏
  • 举报
回复
引用 3 楼 写代码的程序员的回复:
你把原题目发我吧,这个问号的地方是你自己补充?
enum COLOR{ WHITE, RED, BROWN, BLACK, KHAKI };class Mammal{ public: //constructors Mammal(); Mammal(int age); ~Mammal(); //accessors int GetAge() const; void SetAge(int); int GetWeight() const; void SetWeight(int); //Other methods void Speak() const; void Sleep() const; protected: int itsAge; int itsWeight;};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 " << ?? << " years old." << endl; cout << "Dobbie weighs " << ?? << " pounds." << endl; return 0;}
夜太美。 2019-04-18
  • 打赏
  • 举报
回复
引用 3 楼 写代码的程序员的回复:
你把原题目发我吧,这个问号的地方是你自己补充?
嗯嗯对 问号部分是自己补充的
  • 打赏
  • 举报
回复
你把原题目发我吧,这个问号的地方是你自己补充?
夜太美。 2019-04-17
  • 打赏
  • 举报
回复
引用 1 楼 写代码的程序员 的回复:
预期结果谁什么,输出结果是什么
对不起,刚看见 Mammal is speaking... The dog is wagging its tail... Yorkie is 3 years old. Dobbie weighs 20 pounds.
  • 打赏
  • 举报
回复
预期结果谁什么,输出结果是什么

64,636

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧