c++day2

cpp 复制代码
#include <iostream>

using namespace std;

class Rect
{
    int width;
    int height;
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)
{
    this->width = w;
    this->height = h;
}
void Rect::set_w(int w)
{
     this->width = w;
}
void Rect::set_h(int h)
{
     this->height = h;
}
void Rect::show()
{
    cout << "周长为 " << width*2+height*2 << endl;
    cout << "面积为 " << width*height << endl;
}
int main()
{
    Rect s1;
    s1.init(1,2);
    s1.set_w(2);
    s1.set_h(4);
    s1.show();
    return 0;
}

相关推荐
prinrf('千寻)28 分钟前
MyBatis-Plus 的 updateById 方法不更新 null 值属性的问题
java·开发语言·mybatis
pystraf29 分钟前
LG P9844 [ICPC 2021 Nanjing R] Paimon Segment Tree Solution
数据结构·c++·算法·线段树·洛谷
m0_5557629038 分钟前
Qt缓动曲线详解
开发语言·qt
Funny-Boy1 小时前
菱形继承原理
c++
飞川撸码1 小时前
【LeetCode 热题100】739:每日温度(详细解析)(Go语言版)
算法·leetcode·golang
揽你·入怀2 小时前
数据结构:ArrayList简单实现与常见操作实例详解
java·开发语言
yuhao__z2 小时前
代码随想录算法训练营第六十六天| 图论11—卡码网97. 小明逛公园,127. 骑士的攻击
算法
Echo``2 小时前
3:OpenCV—视频播放
图像处理·人工智能·opencv·算法·机器学习·视觉检测·音视频
AA-代码批发V哥2 小时前
Math工具类全面指南
java·开发语言·数学建模
Nobkins2 小时前
2021ICPC四川省赛个人补题ABDHKLM
开发语言·数据结构·c++·算法·图论