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;
}
相关推荐
传奇开心果编程2 小时前
【Rust入门知识点学与练】第24课:Trait 基础
开发语言·学习·rust
wuminyu5 小时前
Kafka中sendfile与mmap实现机制解析
java·linux·c语言·jvm·c++
言乐67 小时前
Python加速器4跨境网络加速器
运维·服务器·开发语言·网络·python
金金计较.7 小时前
Go语言-3
java·开发语言·golang
张小凡vip8 小时前
python--爬虫--经验积累的遇到的坑
开发语言·爬虫·python
Wang's Blog9 小时前
Java框架快速入门: Spring Security+OAuth2之云服务集成与多因子认证设计
java·开发语言·spring
门思科技9 小时前
LoRaWAN 网络容量估算:一个 SX1302 网关到底能带多少设备
开发语言·网络·php
大草原的小灰灰9 小时前
Python基础语法
开发语言·python
无小道10 小时前
C++——列表初始化
c++·列表初始化
blueSatchel10 小时前
c++action 编写(ros-humble)
c++·ros2