當前位置:編程學習大全網 - 編程軟體 - 這道C++編程題怎麽做?如圖所示,求大神解答~

這道C++編程題怎麽做?如圖所示,求大神解答~

#include<iostream>

using?namespace?std;

class?Animal{

private:

int?m_wight;

public:

Animal(int?w){

m_wight=w;

}

void?getWight(){

?cout<<"my?wight?is?"<<m_wight<<"."<<endl;

}

};

class?Horse:public?Animal{

public:

Horse(int?w):Animal(w){

}

void?run(){

cout<<"i?can?run!"<<endl;

}

};

class?Bird:public?Animal{

public:

Bird(int?w):Animal(w){

}

void?fly(){

cout<<"i?can?fly!"<<endl;

}

};

class?Pegasue:public?Horse,public?Bird{

public:

Pegasue(int?w):Horse(w),Bird(w){

}

void?print(){

cout<<"I'm?a?Pegasue!"<<endl;

Horse::getWight();

Horse::run();

Bird::fly();

}

};

int?main(){

int?wight;

cin>>wight;

Pegasue?p1(wight);

p1.print();?

}

Dev C++ 測試通過

  • 上一篇:c語言編程焦慮,答案只有20分。...
  • 下一篇:弗蘭克的數控編程示例
  • copyright 2024編程學習大全網