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;
}
相关推荐
阿Y加油吧22 分钟前
算法实战笔记:LeetCode 169 多数元素 & 75 颜色分类
笔记·算法·leetcode
t***54428 分钟前
如何在Dev-C++中选择Clang编译器
开发语言·c++
橙子1991101629 分钟前
Java 基础相关
java·开发语言
不要秃头的小孩30 分钟前
力扣刷题——509. 斐波那契数
python·算法·leetcode·动态规划
汉克老师1 小时前
GESP2023年9月认证C++三级( 第一部分选择题(9-15))
c++·gesp三级·gesp3级
星越华夏1 小时前
python——三角函数用法
开发语言·python
代码中介商1 小时前
C语言数据存储深度解析:从原码反码补码到浮点数存储
c语言·开发语言·内存
We་ct1 小时前
LeetCode 120. 三角形最小路径和:动态规划详解
前端·javascript·算法·leetcode·typescript·动态规划