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;
}
相关推荐
王老师青少年编程7 分钟前
csp信奥赛C++标准模板库STL(12):C++ STL 中的 next_permutation详解
c++·stl·排列·标准模板库·csp·信奥赛·permutation
深盾科技1 小时前
融合C++与Python:兼顾开发效率与运行性能
java·c++·python
代码村新手1 小时前
C++-入门
开发语言·c++
神舟之光1 小时前
VSCode编译运行C/C++程序问题及解决方法
开发语言·c++
坐怀不乱杯魂1 小时前
C++ STL unordered_map/set 实现
开发语言·c++
hetao17338372 小时前
2025-12-21~22 hetao1733837的刷题笔记
c++·笔记·算法
呱呱巨基2 小时前
Linux 进程控制
linux·c++·笔记·学习
罗湖老棍子3 小时前
最小函数值(minval)(信息学奥赛一本通- P1370)
数据结构·c++·算法··优先队列·
肆悟先生3 小时前
3.17 内联函数
c++
仰泳的熊猫3 小时前
1109 Group Photo
数据结构·c++·算法·pat考试