c++day2

cpp 复制代码
#include <iostream>

using namespace std;

class Rect
{
    int width;
    int height;
public:
    void init(int w,int h);
    void set_w(int w);
    void set_h(int h);
    void show();
};
void Rect::init(int w,int h)
{
    this->width = w;
    this->height = h;
}
void Rect::set_w(int w)
{
     this->width = w;
}
void Rect::set_h(int h)
{
     this->height = h;
}
void Rect::show()
{
    cout << "周长为 " << width*2+height*2 << endl;
    cout << "面积为 " << width*height << endl;
}
int main()
{
    Rect s1;
    s1.init(1,2);
    s1.set_w(2);
    s1.set_h(4);
    s1.show();
    return 0;
}

相关推荐
minji...3 分钟前
C++ STL之list的使用
开发语言·c++
万粉变现经纪人4 分钟前
如何解决pip安装报错ModuleNotFoundError: No module named ‘python-dateutil’问题
开发语言·ide·python·pycharm·pandas·pip·httpx
Sammyyyyy15 分钟前
macOS是开发的终极进化版吗?
开发语言·macos·开发工具
青草地溪水旁26 分钟前
23 种设计模式
开发语言·c++·设计模式
一碗白开水一27 分钟前
【第19话:定位建图】SLAM点云配准之3D-3D ICP(Iterative Closest Point)方法详解
人工智能·算法
草履虫建模29 分钟前
在 RuoYi 中接入 3D「园区驾驶舱」:Vue2 + Three.js + Nginx
运维·开发语言·javascript·spring boot·nginx·spring cloud·微服务
编码浪子29 分钟前
趣味学RUST基础篇(函数式编程闭包)
开发语言·算法·rust
MC皮蛋侠客39 分钟前
使用python test测试http接口
开发语言·python·http
Want5951 小时前
C/C++圣诞树②
c语言·c++·算法
胡耀超1 小时前
5、Python-NumPy科学计算基础
开发语言·人工智能·python·深度学习·numpy