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;
}
相关推荐
honker_X28 分钟前
Python字符串全攻略:从入门到精通
开发语言·python
半杯咖啡半行码30 分钟前
Qt 隐式共享(Implicit Sharing)深度解析:机制、陷阱与 Qt6迁移
开发语言·数据库·qt
吃我一窝jio44 分钟前
Docker+Jenkins+K8s全流程部署
java·开发语言·笔记·python
eggwyw1 小时前
C++设计模式之解释器模式
开发语言·c++
mengge.cloud3 小时前
Python基础保姆级!从入门到入土
开发语言·python·云原生·pygame
在爪洼山玩泥巴4 小时前
fastjson2 JSONPath 取不存在路径,为什么会抛 “not support”?
java·开发语言·jsonpath·fastjson
星落梦生14 小时前
SpringAOP基础笔记(7)
java·开发语言
我不会插花弄玉14 小时前
13.多路转接epoll【由浅入深-网络】
网络·c++·epoll
曹牧16 小时前
Java:“刷新雪崩”
java·开发语言
郝学胜-神的一滴16 小时前
Effective STL 条款03:容器中的对象复制要廉价且正确
开发语言·数据结构·c++·算法·rpc·stl