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;
}
相关推荐
Richard.Wong12 分钟前
qt生成dll供C#调用
开发语言·qt
wang_xin_88824 分钟前
PHP函数
开发语言·php
Immortal__y29 分钟前
php函数
开发语言·php
AI砖家32 分钟前
多商户多租户系统架构设计文档(Java版)
java·开发语言·系统架构·多租户·多商户
计算机内卷的N天1 小时前
CMake与Visual Studio的使用
c++·ide·visual studio
汉克老师1 小时前
GESP2026年3月认证C++七级( 第三部分编程题(1、物流网络))精讲
c++·最短路·gesp7级
鱼子星_2 小时前
【C++】深入剖析list:list及其双向迭代器实现
开发语言·数据结构·c++·笔记·stl·list
脚踏实地皮皮晨2 小时前
003002004_WPF Panel 基类 官方类定义
开发语言·windows·算法·c#·wpf·visual studio
520拼好饭被践踏2 小时前
JAVA+Agent学习day25
java·开发语言·学习
大黄说说2 小时前
Java 并发大坑:volatile、synchronized、Lock 三者如何选择?
java·开发语言