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

9月12日作业

作业代码

#include <iostream>using namespace std;class Shape
{
protected:double cir;double area;
public://无参构造Shape() {cout<<"无参构造"<<endl;}//有参构造Shape(double c, double a):cir(c), area(a){cout<<"有参构造"<<endl;}//析构函数~Shape(){cout<<"析构函数"<<endl;}//拷贝构造Shape(const Shape&other):cir(other.cir), area(other.area){cout<<"拷贝构造"<<endl;}//拷贝赋值Shape& operator=(const Shape& other){if(this != &other){this->cir = other.cir;this->area = other.area;cout<<"拷贝赋值"<<endl;}return *this;}//移动赋值Shape& operator=(Shape&& other){this->cir = other.cir;this->area = other.area;return *this;}
};class Circle:public Shape
{
private:double rad;
public://无参构造Circle() {cout<<"无参构造"<<endl;}//有参构造Circle(double r):rad(r){cout<<"有参构造"<<endl;}//析构函数~Circle(){cout<<"析构函数"<<endl;}//拷贝构造Circle(const Circle&other):rad(other.rad){cout<<"拷贝构造"<<endl;}//拷贝赋值Circle& operator=(const Circle& other){if(this != &other){this->rad = other.rad;cout<<"拷贝赋值"<<endl;}return *this;}//移动赋值Circle& operator=(Circle&& other){this->rad = other.rad;return *this;cout<<"移动赋值"<<endl;}//获取周长double get_cir(){Shape::cir = rad*2*3.14;return Shape::cir;}//获取面积double get_area(){Shape::area = rad*rad*3.14;return Shape::area;}
};class Rect:public Shape
{
private:double len;double width;
public://无参构造Rect() {cout<<"无参构造"<<endl;}//有参构造Rect(double l, double w):len(l), width(w){cout<<"有参构造"<<endl;}//析构函数~Rect(){cout<<"析构函数"<<endl;}//拷贝构造Rect(const Rect&other):len(other.len), width(other.width){cout<<"拷贝构造"<<endl;}//拷贝赋值Rect& operator=(const Rect& other){this->len = other.len;this->width = other.width;return *this;}//移动赋值Rect& operator=(Rect&& other){this->len = other.len;this->width = other.width;return *this;}//获取周长double get_cir(){Shape::cir = (len+width)*2;return Shape::cir;}//获取面积double get_area(){Shape::area = len*width;return Shape::area;}
};int main()
{Circle c(3);cout<<"c_cir = "<<c.get_cir()<<endl;cout<<"c_area = "<<c.get_area()<<endl;Rect r(3.5, 5.5);cout<<"r_cir = "<<r.get_cir()<<endl;cout<<"r_area = "<<r.get_area()<<endl;return 0;
}

运行截图

思维导图

模拟面试

http://www.lryc.cn/news/165630.html

相关文章:

  • React框架下如何集成H.265网页流媒体视频播放器EasyPlayer.js?
  • 《向量数据库》——向量数据库的使用场景有哪些?
  • Java 中 List 集合取补集
  • 我的个人网站——宏夏Coding上线啦
  • 【机器视觉】喇叭的外圆以及金属内圆的同心度视觉检测--康耐德智能
  • STM32WB55开发(2)----修改蓝牙地址
  • 【1++的C++进阶】之C++11(二)
  • 【VS2022】调试
  • python:使用RESTful API(flask)调用python程序传递参数,实现Web端调用python程序
  • 贪心算法(Greedy Algorithm)
  • 论文阅读 - Outlier detection in social networks leveraging community structure
  • 【操作系统】进程控制
  • Linux命令200例:expr一个用于进行数值表达式求值的工具
  • 当你的公司突然开始大量的裁员,被留下的你,真的准备好面对以后了吗?
  • 预约陪诊就诊小程序源码多城市开发版
  • upload-labs文件上传靶场实操
  • leetcode分类刷题:队列(Queue)(二、优先队列解决TopK简单问题)
  • 【排障记录】扩展坞USB 3.0能用而2.0不能用
  • 01-从JDK源码级别剖析JVM类加载机制
  • AI时代:探索机器学习与深度学习的融合之旅
  • 模块化开发_groupby查询think PHP5.1
  • elementUI时间选择器
  • 第1章_瑞萨MCU零基础入门系列教程之单片机程序的设计模式
  • 【UE】刀光粒子效果——part2 材质函数部分
  • 为什么项目经理的时间观念这么重?
  • 编码转换流
  • Pycharm创建项目时如何自动添加头部信息
  • DAY48
  • 光栅和矢量图像处理:Graphics Mill 11.4.1 Crack
  • vue3中组件没有被调用,没进去也没报错