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;
}
相关推荐
Never_Satisfied5 小时前
在JavaScript / HTML中,触发某个对象的click事件
开发语言·javascript·html
lly2024066 小时前
ionic 下拉刷新:实现与优化指南
开发语言
米羊1216 小时前
Spring 框架漏洞
开发语言·python
键盘鼓手苏苏6 小时前
Flutter for OpenHarmony:cider 自动化版本管理与变更日志生成器(发布流程标准化的瑞士军刀) 深度解析与鸿蒙适配指南
运维·开发语言·flutter·华为·rust·自动化·harmonyos
IT 行者6 小时前
ZeroClaw:Rust 驱动的下一代 AI Agent 基础设施
开发语言·人工智能·rust
IT 行者6 小时前
AI Agent 平台横评:ZeroClaw vs OpenClaw vs Nanobot
开发语言·人工智能·rust
BigNiu6 小时前
rust里mut 和遮蔽之间的区别
开发语言·rust
许同6 小时前
JS-WPS 自动化办公(5)多Sheet整合
开发语言·前端·javascript
wjs20246 小时前
SVG 在线编辑器:设计自由,创意无限
开发语言
进击的荆棘6 小时前
算法——二分查找
c++·算法·leetcode