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;
}
相关推荐
阿文的代码库3 分钟前
干货分享|C++运算符重载知识点
java·c++·算法
壹号用户23 分钟前
C++入门(引用)
数据结构·c++
lcj251132 分钟前
【list】手撕C++ list!从0到1实现双向链表,迭代器、const迭代器、模板全解析,面试官都惊呆了!
c++·笔记·链表·list
玖釉-1 小时前
Vulkan Specialization Constants 详解:在“运行时配置”和“编译期优化”之间取得平衡
c++·windows·图形渲染
-FxYaM-1 小时前
【UE】渲染框架学习路径-初次修改源码
服务器·网络·c++·windows·ue5·unreal engine
郝学胜-神的一滴1 小时前
Qt 高级开发 025:打造优雅界面的艺术与高效重构之道
开发语言·c++·qt·程序人生·重构·软件构建·用户界面
froyoisle1 小时前
CSP 真题解析:[CSP-J 2025-T3] 异或和
c++·算法·csp·算法竞赛·信奥赛
彷徨着2 小时前
取石子(C++)
c++
_wyt0012 小时前
洛谷P15799 [GESP202603 五级] 找数 题解
c++·gesp
困意少年2 小时前
C++11 如何减少无意义的拷贝:右值引用、`std::move`、移动语义与完美转发
c++