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 分钟前
C/C++ 面向对象编程(OOP)(进阶)
java·c语言·c++
mayaairi1 小时前
JS BOM完全指南(二):事件轮询、三大尺寸家族与浏览器对象详解
开发语言·javascript·ecmascript
technology_x1 小时前
液冷超充站设备厂家哪家好?2026年功率与散热对比
java·开发语言
SurpriseDPD1 小时前
bpftrace‑tasks 工具代码分析
开发语言·python
千谦阙听1 小时前
C++篇:类和对象(上)
开发语言·c++
许彰午2 小时前
07-SqlBuilder六法
java·开发语言·低代码·架构
BS30813_vx2 小时前
【编号:01652】Spring Boot村务管理系统:财务公开、党建活动与计生服务一体化实战
开发语言·python
Jul1en_2 小时前
【Java 脚手架】封装通用工具类-3
java·开发语言·redis·缓存·ai·bootstrap·rabbitmq
学习星球2 小时前
2026年AI Agent全栈开发实战——从Prompt到Production
开发语言·人工智能·prompt
_Narcissus_2 小时前
分治&递归
数据结构·c++·笔记·算法·leetcode·递归·分治