C++--day5

实现一个图形类(Shape),包含受保护成员属性:周长、面积,

公共成员函数:特殊成员函数书写

定义一个圆形类(Circle),继承自图形类,包含私有属性:半径

公共成员函数:特殊成员函数、以及获取周长、获取面积函数

定义一个矩形类(Rect),继承自图形类,包含私有属性:长度、宽度

公共成员函数:特殊成员函数、以及获取周长、获取面积函数

在主函数中,分别实例化圆形类对象以及矩形类对象,并测试相关的成员函数。

#include 

using namespace std;
class Shape
{
protected:
    double round;
    double area;
public:
    Shape()
    {
        cout<<"无参构造"<area=other.area;
        this->round=other.round;
        cout<<"拷贝赋值"<area=other.area;
        this->round=other.round;
        cout<<"移动赋值"<area=other.area;
        this->round=other.round;
        this->bj=other.bj;
        cout<<"拷贝赋值"<area=other.area;
        this->round=other.round;
        this->bj=other.bj;
        cout<<"移动赋值"<round=this->bj*2*(3.14);
        cout<<"周长="<area=this->bj*this->bj*(3.14);
        cout<<"面积="<area=other.area;
        this->round=other.round;
        this->hight=other.hight;
        this->wight=other.wight;
        cout<<"拷贝赋值"<area=other.area;
        this->round=other.round;
        this->hight=other.hight;
        this->wight=other.wight;
        cout<<"移动赋值"<round=(this->hight+this->wight)*2;
        cout<<"周长="<area=this->hight*this->wight;
        cout<<"面积="<

C++--day5_第1张图片

你可能感兴趣的:(c++,开发语言)