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;
}
相关推荐
jason成都1 分钟前
IoT 设备监控系统实战:基于 EMQX 的 MQTT 连接监控与数据格式指纹识别
开发语言·python
铭毅天下10 分钟前
EasySearch Rules 规则语法速查手册
开发语言·前端·javascript·ecmascript
承渊政道18 分钟前
【优选算法】(实战体会位运算的逻辑思维)
数据结构·c++·笔记·学习·算法·leetcode·visual studio
YMWM_25 分钟前
print(f“{s!r}“)解释
开发语言·r语言
愤豆28 分钟前
05-Java语言核心-语法特性--模块化系统详解
java·开发语言·python
bksczm29 分钟前
文件流(fstream)
java·开发语言
NGC_661130 分钟前
Java 线程池阻塞队列与拒绝策略
java·开发语言
Frostnova丶31 分钟前
LeetCode 2573. 找出对应 LCP 矩阵的字符串
算法·leetcode·矩阵
小碗羊肉42 分钟前
【从零开始学Java | 第二十二篇】List集合
java·开发语言
m0_7167652344 分钟前
C++提高编程--STL常用容器(set/multiset、map/multimap容器)详解
java·开发语言·c++·经验分享·学习·青少年编程·visual studio