- 15
- 0
- 约4.22千字
- 约 12页
- 2018-04-24 发布于江苏
- 举报
每个笼子可以放不同的动物,但只能放1只或0只,包括
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 Snake::DeleteMe(){
SnakeNum--;
}
Snake::~Sn
您可能关注的文档
- 有理数的减法--江苏教育版.ppt
- 有样食物比红枣更补血,产后的你记得拿来当零食.pdf
- 期末练习四(下).ppt
- 未央歌 简体版.doc
- 未来美容新模式:.doc
- 本简本内容由同济大学编制,并经彩虹湾置业(上海)有限公.PDF
- 术语的解读小説史研究的特殊理路.PDF
- 机动车综合性能检测机构.doc
- 机械五金模具业合力打造“商贸长安”.pdf
- 机械五金:我国农机工业发展呈现四大新特点.pdf
- 浙江省温州市2024-2025学年七年级上学期语文期末考查卷.docx
- 精品解析:北京市建华实验学校2024-2025学年七年级下学期期中英语试题(原卷版).docx
- 精品解析:北京市通州区2024-2025学年七年级下学期期末考试英语试卷(原卷版).docx
- 精品解析:北京市回民学校2024-2025学年九年级上学期期中语文试题(解析版).docx
- 精品解析:北京市海淀区2025-2026学年九年级上学期期末语文试题(解析版).docx
- 精品解析:北京市东城区汇文中学2025-2026学年八年级上学期期中语文试题(原卷版).docx
- 精品解析:北京市回民学校2024-2025学年九年级上学期期中语文试题(原卷版).docx
- 精品解析:2024-2025学年广东省广州市从化区街口镇中心小学人教版五年级上册期中测试数学试卷(解析版).docx
- 精品解析:北京市通州区2024-2025学年七年级下学期期末考试英语试卷(解析版).docx
- 精品解析:北京市建华实验学校2024-2025学年七年级下学期期中英语试题(解析版).docx
原创力文档

文档评论(0)