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;
}
相关推荐
卡提西亚几秒前
C++笔记-34-map/multimap容器
开发语言·c++·笔记
lxh011320 分钟前
螺旋数组题解
前端·算法·js
2***B44921 分钟前
C++在金融中的QuantLibXL
开发语言·c++·金融
A***071735 分钟前
C++在游戏中的阴影渲染
开发语言·c++·游戏
2401_8370885039 分钟前
Redisson的multilock原理
java·开发语言
合作小小程序员小小店1 小时前
桌面开发,在线%超市销售管理%系统,基于vs2022,c#,winform,sql server数据
开发语言·数据库·microsoft·c#
czlczl200209251 小时前
算法:二叉树的公共祖先
算法
Q***l6872 小时前
C++在计算机图形学中的渲染
开发语言·c++
0和1的舞者2 小时前
《网络编程核心概念与 UDP Socket 组件深度解析》
java·开发语言·网络·计算机网络·udp·socket
惜棠2 小时前
visual code + rust入门指南
开发语言·后端·rust