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;
}
相关推荐
fish_xk2 小时前
c++中的引用和数组
开发语言·c++
有点。5 小时前
C++ ⼀级 2024 年 03 ⽉
c++
酒尘&5 小时前
JS数组不止Array!索引集合类全面解析
开发语言·前端·javascript·学习·js
冬夜戏雪5 小时前
【java学习日记】【2025.12.7】【7/60】
java·开发语言·学习
xwill*5 小时前
分词器(Tokenizer)-sentencepiece(把训练语料中的字符自动组合成一个最优的子词(subword)集合。)
开发语言·pytorch·python
CC.GG5 小时前
【C++】二叉搜索树
java·c++·redis
咖啡の猫6 小时前
Python列表的查询操作
开发语言·python
Savior`L6 小时前
二分算法及常见用法
数据结构·c++·算法
深海潜水员6 小时前
OpenGL 学习笔记 第一章:绘制一个窗口
c++·笔记·学习·图形渲染·opengl
quikai19816 小时前
python练习第三组
开发语言·python