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;
}
相关推荐
想吃火锅10051 天前
【leetcode】405.数字转换为十六进制数js
开发语言·javascript·ecmascript
专注VB编程开发20年1 天前
AI 生成C# WinForm 窗体 = 目前就是垃圾
开发语言·人工智能·c#
cfm_29141 天前
JVM GC垃圾回收初步了解
java·开发语言·jvm
~小先生~1 天前
Python从入门到放弃(一)
开发语言·python
许彰午1 天前
17_synchronized关键字深度解析
java·开发语言
z落落1 天前
C# 泛型接口和泛型类+泛型约束
开发语言·c#
阿正的梦工坊1 天前
【Rust】02-变量、不可变性与基础类型
开发语言·后端·rust
阿正的梦工坊1 天前
【Rust】08-集合类型、字符串与迭代器入门
开发语言·rust·c#
FuckPatience1 天前
C# 使用泛型协变将派生类类型替换为基类类型
开发语言·c#
张忠琳1 天前
【Go 1.26.4】(Part 1) Go 1.26.4 超深度源码分析 — 总体架构与模块全景
开发语言·golang