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;
}
相关推荐
米粒125 分钟前
力扣算法刷题 Day 31 (贪心总结)
算法·leetcode·职场和发展
乱蜂朝王26 分钟前
使用 C# 和 ONNX Runtime 部署 PaDiM 异常检测模型
开发语言·c#
少许极端29 分钟前
算法奇妙屋(四十)-贪心算法学习之路7
java·学习·算法·贪心算法
波诺波30 分钟前
p1项目system_model.py代码
开发语言·python
危笑ioi30 分钟前
helm部署skywalking链路追踪 java
java·开发语言·skywalking
静心观复39 分钟前
Python 虚拟环境与 pipx 详解
开发语言·python
卷心菜狗41 分钟前
Re.从零开始使用Python构建本地大模型网页智慧聊天机器人
开发语言·python·机器人
AlenTech1 小时前
647. 回文子串 - 力扣(LeetCode)
算法·leetcode·职场和发展
py有趣1 小时前
力扣热门100题之合并两个有序链表
算法·leetcode·链表
书到用时方恨少!1 小时前
Python NumPy 使用指南:科学计算的基石
开发语言·python·numpy