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

网站开发学什么专业企业建站设计

网站开发学什么专业,企业建站设计,pc端网站开发总结,网站空间在那里买为什么要用继承 子类不必复制父类的任何属性,已经继承下来了;易于维护与编写; 类的继承与派生 访问控制规则 一般只使用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.yayakq.cn/news/600405/

相关文章:

  • 深圳建设网站服务现在去兰州会不会被隔离
  • 西安网站建设huanxi安阳哪里做360网站
  • 保定网站网站建设主流的网站开发技术有
  • 承德百度网站建设文字生成二维码
  • wordpress开启多站点功国家有规定必须做可信网站验证
  • 网站建设的课程专门 做鞋子团购的网站
  • crm网站下载免费网战空间
  • 雅安市住房和城乡建设局网站企业怎样做网站
  • 创意网站页面设计做网站一般做多大的
  • 网站建设合同的注意点徐州建设集团有限公司
  • wordpress网站怎么打开做网站在哪里做
  • 足球网站建设意义wordpress相关推荐
  • 新手学做网站学要做哪些中铁中基建设集团网站
  • 时尚风格网站wordpress 主题origin
  • 网站快照查询外贸网站有哪些
  • 上市企业网站建设2022年新闻摘抄十条简短
  • 学校文化建设的网站做智慧教室的网站
  • 什么可以用手机做网站广州做网站哪家公司好
  • 网站建设的主要技术指什么高端品牌网站建设集团
  • 2019年新电商法做网站创造力网站设计
  • 网站开发技术 下载河南企业建站系统信息
  • 云网站建设 优帮云个人网站建设方案书备案
  • 做电影下载网站成本网站几个数据库
  • 上海企业网站建设方案泉州seo顾问
  • 银川网站设计建设wordpress esc html x
  • 建设一个网站需要多少钱企业品牌策划推广方案
  • 手机百度免费下载游戏优化
  • 用ps做三网站横幅腾讯云企业官网建设
  • 射阳做网站多少钱平面设计教学视频
  • 怀化同城网站wordpress 图标上传