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;
}
相关推荐
共享家95271 分钟前
特殊类的设计
开发语言·c++
嘟嘟w30 分钟前
JVM(Java 虚拟机):核心原理、内存模型与调优实践
java·开发语言·jvm
信奥卷王44 分钟前
2025年9月GESPC++三级真题解析(含视频)
开发语言·c++·算法
喵了几个咪1 小时前
Golang微服务框架kratos实现Socket.IO服务
开发语言·微服务·golang
q***42051 小时前
PHP使用Redis实战实录2:Redis扩展方法和PHP连接Redis的多种方案
开发语言·redis·php
qq_433554542 小时前
C++ 稀疏表
开发语言·c++·算法
Bona Sun2 小时前
单片机手搓掌上游戏机(十二)—esp8266运行gameboy模拟器之编译上传
c语言·c++·单片机·游戏机
帅中的小灰灰2 小时前
C++编程观察者设计模式
数据库·c++·设计模式
z***y8622 小时前
Java数据挖掘开发
java·开发语言·数据挖掘
软件开发技术深度爱好者3 小时前
Python库/包/模块管理工具
开发语言·python