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;
}
相关推荐
GHL2842710902 分钟前
Docker Desktop 启动报错“Virtualization support not detected“
c++·docker·容器
开发者小天4 分钟前
python中的class类
开发语言·python
2501_9333295517 分钟前
Infoseek数字公关AI中台技术解析:如何构建企业级舆情监测与智能处置系统
开发语言·人工智能
m0_7066532317 分钟前
基于C++的爬虫框架
开发语言·c++·算法
梵刹古音18 分钟前
【C语言】 数据类型的分类
c语言·开发语言
diediedei24 分钟前
嵌入式数据库C++集成
开发语言·c++·算法
君义_noip26 分钟前
洛谷 P3388 【模板】割点(割顶)
c++·算法·图论·信息学奥赛·csp-s
xie0510_26 分钟前
string模拟实现
开发语言·c++·算法
FAFU_kyp32 分钟前
RISC0_ZERO项目在macOs上生成链上证明避坑
开发语言·后端·学习·macos·rust
xuedingbue43 分钟前
数据结构与顺序表:高效数据管理秘籍
数据结构·算法·链表