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;
}
相关推荐
D e re k ZH2 小时前
P5025 [SNOI2017] 炸弹
c++·算法
wuminyu3 小时前
Java字节码学习总结:字节码如何加载、解析和执行
java·linux·c语言·jvm·c++
qq_406981033 小时前
c++的decltype是什么
开发语言·c++
坤坤子吖3 小时前
算法学习——单调队列
开发语言·c++·笔记·学习·算法
杜 硕4 小时前
从零开始的C++生活——第六讲——01
开发语言·c++·生活
Risehuxyc6 小时前
C++(VS2026)使用Ncap库的配置
c++
4ever.ov06 小时前
精学C++第一站 从命名空间到引用:C++入门核心语法全梳理(13000字长文)
开发语言·c++·clion
听风若依7 小时前
C++模板初阶
c++·算法
纪念 2297 小时前
C++ 算法(模拟)
开发语言·c++·算法
zwc32104320557 小时前
Day 2:图像内存、数据类型与stride
c++·人工智能·opencv·算法·计算机视觉