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;
}

相关推荐
开发者工具分享21 分钟前
如何应对敏捷转型中的团队阻力
开发语言
gregmankiw28 分钟前
C#调用Rust动态链接库DLL的案例
开发语言·rust·c#
roman_日积跬步-终至千里43 分钟前
【Go语言基础【20】】Go的包与工程
开发语言·后端·golang
music&movie1 小时前
算法工程师认知水平要求总结
人工智能·算法
秦少游在淮海1 小时前
C++ - string 的使用 #auto #范围for #访问及遍历操作 #容量操作 #修改操作 #其他操作 #非成员函数
开发语言·c++·stl·string·范围for·auto·string 的使用
const5441 小时前
cpp自学 day2(—>运算符)
开发语言·c++
心扬1 小时前
python生成器
开发语言·python
阿蒙Amon1 小时前
06. C#入门系列【自定义类型】:从青铜到王者的进阶之路
开发语言·c#
虾球xz1 小时前
CppCon 2015 学习:CLANG/C2 for Windows
开发语言·c++·windows·学习
laocui12 小时前
Σ∆ 数字滤波
人工智能·算法