c++day2

cpp 复制代码
#include <iostream>

using namespace std;

class Rect
{
private:
    int width;
    int hight;
public:
    void init(int w, int h);
    void set_w(int w);
    void set_h(int h);
    void show();
};

void Rect::init(int w, int h)
{
    width = w;
    hight = h;
}

void Rect::set_w(int w)
{
    width = w;
}

void Rect::set_h(int h)
{
    hight = h;
}

void Rect::show()
{
    cout << "width = " << width << "\t hight = " << hight << "\t周长 = " << 2*(width+hight) << endl;
    cout << "width = " << width << "\t hight = " << hight << "\t面积 = " << width*hight << endl;
}
int main()
{
    Rect re;
    re.init(4, 5);
    re.show();
    re.set_h(10);
    re.show();
    re.set_w(10);
    re.show();
    return 0;
}
相关推荐
SatVision炼金士4 分钟前
SDK管理本地java版本
java·开发语言·sdkman
奕成则成5 分钟前
Python 创建虚拟环境
开发语言·python
独自破碎E9 分钟前
什么时候@Async会失效?
java·开发语言
梭七y16 分钟前
【力扣hot100题】(105)三数之和
数据结构·算法·leetcode
军军君0120 分钟前
Three.js基础功能学习四:摄像机与阴影
开发语言·前端·javascript·3d·typescript·three·三维
Morwit24 分钟前
如何使用CMake构建Qt新项目
开发语言·c++·qt
独自破碎E28 分钟前
Leetcode1499满足不等式的最大值
java·开发语言
zmzb010335 分钟前
C++课后习题训练记录Day62
开发语言·c++
蕨蕨学AI36 分钟前
【Wolfram语言】36 创建云端应用
开发语言·wolfram
fpcc1 小时前
C++23中的模块应用说明之二整体说明和导出控制
c++·c++23