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;
}
相关推荐
吃我一窝jio10 小时前
Python与Go线程模型深度对比
java·开发语言·python
eggwyw10 小时前
C++ union 的一种妙用法
开发语言·c++
ShineWinsu12 小时前
对于Qt:QHBoxLayout常见属性以及方法的解析
c++·qt·面试·gui·客户端·布局管理器·水平布局器
starzy199012 小时前
深入理解Scala隐式函数:自动类型转换
开发语言·后端·scala
小七在进步13 小时前
string的实现(1)
c++·笔记·visual studio
布莱克60514 小时前
Swift 循环与控制转移详解:从 for-in 到标签跳转
开发语言·ssh·swift·循环
敲上瘾15 小时前
Qt核心机制:信号与槽详解
开发语言·c++·qt·ui·qt6.3
联犀15 小时前
ai时代复杂项目的golang项目如何更好的与ai共舞:monorepo+gozero
开发语言·人工智能·golang
牢姐与蒯16 小时前
cpp算法之哈希
c++·算法·哈希算法
lcj251117 小时前
[C++] C++11
开发语言·c++·笔记