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;
}
相关推荐
开心大爆炸6 分钟前
ubuntu20.4 安装ros1 noetic版本流程
c++
欧特克_Glodon2 小时前
OpenCV计算机视觉开发入门与实践<二十四>:几何变换之平移、缩放、旋转
c++·人工智能·opencv·计算机视觉
鱼很腾apoc3 小时前
【Linux】第13期 详解应用层协议HTTP+Cookie/Session+HTTPS
linux·服务器·c++·学习·http·https
charlie1145141913 小时前
deque、list 与 forward_list:vector 之外的三个选择
开发语言·数据结构·c++·list·开源项目
Escalating_xu3 小时前
【C++ string 上篇】从字符串基础到容量管理、迭代器与经典算法题
java·c++·算法
啦啦啦啦啦zzzz4 小时前
ET和LT详解
linux·运维·服务器·网络·c++·网络编程
skr爱码士4 小时前
10_Qt Designer 与 UI 文件(.ui 原理、uic 编译、动态加载)
c++·qt·ui·客户端
程与留4 小时前
11_常用控件速查(上):QPushButton、QLabel、QLineEdit、QComboBox
c++·qt
Demon--hx4 小时前
多态实现原理
开发语言·c++
水饺编程5 小时前
第5章,[Win32 章节] :绘制填充区域
c语言·c++·windows·visual studio