11.29 c++类

11.29 c++类_第1张图片
 

#include 

using namespace std;
class Rect
{
private:
    double high;
    double wide;
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)
{
    high=h;
    wide=w;
}
void Rect::set_h(int h)
{
    high=h;
}
void Rect::set_w(int w)
{
    wide=w;
}
void Rect::show()
{
    cout << "周长" << 2*(wide+high) << endl;
    cout << "面积" << wide*high << endl;
}
int main()
{
    Rect r;
    cout << "宽为5,高为6" << endl;
    r.init(5,6);
    r.show();
    cout << "修改宽为4" << endl;
    r.set_w(4);
    r.show();
    cout << "修改高为5" <

11.29 c++类_第2张图片

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