#include <iostream>
using namespace std;
class Dog
{
public:
void setdata()
{
cin >> name >> age >> sex >> weight;
}
void GetName()
{
cout << "它的名字叫" << name << "。" << endl;
}
void GetAge()
{
cout << "它今年" << age << "岁。" << endl;
}
void GetSex()
{
if (sex == 'm')
cout << "是公的。" << endl;
else
cout << "是母的。" << endl;
}
void GetWeight()
{
cout << "体重" << weight << "千克。" << endl;
}
private:
char name[20];
int age;
char sex;
double weight;
};
int main()
{
Dog d;
cout << "依次输入狗的姓名,年龄,性别,体重:" << endl;
d.setdata();
cout << "这是我的狗:" << endl;
d.GetName();
d.GetAge();
d.GetSex();
d.GetWeight();
return 0;
}
标签:12,cout,weight,继承,void,sex,char,GetAge From: https://www.cnblogs.com/yuanxinglan/p/17321664.html