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;
}
相关推荐
U-52184F697 分钟前
深入理解“隐式共享”与“写时复制”:从性能魔法到内存深坑
java·数据库·算法
wheelmouse778811 分钟前
网络排查基础与实战指南:Ping 与 Telnet
开发语言·网络·php
pp起床26 分钟前
Part02:基本概念以及基本要素
大数据·人工智能·算法
lzh2004091930 分钟前
红黑树详解
算法
敲代码的嘎仔34 分钟前
Java后端开发——真实面试汇总(持续更新)
java·开发语言·程序人生·面试·职场和发展·八股
U-52184F6937 分钟前
深度解析:从 Qt 的 Q_D 宏说起,C++ 工业级 SDK 是如何保证 ABI 稳定性的
数据库·c++·qt
迈巴赫车主43 分钟前
蓝桥杯20560逃离高塔
java·开发语言·数据结构·算法·职场和发展·蓝桥杯
泯仲1 小时前
Ragent项目7种设计模式深度解析:从源码看设计模式落地实践
java·算法·设计模式·agent
dulu~dulu1 小时前
算法---寻找和为K的子数组
笔记·python·算法·leetcode
moonsea02031 小时前
【无标题】
算法