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;
}
相关推荐
222you16 分钟前
Java线程的三种创建方式
java·开发语言
云上漫步者22 分钟前
深度实战:Rust交叉编译适配OpenHarmony PC——unicode_width完整适配案例
开发语言·后端·rust·harmonyos
漫漫求25 分钟前
Java内存模型【JMM】、JVM内存模型
java·开发语言·jvm
wanderist.27 分钟前
2025年蓝桥杯省赛C++大学A组
c++·算法·蓝桥杯
田姐姐tmner31 分钟前
Python 全面语法指南
开发语言·python
月上林梢37 分钟前
QT圆形加载进度条
数据库·c++·qt·进度条
啊董dong37 分钟前
noi-2025年12月16号作业
数据结构·c++·算法·noi
white-persist40 分钟前
【攻防世界】reverse | simple-check-100 详细题解 WP
c语言·开发语言·汇编·数据结构·c++·python·算法
wuguan_1 小时前
C#中的静态成员、常量和只读变量
开发语言·c#
张人玉1 小时前
C# 与西门子 PLC 通信:地址相关核心知识点
开发语言·microsoft·c#·plc