你好,能帮我看一道C++的题目吗?

2024-11-28 22:38:38
推荐回答(1个)
回答1:

//---------------------------------------------------------------------------

#include
#include
#include
#include
using namespace std;

class unspotted_dog{
protected:
char breed[30];
int height;
int weight;
char colour[10];
public:
unspotted_dog(){}
unspotted_dog(char* breed,float height,float weight,char* colour)
{strcpy(this->breed,breed);

this->height=height;
this->weight=weight;

strcpy(this->colour,colour);
}
void show_breed();
};

void unspotted_dog::show_breed()
{cout<<"狗的品种为:"<
class spotted_dog:public unspotted_dog{
char spotcolour[10];
public:
spotted_dog(char* breed,int height,int weight,char* colour,char* spotcolour)
{strcpy(this->breed,breed);
this->height=height;
this->weight=weight;
strcpy(this->colour,colour);
strcpy(this->spotcolour,spotcolour);
}
void show_breed()
{cout<<"无斑狗的品种为:"< void spot_info() {cout<<"斑点为:"<};

int main(void)
{spotted_dog redSpot("Damlmatian",24,60,"white","red");
unspotted_dog rover("Labrador Retriever",30,40,"yellow");
redSpot.show_breed();
redSpot.spot_info();
rover.show_breed();
return 0;
}

//---------------------------------------------------------------------------