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;
}
相关推荐
weixin_307779132 分钟前
C++代码实现MATLAB中的pade函数功能
开发语言·c++·算法·matlab
smj2302_796826525 分钟前
解决leetcode第4064题至多一次取反能被k整除的最长子数组II
python·算法·leetcode
AIGC小尼9 分钟前
ACE-Step-1.5 本地 AI 音乐模型实战|text2music 歌词转人声,部署脚本、参数调优与排坑全记录
人工智能·算法·comfyui·ai漫剧
ProcessOn官方账号9 分钟前
java IO操作 你快速认识IO的相关基本知识
java·开发语言
YOLO数据集集合16 分钟前
树木检测数据集 | 树木检测 树种分类 航拍林业 森林监测9131期
人工智能·算法·机器学习·分类·数据挖掘·林业·树种分类
青山木21 分钟前
Hot 100 --- 下一个排列
java·数据结构·算法·leetcode
垆边人似月.24 分钟前
字符串重排后最大字典序
算法·leetcode·职场和发展
码流子25 分钟前
AI稽核精灵-Agent落地
大数据·人工智能·物联网·算法·系统架构
神仙别闹26 分钟前
基于C++实现的(控制台)学校开课查询系统
开发语言·c++
微三云生态系统架构师-彭丹34 分钟前
排队免单资金池专户存管与返本算法:队列模型与熔断保护
算法·熔断机制·排队免单·消费增值·资金池·队列系统·返本算法