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;
}
相关推荐
女神下凡3 小时前
芯参谋(11): 各种存储芯片电路设计
开发语言·嵌入式硬件
冬夜戏雪3 小时前
笔试的Scanner in Scanner out
java·开发语言
Zane1994123 小时前
HashSet、TreeSet、LinkedHashSet:底层都是“套壳“
java·开发语言
小小龙学IT4 小时前
ONNX Runtime 开源 AI 推理引擎深度解析:从模型部署到边缘 AI 加速的全栈实战
c++·人工智能·开源
五_谷_丰_登4 小时前
平衡二叉树(AVL)讲解二
数据结构·c++
麻花20134 小时前
Win10、win11清理C盘的bat文件内容
开发语言
露天赏雪4 小时前
掘金小册样章
java·开发语言·人工智能·ai编程
知无不研4 小时前
std::function在使用时遇到的问题
c++·算法·st·function
一晌小贪欢4 小时前
python-第15天:Python 列表推导式
开发语言·python·excel·数据可视化·python办公
Java后端的Ai之路4 小时前
17、Python - 观察者模式
开发语言·人工智能·python·观察者模式·外观模式