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;
}
相关推荐
Дерек的学习记录16 分钟前
C++:stack和queue
开发语言·c++·学习·算法
fqbqrr5 小时前
2612,现代cmake
c++·cmake
我要见SA姐16 小时前
用生活化类比当钥匙,一键打开 C++ 入门大门
java·开发语言·c++
船神丿男人6 小时前
C++ 背包动态规划六题:看懂倒序、正序和两层循环
c++·动态规划
郝学胜-神的一滴8 小时前
Effective STL 条款 17:用 swap 技巧去掉多余容量
c语言·开发语言·数据结构·c++·算法·rpc
随流寻影9 小时前
利用 C++ 实现快速排序及三种优化
开发语言·c++
西西弗Sisyphus10 小时前
C++ 最小 Agentic Loop 实现 - 回调函数系列 - 指针与内存地址(2)
开发语言·c++
西西弗Sisyphus12 小时前
C++ 最小 Agentic Loop 实现 - 回调函数系列 - typedef 封装(4)
c++
笑鸿的学习笔记12 小时前
C++笔记之信号量和引用计数的概念是否等价?
java·c++·笔记
real_metrix14 小时前
【教程】C/C++ 基础系列 - 内存泄漏最佳实践
c++·c·内存泄漏