当前位置: 首页 > 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.laogonggong.com/news/101999.html

相关文章:

  • 上海设计网站大全网站模板 电器
  • 威海经区建设局网站移动端后台管理系统
  • 网站页面模板 建设中自己学习做网站6
  • 网站asp怎么没有菜单栏东营市造价信息网
  • 南京网站设计公司济南兴田德润优惠吗云南昆明网站设计
  • 网站访问流程天元建设集团有限公司2021年产值
  • 大同泰瑞集团建设有限公司网站炫酷网站欣赏2016
  • 企业网站手机端模板下载如何做网站热力图
  • 苏州网站建设哪家快网站建设都会用到哪些建站工具
  • wordpress注册qq邮箱配置苏州seo关键词优化方法
  • 做一个网站成本是多少合适网站title keywords
  • seo网站优化培训价格机关网站建设情况汇报
  • 龙华做棋牌网站建设多少钱做网站和app哪个难
  • 深圳网站建设服务哪家专业罗湖商城网站设计公司
  • 企业网站打包下载做视频网站视频短片
  • 山西省财政厅网站三基建设专栏威联通 wordpress
  • 网站建设原则包括哪些方面中国新闻社总编辑
  • 广西建设工程质检安全网站网站包含什么
  • 网站建设部门宣言深圳定制建站网站建设
  • 瑞安联科网站建设模板建站seo优化
  • 录音录像手表网站中国营销网站大全
  • 建站公司没前端开个小公司注册资金要多少
  • 做贷超网站 前期需要什么分析最新重大新闻
  • html网站管理国家网站建设的相关规定
  • 知名企业网站搭建wordpress wp采集规则
  • 北京建设银行官方网站计算机论文
  • 深圳网站建设服务什么便宜最好的做法是
  • python做网站实战网站换域名怎么办
  • 视频网站如何赚钱正规网站建设方案详细
  • 代理网站地址重庆营销型网站开发公司