//实验四q3_(4),仿真农场(观察基类与派生类的构造函数和析构函数的调用顺序)
//作者:朱婧文,时间:2011年5月15日
#include <iostream>
#include "Mammal.h"
#include "Dog.h"
#include "Donkey.h"
#include "Horse.h"
#include "Pig.h"
#include "Mule.h"
using namespace std;
int main()
{
int age;
int weight;
Mammal *a = new Mammal;//定义哺乳动物类的对象a,执行一些列函数
a->Speak();
a->Move();
a->sleep();
cout << "Age:" << a->GetAge() << endl;
cout << "Weight:" << a->GetWeight() << endl;
cout << "Input age:";
cin >> age;
cout << "Input weight:";
cin >> weight;
a->SetAge(age);
a->SetWeight(weight);
cout << "Age:" << a->GetAge() << endl;
cout << "Weight:" << a->GetWeight() << endl;
cout << endl;
Dog *d = new Dog;//定义狗类的对象d,执行一系列函数
d->Speak();
d->Move();
d->sleep();
d->Shake();
d->food();
cout << "Age:" << d->GetAge() << endl;
cout << "Weight:" << d->GetWeight() << endl;
cout << "Variety:" << d->GetDog() << endl;
cout << "Input age:";
cin >> age;
cout << "Input weight:";
cin >> weight;
d->SetAge(age);
d->SetWeight(weight);
cout << "Age:" << d->GetAge() << endl;
cout << "Weight:" << d->GetWeight() << endl;
cout << endl;
Horse *h = new Horse;//定义马类对象h,执行一系列函数
h->Speak();
h->Move();
h->sleep();
cout << "Age:" << h->GetAge() << endl;
cout << "Weight:" << h->GetWeight() << endl;
cout << "Input age:";
cin >> age;
cout << "Input weight:";
cin >> weight;
h->SetAge(age);
h->SetWeight(weight);
cout << "Age:" << h->GetAge() << endl;
cout << "Weight:" << h->GetWeight() << endl;
cout << endl;
Donkey *dk = new Donkey;//定义驴类对象dk,执行一系列函数
dk->Speak();
dk->Move();
dk->sleep();
cout << "Age:" << dk->GetAge() << endl;
cout << "Weight:" << dk->GetWeight() << endl;
cout << "Input age:";
cin >> age;
cout << "Input weight:";
cin >> weight;
dk->SetAge(age);
dk->SetWeight(weight);
cout << "Age:" << dk->GetAge() << endl;
cout << "Weight:" << dk->GetWeight() << endl;
cout << endl;
Pig *p = new Pig;//定义猪类对象p,执行一系列函数
p->Speak();
p->Move();
p->sleep();
cout << "Age:" << p->GetAge() << endl;
cout << "Weight:" << p->GetWeight() << endl;
cout << "Input age:";
cin >> age;
cout << "Input weight:";
cin >> weight;
p->SetAge(age);
p->SetWeight(weight);
cout << "Age:" << p->GetAge() << endl;
cout << "Weight:" << p->GetWeight() << endl;
cout << endl;
Mule *m = new Mule;//定义骡类对象m,执行一系列函数
m->Speak();
m->Move();
m->sleep();
cout << "Age:" << m->GetAge() << endl;
cout << "Weight:" << m->GetWeight() << endl;
cout << "Input age:";
cin >> age;
cout << "Input weight:";
cin >> weight;
m->SetAge(age);
m->SetWeight(weight);
cout << "Age:" << m->GetAge() << endl;
cout << "Weight:" << m->GetWeight() << endl;
cout << endl;
delete d;
cout << endl;
delete h;
cout << endl;
delete dk;
cout << endl;
delete p;
cout << endl;
delete m;
cout << endl;
system("pause");
return 0;
}
没有合适的资源?快使用搜索试试~ 我知道了~
仿真农场(哺乳动物类)
共91个文件
cpp:49个
h:42个
4星 · 超过85%的资源 需积分: 11 34 下载量 62 浏览量
2011-05-22
13:59:00
上传
评论 9
收藏 34KB RAR 举报
温馨提示
从基类Mammal类分别派生出各种动物,通过虚函数实现Mammal类动物对象指针被赋予不同的动物种类时,编程分别使各个动物表现为不一样的行为。
资源推荐
资源详情
资源评论
收起资源包目录
4_3.rar (91个子文件)
4_3
10389332zhaoyao
Donkey.h 184B
Mule.h 200B
Pig.cpp 252B
test.cpp 689B
Mammal.h 358B
Donkey.cpp 276B
Mammal.cpp 785B
Dog.h 403B
Dog.cpp 503B
Mule.cpp 269B
Pig.h 161B
Horse.cpp 270B
Horse.h 181B
10389288zhujingwen
(4)
Donkey.h 351B
Mule.h 347B
Pig.cpp 387B
Mammal.h 563B
Donkey.cpp 411B
Mammal.cpp 861B
Dog.h 455B
Dog.cpp 600B
Mule.cpp 435B
Pig.h 331B
client.cpp 3KB
Horse.cpp 405B
Horse.h 346B
(5)
Donkey.h 338B
Mule.h 335B
Pig.cpp 377B
Mammal.h 559B
Donkey.cpp 397B
Mammal.cpp 851B
Dog.h 443B
Dog.cpp 586B
Mule.cpp 421B
Pig.h 319B
client.cpp 3KB
Horse.cpp 393B
Horse.h 334B
(6)
Donkey.h 381B
Mule.h 377B
Pig.cpp 440B
Mammal.h 611B
Donkey.cpp 470B
Mammal.cpp 856B
Dog.h 484B
Dog.cpp 653B
Mule.cpp 490B
Pig.h 361B
client.cpp 3KB
Horse.cpp 462B
Horse.h 376B
10389319林熙南(代码风格稍微欠缺)
Abstract
Donkey.h 205B
Mule.h 230B
Pig.cpp 401B
Mammal.h 2KB
Donkey.cpp 423B
Mammal.cpp 603B
Dog.h 209B
Dog.cpp 459B
4_3_Test_3.cpp 1002B
Mule.cpp 456B
Pig.h 192B
Horse.cpp 421B
Horse.h 199B
Virtual
Donkey.h 213B
Mule.h 230B
Pig.cpp 401B
Mammal.h 441B
4_3_Test_2.cpp 2KB
Donkey.cpp 423B
Mammal.cpp 603B
Dog.h 217B
Dog.cpp 459B
Mule.cpp 456B
Pig.h 200B
Horse.cpp 421B
Horse.h 207B
Derived
Donkey.h 182B
Mule.h 207B
Pig.cpp 355B
Mammal.h 354B
4_3_Test_1.cpp 756B
Donkey.cpp 378B
Mammal.cpp 593B
Dog.h 186B
Dog.cpp 407B
Mule.cpp 391B
Pig.h 169B
Horse.cpp 376B
Horse.h 176B
共 91 条
- 1
资源评论
- xiongzhd2014-04-19确实还不错
- u0103514432013-05-01做得很好,写的用心
- lyzpokemon2013-04-19做得很好,写的用心
- Blue_android2014-05-02程序写的还不错,有借鉴意义
dengjianqiang2011
- 粉丝: 59
- 资源: 26
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 《认识计算机桌面》教案.doc
- 《软件工程》期末考试参考题及答案.doc
- 《软件工程》期末考试及答案.doc
- 《软件工程》经典考试例题复习试题-重点知识点(含答案)(良心出品必属精品).doc
- 《软件工程》经典考试例题复习题-重点知识点(含答案)(良心出品必属精品).docx
- 《软件工程》考试及答案A卷B卷.doc
- python-ldap-3.4.4-cp311-cp311-win-amd64.whl
- 【推荐】logistic分析(可编辑修改).ppt
- 基于opencv的dnn模块实现Yolo-Fastest的目标检测python源码+模型+说明(高分项目).zip
- 使用Python调用微信本地ocr服务.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功