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;
}
相关推荐
感哥2 小时前
C++ std::set
c++
Fanxt_Ja2 小时前
【LeetCode】算法详解#15 ---环形链表II
数据结构·算法·leetcode·链表
侃侃_天下2 小时前
最终的信号类
开发语言·c++·算法
茉莉玫瑰花茶2 小时前
算法 --- 字符串
算法
博笙困了2 小时前
AcWing学习——差分
c++·算法
NAGNIP2 小时前
认识 Unsloth 框架:大模型高效微调的利器
算法
NAGNIP2 小时前
大模型微调框架之LLaMA Factory
算法
echoarts2 小时前
Rayon Rust中的数据并行库入门教程
开发语言·其他·算法·rust
Python技术极客3 小时前
一款超好用的 Python 交互式可视化工具,强烈推荐~
算法
徐小夕3 小时前
花了一天时间,开源了一套精美且支持复杂操作的表格编辑器tablejs
前端·算法·github