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;
}
相关推荐
D_evil__3 分钟前
【Effective Modern C++】第五章 右值引用、移动语义和完美转发:24. 区分万能引用和右值引用
c++
禹凕8 分钟前
Python编程——进阶知识(多线程)
开发语言·爬虫·python
蜡笔小马21 分钟前
10.Boost.Geometry R-tree 空间索引详解
开发语言·c++·算法·r-tree
IOsetting21 分钟前
金山云主机添加开机路由
运维·服务器·开发语言·网络·php
林开落L35 分钟前
从零开始学习Protobuf(C++实战版)
开发语言·c++·学习·protobuffer·结构化数据序列化机制
林开落L38 分钟前
从入门到了解:Protobuf、JSON、XML 核心解析(C++ 示例)
xml·c++·json·protobuffer·结构化数据序列化机制
牛奔40 分钟前
Go 是如何做抢占式调度的?
开发语言·后端·golang
Queenie_Charlie42 分钟前
stars(树状数组)
数据结构·c++·树状数组
符哥20081 小时前
C++ 进阶知识点整理
java·开发语言·jvm
小猪咪piggy1 小时前
【Python】(4) 列表和元组
开发语言·python