C++ day2

1.xmind
2.

cpp 复制代码
#include <iostream>

using namespace std;

class Rect
{
private:
    int  width;
    int height;
public:
    void init(int width,int height );
    void set_width(int width);
    void set_height(int height);
    void show();
};
void Rect :: init (int width,int height)
{
    this->width=width;
    this->height=height;
}
void Rect :: set_width(int width)
{
    this->width=width;
}
void Rect :: set_height(int height)
{
    this->height=height;
}
void Rect :: show()
{
    cout << "周长: " << 2*height+2*width << "  面积: " << height*width << endl ;
}

int main()
{
    int width = 10;
    int height =10 ;
    Rect r1;
    r1.init(width,height);
    r1.show();

    cout << "please enter width : " ;
    cin >> width ;
    r1.set_width(width);
    cout << "please enter height : ";
    cin >> height;
    r1.set_height(height);
    r1.show();

    return 0;
}
相关推荐
拳里剑气4 小时前
C++算法:多源BFS
c++·算法·宽度优先·多源bfs
ysa0510305 小时前
【板子】短序列dp(换成维护更小常数维度的dp)
c++·笔记·算法·板子
aramae7 小时前
C++ IO流完全指南:从C标准库到C++流式编程
服务器·c语言·开发语言·c++·后端
_wyt0017 小时前
c++里的族谱:树
c++·
@三十一Y8 小时前
C++:AVL树实现
c++
haolin123.9 小时前
类和对象(上)
开发语言·c++
ShineWinsu9 小时前
对于Linux:传输层协议UDP原理的解析
linux·c++·面试·udp·协议·传输层·计算机系统
LingzhiPi9 小时前
零知派ESP32--AS5600磁吸旋钮音量控制器
c++·单片机·嵌入式硬件
小保CPP9 小时前
OpenCV C++车型识别1-图像预处理
c++·人工智能·opencv·计算机视觉
库克克9 小时前
【C++】C++11 包装器function 与 绑定器 bind
开发语言·c++