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;
}
相关推荐
风筝在晴天搁浅3 分钟前
hot100 230.二叉搜索树中第K小的元素
数据结构·算法
June bug12 分钟前
(#数组/链表操作)寻找两个正序数组的中位数
数据结构·python·算法·leetcode·面试·职场和发展·跳槽
通信小呆呆19 分钟前
DDMA MIMO OFDM ISAC:从回波模型到距离-速度图与非相参积累的原理梳理
算法·信息与通信·ofdm·mimo·通信感知一体化
王燕龙(大卫)28 分钟前
linuxptp时间同步
c++
leo__52035 分钟前
电动助力转向(EPS)系统Simulink模型构建与应用
算法
TracyCoder12340 分钟前
LeetCode Hot100(8/100)—— 438. 找到字符串中所有字母异位词
算法·leetcode
郝学胜-神的一滴41 分钟前
深入理解Linux套接字(Socket)编程:从原理到实践
linux·服务器·开发语言·网络·c++·程序人生·算法
程序猿编码43 分钟前
高性能HTTP服务压测工具:设计思路与实现原理(C/C++代码实现)
c语言·网络·c++·网络协议·tcp/ip·http
向前V1 小时前
Flutter for OpenHarmony轻量级开源记事本App实战:笔记编辑器
开发语言·笔记·python·flutter·游戏·开源·编辑器