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;
}
相关推荐
Mr_Xuhhh3 小时前
YAML相关
开发语言·python
阿巴~阿巴~3 小时前
JsonCpp:C++ JSON处理利器
linux·网络·c++·json·tcp·序列化和反序列化
Promise4853 小时前
贝尔曼公式的迭代求解笔记
笔记·算法
咖啡の猫3 小时前
Python中的变量与数据类型
开发语言·python
前端达人3 小时前
你的App消息推送为什么石沉大海?看Service Worker源码我终于懂了
java·开发语言
汤姆yu4 小时前
基于springboot的电子政务服务管理系统
开发语言·python
全栈师4 小时前
C#中控制权限的逻辑写法
开发语言·c#
S***q1924 小时前
Rust在系统工具中的内存安全给代码上了三道保险锁。但正是这种“编译期的严苛”,换来了运行时的安心。比如这段代码:
开发语言·后端·rust
打点计时器4 小时前
matlab 解决wfdb工具使用本地数据集报错
开发语言·matlab
zmzb01034 小时前
C++课后习题训练记录Day38
开发语言·c++