你好,能帮我看一道C++的题目吗?2
发布网友
发布时间:2024-02-23 19:44
我来回答
共1个回答
热心网友
时间:2024-04-02 18:04
//---------------------------------------------------------------------------
#include <iostream>
#include <cmath>
#include <cstring>
#include <string>
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<<"狗的品种为:"<<breed;}
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<<"无斑狗的品种为:"<<breed;}
void spot_info() {cout<<"斑点为:"<<colour;}
};
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;
}
//---------------------------------------------------------------------------