C++DAY40

C++DAY40_第1张图片

#include 

using namespace std;

class Rect
{
private:
    int width,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()
    {
        int C = (width + height) * 2;
        int S = width * height;
        cout << "周长是" << C << " 面积是" << S << endl;
    }
};
int main()
{
    int w,h;
    cout << "宽:" << endl;
    cin >> w;
    cout << "高:" << endl;
    cin >> h;
    Rect r1;
    r1.init(w,h);
    r1.show();
    cout << "更改高为:" << endl;
    cin >> h;
    r1.set_h(h);
    cout << "更改宽为:" << endl;
    cin >> w;
    r1.set_w(w);
    r1.show();

    return 0;
}

 

你可能感兴趣的:(c++,算法,开发语言)