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;
}
相关推荐
quantdash_cc2 分钟前
如何设计高效率的批量股票数据获取程序?QuantDash Python SDK 全市场行情拉取实战指南
开发语言·python·数据分析·量化交易·股票数据·quantdash
Jul1en_7 分钟前
Matt 与 Uncle Bob 的播客访谈有感
开发语言·经验分享·笔记·ai·开源·github·ai编程
玖玥拾11 分钟前
Lua 基础语法(五)Unity xLua基础配置与 C# 访问 Lua
开发语言·unity·c#·lua
淼澄研学16 分钟前
Sonos空间音频技术解析与Python本地API控制实操
开发语言·python·音视频
研☆香22 分钟前
js中使用的正则表达式
开发语言·javascript·正则表达式
szarron22 分钟前
国产手持式频谱分析仪选型攻略:TFN RC系列 vs HTOOL SA8T频谱分析仪 专业参数对比(军工/路测/调试全覆盖)
开发语言·前端·状态模式
我是唐青枫23 分钟前
C#.NET StructureMap 从依赖注入到项目实战
开发语言·c#·.net
Beyond_System|系统之外26 分钟前
一个网页如何同时适配投影仪、1366×768 和 1920×1080?我重新理解了“自适应布局”
开发语言·css·html
蛋先生DX26 分钟前
内存安全翻车现场的罪魁祸首,根源就在这三步里?
c++·后端·编程语言
小七在进步34 分钟前
C++入门(1)
java·jvm·c++