PAGE / NUMPAGES Anne的宠物小屋有12个笼子,每个笼子可以放不同的动物,但只能放1只或0只,包括猫Cat,狗Dog,蛇Snake. 定义描述宠物小屋的类shelves,其中有12笼子用于存放各种宠物。 定义虚拟基类Animal,包括纯虚函数ShowMe,显示每个宠物的情况,包括类型、颜色、体重和喜爱的食物。矚慫润厲钐瘗睞枥。 定义派生类Cat,Dog,Snake,具体实现上述纯虚函数。 编写main函数,可增加、删除笼子中的宠物,查询每个笼子中存放的宠物类型,(包括笼子为空的情况),统计笼中宠物的种类和数量。聞創沟燴鐺險爱氇。 解答:#include iostream.h #include12.h //int int Cat::CatNum=0; Cat::Cat(){ type=0; colour=new char[20]; food=new char[20]; CatNum++; } void Cat::ShowMe(){ coutThe animal in the shelve is a Cat.endl; coutThe colour is: colourendl; coutThe weight is: weightendl; coutThe favorite food is: foodendl; return; } int Cat::number(){ return CatNum; } istream operator (istream is,Cat cat){ coutThe Cats colour is:; cincat.colour; coutThe Cats weight is:; cincat.weight; coutThe Cats favorite food is:; cincat.food; return is; } void Cat::DeleteMe(){ CatNum--; } Cat::~Cat(){} int Dog::DogNum=0; Dog::Dog(){ type=1; colour=new char[20]; food=new char[20]; DogNum++; } void Dog::ShowMe(){ coutThe animal in the shelve is a Dog.endl; coutThe colour is: colourendl; coutThe weight is: weightendl; coutThe favorite food is: foodendl; return; } int Dog::number(){ return DogNum; } istream operator (istream is,Dog dog){ coutThe Dogs colour is: ; cindog.colour; coutThe Dogs weight is: ; cindog.weight; coutThe Dogs favorite food is: ; cindog.food; return is; } void Dog::DeleteMe(){ DogNum--; } Dog::~Dog(){ } int Snake::SnakeNum=0; Snake::Snake(){ type=2; colour=new char[20]; food=new char[20]; SnakeNum++; } void Snake::ShowMe(){ coutThe animal in the shelve is a Snake.endl; 残骛楼諍锩瀨濟溆。 coutThe colour is: colourendl; coutThe weight is: weightendl; coutThe favorite food is: foodendl; return; } int Snake::number(){ return SnakeNum; } istream operator(istream is,Snake snake) { coutThe Snakes colour is: ; cinsnake.colour; coutThe Snakes weight is: ; cinsnake.weight; coutThe Snakes favorite food is: ; cinsnake.food; return is; } void Sna
相关知识
宠物小屋管理系统 宠物小屋内共有12个笼子,每个笼子内可放不同的小动物,如猫、狗、鹦鹦等,但同一时
C++课程作业之 宠物类的创建
C++:结合容器多态继承的(宠物小屋)实例
C++ 安妮的宠物小屋 练习
C++宠物小屋实例
刺猬饲养恒温保暖小屋宠物仓鼠笼子空间房子笼子
仓鼠笼子里面放什么东西好 仓鼠笼子一般放哪里比较合适
如何让宠物适应笼子生活(狗狗放笼子里面的应对策略)
客厅放猫笼子风水禁忌
家里狗笼子放哪里好
网址: Anne的宠物小屋有12个笼子,每个笼子可以放不同的动物,.doc https://m.mcbbbk.com/newsview819515.html
上一篇: WOW要塞宠物小屋任务宠物搭配技 |
下一篇: 要塞宠物小屋每日对战攻略:缝合二 |