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

腾讯云网站备案不能用阿里云免费模式营销案例

腾讯云网站备案不能用阿里云,免费模式营销案例,建站视频教程网,建设银行吴中支行网站为什么要用继承 子类不必复制父类的任何属性,已经继承下来了;易于维护与编写; 类的继承与派生 访问控制规则 一般只使用Public! 构造函数的继承与析构函数的继承 构造函数不被继承! 在创建子类对象的时候&…

为什么要用继承

在这里插入图片描述
子类不必复制父类的任何属性,已经继承下来了;易于维护与编写;

类的继承与派生

在这里插入图片描述

访问控制规则

一般只使用Public!
在这里插入图片描述

构造函数的继承与析构函数的继承

构造函数不被继承!
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在创建子类对象的时候,会先调用父类的构造函数,再调用子类的构造函数
在消亡子类对象的时候,会先调用子类的析构函数,再调用父类的析构函数

派生类构造函数

在这里插入图片描述

派生类析构函数

在这里插入图片描述

作业

在这里插入图片描述
在这里插入图片描述
main.cpp

#include "shape.h"
#include "circle.h"
#include "rectangle.h"
#include "roundrectangle.h" 
#include <iostream>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */int main(void) {shape myshape1("red");myshape1.display();circle mycircle1;mycircle1.display();circle mycircle2("red",2);mycircle2.display();Rectangle myrectangle1("green",2,3);myrectangle1.display();RoundRectangle myroundrectangle1("yeelow",2,3,1);myroundrectangle1.display();return 0;
}

shape.cpp

#include "shape.h"
#include <iostream>
using namespace std;		shape::shape():color("white"){cout<<"无参创建shape"<<endl;}shape::shape(string color){this->color = color;cout<<"有参创建shape"<<endl;}shape::~shape(){cout<<"消亡shape"<<endl;}string shape::getColor(){return this->color;}void shape::setcolor(char color){this->color = color;}void shape::display(){cout<<"color:"<<getColor()<<endl;}

shape.h

#ifndef SHAPE_H
#define SHAPE_H
#include <string>
#include <iostream>
using namespace std;
class shape{private:string color;public:shape();shape(string color);~shape();string getColor();void setcolor(char color);void display();
};#endif

circle.cpp

#include "circle.h"
#include "shape.h"
#include <iostream>const double pi = 3.14;circle::circle(){radius = 1;cout<<"无参创建circle"<<endl;}circle::circle(string color,double radius):shape(color){this->radius = radius;cout<<"有参创建circle"<<endl;}circle::~circle(){cout<<"消亡circle"<<endl;}double circle::getRadius(){return this->radius;}void circle::setradius(double radius){this->radius = radius;	}double circle::getArea(){return pi*radius*radius;}void circle::display(){shape::display();cout<<"R="<<getRadius()<<","<<"Area="<<getArea()<<endl;}

circle.h

#ifndef CIRCLE_H
#define CIRCLE_H
#include <string>
#include "shape.h"class circle:public shape{private:double radius;public:circle();circle(string color,double radius);~circle();double getRadius();void setradius(double radius);double getArea();void display();
};#endif

rectangle.cpp

#include "rectangle.h"
#include "shape.h"
#include <iostream>Rectangle::Rectangle(){width = 1;height = 1;cout<<"无参创建Rectangle"<<endl;}Rectangle::Rectangle(string color,double width,double height):shape(color){this->width = width;this->height = height;cout<<"有参创建Rectangle"<<endl; }Rectangle::~Rectangle(){cout<<"消亡Rectangle"<<endl;}double Rectangle::getWidth(){return width; }double Rectangle::getHeight(){return height;}void Rectangle::setWidth(double width){this->width = width;}void Rectangle::setHeight(double height){this->height = height;}double Rectangle::getArea(){return width*height;}void Rectangle::display(){shape::display();cout<<"width="<<getWidth()<<","<<"Height="<<getHeight()<<","<<"Area="<<getArea()<<endl;}

rectangle.h

#ifndef RECTANGLE_H
#define RECTANGLE_H
#include <string>
#include "shape.h"class Rectangle:public shape{private:double width;double height;public:Rectangle();Rectangle(string color,double width,double height);~Rectangle();double getWidth();double getHeight();void setWidth(double width);void setHeight(double height);double getArea();void display();
};#endif

roundrectangle.cpp

#include "roundrectangle.h"
#include "rectangle.h"
#include"shape.h"
#include <iostream>RoundRectangle::RoundRectangle(){this->roundRadius = 1;cout<<"无参创建RoundRectangle"<<endl; }RoundRectangle::RoundRectangle(string color,double width,double height,double roundRadius):Rectangle(color,width,height){this->roundRadius = roundRadius;cout<<"有参创建RoundRectangle"<<endl;}RoundRectangle::~RoundRectangle(){cout<<"消亡RoundRectangle"<<endl; }double RoundRectangle::getRoundradius(){return roundRadius;}void RoundRectangle::setRoundradius(double roundRadius){this->roundRadius = roundRadius;}double RoundRectangle::getArea(){return Rectangle::getWidth()*Rectangle::getHeight()+(3.14*roundRadius*roundRadius)/2;}void RoundRectangle::display(){shape::display();cout<<"width="<<Rectangle::getWidth()<<","<<"Height="<<Rectangle::getHeight()<<","<<"Area="<<getArea()<<endl;}

roundrectangle.h

#ifndef ROUNDRECTANGLE_H
#define ROUNDRECTANGLE_H
#include <string>
#include "rectangle.h"class RoundRectangle:public Rectangle{private:double roundRadius;public:RoundRectangle();RoundRectangle(string color,double width,double height,double roundRadius);~RoundRectangle();double getRoundradius();void setRoundradius(double roundRadius);double getArea();void display();
};#endif
http://www.qdjiajiao.com/news/4840.html

相关文章:

  • 美容院怎么建立自己的网站微信小程序开发工具
  • 专业建设 教学成果奖网站舆情报告范文
  • 音乐外链生成网站怎么做主流网站关键词排名
  • 吉林省长春市长春网站建设哪家好企业网站优化关键词
  • 网站如何做伪静态潍坊seo招聘
  • 西部数码网站管理助手v4.0深度搜索
  • 用自己电脑配置服务器做网站武汉seo网络优化公司
  • 哪些网站可以做微信支付搜索引擎关键词seo优化公司
  • 纯flash网站下载做网络销售感觉自己是骗子
  • 网站的常用技术有哪些上海网络优化服务
  • 网站优化一般怎么做小说风云榜
  • 烟台h5网站制作河南郑州最近的热搜事件
  • 黄埔定制型网站建设手机系统优化软件哪个好
  • 网站开发上门服务费西安seo代运营
  • 网站开发都是用什么做的广州推广seo
  • 永川建网站铁岭网站seo
  • web3普通人从哪里入手惠州seo优化服务
  • 做网站需要域名吗企业网站设计素材
  • 专业做公司网站网址查询服务器地址
  • 做细胞激活的母液网站百度一下百度网页版进入
  • 阿里巴巴怎么做网站关键词推广优化排名如何
  • 自己做网站花钱吗免费发软文的网站
  • 免费的网站模板有哪些网页设计培训学校
  • 网站开发 确认函seo教育培训机构
  • 美团外卖网站开发上海网站建设推广服务
  • 重庆网站建设咨询网络项目怎么推广
  • 做哪类英文网站赚钱郑州网站推广优化公司
  • 云游戏平台网页版宁波如何做seo排名优化
  • 宠物网站建设进度表北京seo结算
  • 教育平台网站开发站长联盟