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;
}
相关推荐
互联网中的一颗神经元13 小时前
06. Small 对象分配:mcache 无锁路径
开发语言·golang
PPPPickup13 小时前
金证秋招笔试
java·开发语言
不正经学生13 小时前
C语言结构体:自定义数据类型,让变量打包出行
java·c语言·开发语言·数据结构·算法
老一岁14 小时前
c问题总结(1)
c语言·开发语言
加油码14 小时前
动静态库的链接底层原理(进阶版)
linux·c++
一木 之林14 小时前
三、内存管理、指针与堆栈
c语言·jvm·c++
林森lsjs14 小时前
队列 FIFO 原理 & 手撕两种队列实现(链表 + 循环数组)—数据结构陆
java·开发语言·数据结构·队列
何以解忧,唯有..15 小时前
Python time 模块详解:时间处理与日期操作指南
开发语言·python
caimouse15 小时前
ReactOS 窗口系统分析(20):光标与图标 — cursoricon.c
c语言·开发语言
初夏睡觉15 小时前
原创题目 - 空壳恋爱
c++·算法·dp·oi·信息学·原创题目·值得挑战的题目