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;
}
相关推荐
syagain_zsx13 分钟前
算法基础篇 · 03 枚举(C++ 题解)
c++·算法·二进制·枚举
weixin_3077791335 分钟前
C++代码实现MATLAB中的ode23tb函数功能
开发语言·c++·算法·matlab
S_WEAN1 小时前
C++STL - string类的模拟实现
c++
S_WEAN1 小时前
【C++】STL - string类
c++
码匠许师傅2 小时前
【C++三方组件】toml++:人性化的配置文件格式
c++
骑着蜗牛撵大象3273 小时前
告别内存泄漏:LLMManager架构设计与智能指针在AI SDK中的智慧选型
c++·ai·架构
汉克老师3 小时前
CSP-J 2026 初赛试题解析(第二部分:阅读程序题(第一题))精讲
c++·csp-j·小学生·学c++编程
syagain_zsx4 小时前
算法基础篇 · 04 前缀和(C++ 题解)
c++·算法·前缀和
汉克老师5 小时前
CSP-J 2026 初赛试题解析(第三部分:完善程序题(第一题))精讲
c++·csp-j·小学生·学c++编程