C++Day2

cpp 复制代码
#include <iostream>

using namespace std;


class Rect
{
private:
    int width;
    int height;
public:
    void init(int w,int h)
    {
        width = w;
        height = h;
    }
    void set_w(int w)
    {
        width = w;
    }
    void set_h(int h)
    {
        height = h;
    }
    void show()
    {
        cout << "矩形的周长为:" << (width + height) * 2 << endl;
        cout << "矩形的面积为:" << width * height << endl;
    }
};
int main()
{
   Rect r1;
   r1.init(15,20);
   r1.show();
   r1.set_h(5);
   r1.set_w(8);
   r1.show();
    return 0;
}
相关推荐
墨白曦煜17 小时前
RocketMQ 实战:揭秘 @RocketMQMessageListener 的反序列化魔法与“万能”消费策略
开发语言·python·rocketmq
东方-教育技术博主17 小时前
AI 写一个可被 Blueprint 调用的角色技能系统
开发语言
m0_7488735518 小时前
C++与Rust交互编程
开发语言·c++·算法
ZTLJQ1 天前
序列化的艺术:Python JSON处理完全解析
开发语言·python·json
2401_891482171 天前
多平台UI框架C++开发
开发语言·c++·算法
88号技师1 天前
2026年3月中科院一区SCI-贝塞尔曲线优化算法Bezier curve-based optimization-附Matlab免费代码
开发语言·算法·matlab·优化算法
t198751281 天前
三维点云最小二乘拟合MATLAB程序
开发语言·算法·matlab
无敌昊哥战神1 天前
【LeetCode 257】二叉树的所有路径(回溯法/深度优先遍历)- Python/C/C++详细题解
c语言·c++·python·leetcode·深度优先
m0_726965981 天前
面面面,面面(1)
java·开发语言