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;
}
相关推荐
蒸蒸yyyyzwd11 分钟前
cpp 选手备战秋招学习笔记 day36
c++
用户695861067271124 分钟前
从源码到加载器:__attribute__((constructor)) / __attribute__((destructor))的跨平台实现原理详解
c++
余额瞒着我当琳1 小时前
C++多态深入解析:多态概念,多态实现条件,虚函数表与内存分布,常见问题及注意事项
c++·算法
ocean21032 小时前
2025-2026年C++专题大厂面试高频问题
开发语言·c++·面试
程序猿编码2 小时前
扔掉 Python!纯 C++ 本地跑扩散 TTS,GGML 加持,支持 RK3588 NPU 加速
c++·计算机视觉·大模型·transformer·rk3588·推理·ggml
郝学胜-神的一滴2 小时前
C++20模板元编程 02:吃透模板基础核心四大核心知识点
开发语言·数据结构·c++·程序人生·软件工程·visual studio
代码王同学3 小时前
2026.9.15日C++类和对象学习收获笔记
c语言·c++
刚入门的大一新生3 小时前
Linux-简单设计libc库
linux·c++
6Hzlia4 小时前
【Classic 150 刷题计划】 LeetCode 14. 最长公共前缀 | C++ 纵向扫描法与防越界细节
c++·算法·leetcode
讳疾忌医丶12 小时前
深度拆解 RocksDB 内核:基于 C++17 的 FIFO 调度状态机与温度阶梯自愈设计
java·c++·算法·架构