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;
}
相关推荐
Cinema KI21 小时前
一键定位,哈希桶的极速魔法
数据结构·c++·算法·哈希算法
AI殉道师21 小时前
FastScheduler:让 Python 定时任务变得优雅简单
开发语言·python
曾几何时`21 小时前
二分查找(九)2300. 咒语和药水的成功对数
数据结构·算法
D_evil__21 小时前
【Effective Modern C++】第三章 转向现代C++:8. 优先选用nullptr,而非0或NULL
c++
花间相见21 小时前
【JAVA开发】—— HTTP常见请求方法
java·开发语言·http
楼田莉子21 小时前
Linux系统小项目——“主从设计模式”进程池
linux·服务器·开发语言·c++·vscode·学习
走粥21 小时前
选项式API与组合式API的区别
开发语言·前端·javascript·vue.js·前端框架
从此不归路21 小时前
Qt5 进阶【7】网络请求与 REST API 实战:QNetworkAccessManager 深度应用
开发语言·c++·qt
We་ct21 小时前
LeetCode 12. 整数转罗马数字:从逐位实现到规则复用优化
前端·算法·leetcode·typescript
绿算技术21 小时前
重塑智算存储范式:绿算技术NVMe-oF芯片解决方案全景剖析
人工智能·算法·gpu算力