0
点赞
收藏
分享

微信扫一扫

c++ 封装 权限

杏花疏影1 2024-06-05 阅读 5
#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=" << w << endl;
        //cout << "height=" << h << endl;
        cout << "面积=" << width*height << endl;
        cout << "周长=" << (width+height)*2 << endl;
    }

};

int main()
{
    Rect s1;
    s1.init(8,9);
    s1.set_h(10);
    s1.set_w(10);
    s1.show();

    return 0;
}

思维导图:

举报

相关推荐

0 条评论