C++Day2

cpp 复制代码
#include <iostream>

using namespace std;


class Rect
{
private:
    int width;
    int height;
public:
    void init(int w,int h)
    {
        width = w;
        height = h;
    }
    void set_w(int w)
    {
        width = w;
    }
    void set_h(int h)
    {
        height = h;
    }
    void show()
    {
        cout << "矩形的周长为:" << (width + height) * 2 << endl;
        cout << "矩形的面积为:" << width * height << endl;
    }
};
int main()
{
   Rect r1;
   r1.init(15,20);
   r1.show();
   r1.set_h(5);
   r1.set_w(8);
   r1.show();
    return 0;
}
相关推荐
小七在进步3 小时前
string的使用(1)
c++·visual studio
SomeOtherTime3 小时前
Rust所有权(AI回答)
开发语言·后端·rust
Easyhood3 小时前
Android 开发入门实践(十四):Compose 副作用入门与四个常用 API
android·开发语言·kotlin·android jetpack·compose
白杨尚青4 小时前
C++进阶篇(六):map 和 set 的模拟实现——用红黑树封装 mymap/myset(迭代器 + operator[])
开发语言·c++·迭代器·stl·set·map·红黑树
kloc7 小时前
聊天室项目入口网关子服务的实现
linux·c++
饮水桶_T8 小时前
JAVA IO流笔记
开发语言·数据结构·算法
csdn_aspnet10 小时前
C++ 3个有序点的方向(Orientation of 3 ordered points)
c++·算法
Felven10 小时前
C. Brr Brrr Patapim
c语言·开发语言
小七在进步11 小时前
string的使用(2)
c++
路溪非溪11 小时前
python标准库使用总结
开发语言·python