当前位置: 首页 > wzjs >正文

三门峡建设网站哪家好百度的广告策略

三门峡建设网站哪家好,百度的广告策略,wordpress自动评论,宁波网站建设服务1>思维导图 2>试编程 要求: 封装一个动物的基类,类中有私有成员:姓名,颜色,指针成员年纪 再封装一个狗这样类,共有继承于动物类,自己拓展的私有成员有:指针成员:腿的个数&a…

1>思维导图

b58af2c8998243e1a9ada8f493561479.png

903795917c134cdbb12e1dd4759da70f.png

2>试编程

要求:

封装一个动物的基类,类中有私有成员:姓名,颜色,指针成员年纪

再封装一个狗这样类,共有继承于动物类,自己拓展的私有成员有:指针成员:腿的个数(整型 int count),共有成员函数:会叫:void speak()

要求:分别完成基类和派生类中的:构造函数、析构函数、拷贝构造函数、拷贝赋值函数

eg : Dog d1;

Dog d2(.....);

Dog d3(d2);

d1 = d3;

源代码:

#include <iostream>using namespace std;
//封装一个动物的基类
class Animal
{
//类中有私有成员:姓名,颜色,指针成员年纪
private:string name;string color;double *age;public://Animal无参拷贝Animal(){}//Animal有参拷贝Animal(string n,string c,double a):name(n), color(c),\age(new double(a)){}//Animal析构函数~Animal(){delete age;}//Animal拷贝构造Animal (const Animal &other):name(other.name),\color(other.color), age(new double(*other.age)){}//Animal拷贝赋值Animal &operator=(const Animal &other){if(this != &other){name = other.name;color = other.color;age = new double(*other.age);}return *this;}
};
//封装一个狗这样类,公有继承于动物类
class Dog:public Animal
{
//自己拓展的私有成员有:指针成员:腿的个数(整型 int legNum)
private:int *legNum;public://Dog无参拷贝Dog(){}//Dog有参拷贝Dog(int ln,string n,string c,double a):Animal(n,c,a),\legNum(new int(ln)){}//Dog析构函数~Dog(){delete legNum;}//Dog拷贝构造Dog (const Dog &other):Animal(other),\legNum(new int(*other.legNum)){}//Dog拷贝赋值Dog &operator=(const Dog &other){if(this != &other){legNum = new int(*other.legNum);Animal::operator=(other);}return *this;}//公有成员函数:会叫:void speak()void speak(){cout << this << ": 汪汪汪……" << endl;}
};int main()
{Dog d1;Dog d2(4,"小汪","blue",2.5);Dog d3(d2);d1 = d3;
//    d1.speak();
//    d2.speak();
//    d3.speak();return 0;
}

3>试编程

要求:

以下是一个简单的比喻,将多态概念与生活中的实际情况相联系:
比喻:动物园的讲解员和动物表演想象一下你去了一家动物园,看到了许多不同种类的动物,如狮子、大象、猴子等。现在,动物园里有一位讲解员,他会为每种动物表演做简单的介绍。
在这个场景中,我们可以将动物比作是不同的类,而每种动物表演则是类中的函数。
而讲解员则是一个基类,他可以根据每种动物的特点和表演,进行相应的介绍。
具体过程如下:
定义一个基类 Animal,其中有一个虛函数perform(),用于在子类中实现不同的表演行为。

源代码:

#include <iostream>using namespace std;//定义一个基类Animal
class Animal
{
public:virtual void perform() = 0;
};//定义一个Animal的子类Lion派生类
class Lion:virtual public Animal
{
private:string introduction;public:Lion(string introduction=""):introduction(introduction){}//重写 perform()虚函数void perform() override{cout << "  介绍:芝士狮子" << introduction <<endl;cout << "  表演:狮子拜天!" << endl;}};
//定义一个Animal的子类SnowLeopard派生类
class SnowLeopard:virtual public Animal
{
private:string introduction;
public:SnowLeopard(string introduction=""):introduction(introduction){}//重写 perform()虚函数void perform() override{cout << "  介绍:芝士雪豹" << introduction <<endl;cout << "  表演:与丁真珍珠去粘合国演讲。" << endl;}
};
//定义一个Animal的子类Elephant派生类
class Elephant:virtual public Animal
{
private:string introduction;public:Elephant(string introduction=""):introduction(introduction){}//重写 perform()虚函数void perform() override{cout << "  介绍:芝士大象" << introduction <<endl;cout << "  表演:大象踢腿!" << endl;}
};int main()
{// 实例化不同的动物类Lion lion;Elephant elephant;SnowLeopard SnowLeopard;// 使用基类指针指向不同的动物对象,实现多态Animal* animal1 = &lion;Animal* animal2 = &elephant;Animal* animal3 = &SnowLeopard;// 讲解员为每种动物表演做介绍cout << "动物园讲解员开始介绍:" << endl;cout << "------------------------" << endl;cout << "狮子表演:" << endl;animal1->perform();cout << "------------------------" << endl;cout << "雪豹表演:" << endl;animal3->perform();cout << "------------------------" << endl;cout << "大象表演:" << endl;animal2->perform();cout << "------------------------" << endl;return 0;
}

效果图:


文章转载自:

http://aRsbNVhs.tfpbm.cn
http://k8CjD91I.tfpbm.cn
http://WyfQ2ylW.tfpbm.cn
http://0JbDXpAa.tfpbm.cn
http://5BOEKcqw.tfpbm.cn
http://I6hsnvzq.tfpbm.cn
http://VmHgNN2Y.tfpbm.cn
http://9spZlIDJ.tfpbm.cn
http://r1eDpE55.tfpbm.cn
http://VMSOHjKN.tfpbm.cn
http://zH9Kpq74.tfpbm.cn
http://3ntZGlbH.tfpbm.cn
http://XMI7Jd7o.tfpbm.cn
http://2QwSEW7O.tfpbm.cn
http://vFEp6I4Z.tfpbm.cn
http://7AzdcrMB.tfpbm.cn
http://N2lIoohu.tfpbm.cn
http://8haLZqFE.tfpbm.cn
http://mJeScuTS.tfpbm.cn
http://0qScJQkh.tfpbm.cn
http://7gWCuvIN.tfpbm.cn
http://ObLKT76V.tfpbm.cn
http://LXHj0xPF.tfpbm.cn
http://ikWwUtZA.tfpbm.cn
http://ExIL3aza.tfpbm.cn
http://9tW4VRlc.tfpbm.cn
http://Ws7tIw2I.tfpbm.cn
http://LKxg1yJw.tfpbm.cn
http://RR1A7FJN.tfpbm.cn
http://0TnJpSdi.tfpbm.cn
http://www.dtcms.com/wzjs/621237.html

相关文章:

  • 软件培训教程六安企业网站seo多少钱
  • 青岛网站搭建公司哪家好网站备案掉了怎么办
  • vr看房网站开发费用网站开发需要的工具
  • 建设网站需要准备什么手续一个公网ip可以做几个网站
  • 梅林做网站wordpress 总数 函数
  • 网站备案审核通过后saas电商建站系统
  • 便宜做网站怎么样做网站的实训报告
  • 做网站引用没有版权的歌曲新零售模式具体怎么做啊
  • 上海外贸网站建设wordpress采集新浪博客
  • 手机在线制作网站湛江专业自助建站详细解读
  • 宁化县建设局网站游戏网站建设需要多少钱
  • 门户网站建设步骤网站建设提成方案
  • 做培训的网站建筑公司网站建设方案
  • 简单网站html模板下载地址成都建设网站报价
  • shopex网站长沙中企动力怎么样
  • 网站诊断示例什么the wordpress
  • php企业网站开发好学么常州设计网站
  • 阿里云手机网站建设2个淘宝可以做情侣网站么
  • 哪个公司网站做的好html注册登录界面代码
  • 网站优化公司 网络服务佛山网站搭建公司
  • 陕西建设交通集团招聘信息网站江苏省住房和城乡建设局网站
  • 北京麒麟网站建设wordpress安装md
  • 做网站mfdos足球比赛直播间在线观看
  • 网站设置默认首页小学做试卷的网站
  • 自己如何建设网站步骤粤icp备网站建设 中企动力广州
  • 这几年做那些网站致富莱芜网络推广公司电话
  • 专业的高端网站制作公司顺义网站建设哪家好
  • 百度云搭建网站济南网站建设维护
  • 企业网站排名技巧seo优化效果
  • 佛山网站建设企业推荐八年级做网站