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;
}
相关推荐
Dxy1239310216几秒前
Python的zip用法详解
开发语言·python
逑之1 分钟前
C语言笔记3:分支与循环
c语言·开发语言·笔记
黎雁·泠崖9 分钟前
Java入门从零起步:CMD操作+JDK环境搭建+第一个Java程序
java·开发语言
f***24119 分钟前
MATLAB高效算法优化实战指南
开发语言·算法·matlab
智算菩萨11 分钟前
【Python自然语言处理】实战项目:词向量表示完整实现指南
开发语言·python·自然语言处理
CSDN_RTKLIB12 分钟前
【std::vector】避免频繁扩容方法
c++·stl
Blossom.11815 分钟前
联邦迁移学习实战:在数据孤岛中构建个性化推荐模型
开发语言·人工智能·python·深度学习·神经网络·机器学习·迁移学习
yaoxin52112316 分钟前
288. Java Stream API - 创建随机数的 Stream
java·开发语言
superman超哥18 分钟前
迭代器适配器(map、filter、fold等):Rust函数式编程的艺术
开发语言·rust·编程语言·rust map·rust filter·rust fold·rust函数式
yuanmenghao20 分钟前
自动驾驶中间件iceoryx - 同步与通知机制(二)
开发语言·单片机·中间件·自动驾驶·信息与通信