码迷,mamicode.com
首页 > 其他好文 > 详细

关于狗的类

时间:2016-05-05 12:56:41      阅读:115      评论:0      收藏:0      [点我收藏+]

标签:

class Dog
{
DOGCOLOR color;
char name[20];
static int count;
public:
Dog(char name[], DOGCOLOR color)
{
strcpy(this->name, name);
this->color = color;
}
DOGCOLOR getColor()const { return color; }
const char* getName()const { return name; }
const char* getColorString()const
{
switch (color)
{
case BLACK: return "black";
case WHITE: return "white";
case YELLOW: return "yellow";
case BROWN: return "brown";
case PIEBALD: return "piebald";
}
return "motley";
}
void show()const
{
cout << "There is a " << getColorString() << "dog named " << name<<‘.‘ << endl;
}
};

int main()
{
Dog dog1("hoho", WHITE), dog2("haha", BLACK), dog3("hihi", OTHER);
dog1.show();
dog2.show();
dog3.show();
return 0;
}

关于狗的类

标签:

原文地址:http://www.cnblogs.com/huninglei/p/5461166.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!