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;
}
相关推荐
小宇的天下8 分钟前
Calibre LVS Circuit Comparison(2)
算法·lvs
zihao_tom9 分钟前
Go环境搭建(vscode调试)
开发语言·vscode·golang
IT方大同19 分钟前
(实时操作系统)线程管理
c语言·开发语言·嵌入式硬件
十年编程老舅32 分钟前
Linux 多线程高并发编程:读写锁的核心原理与底层实现
linux·c++·linux内核·高并发·线程池·多线程·多进程
迈巴赫车主33 分钟前
求最大公约数-欧几里得算法(辗转相除法)
算法·最大公约数
阿kun要赚马内34 分钟前
Python面向对象:@property装饰器
开发语言·前端·python
sunwenjian88636 分钟前
Java进阶--IO流
java·开发语言
wildlily842737 分钟前
C++ Primer 第5版章节题 第十三章(二)
开发语言·c++
lxl13071 小时前
C++算法(15)BFS_FloodFill
算法·宽度优先
意法半导体STM321 小时前
【官方原创】STM32H7双核芯片通过 STlink连接失败问题分析 LAT1654
开发语言·前端·javascript·stm32·单片机·嵌入式硬件