# 第四次作业

## 2.问题解析：

class point {
public:
void initpoint(float x = 0, float y = 0)
{
this->x = x;this->y = y;
}
void move(float offx = 0, float offy = 0)
{
x += offx;y += offy;
}
float getx() const { return x; }
float gety() const { return y; }

private:
float x;
float y;
};
#include "point.h"
class rectangle :private point{
public:
void initrectangle(float x, float y, float w, float h)
{
initpoint(x, y);
this->w = w;
this->h = h;
}
void move(float offx, float offy)
{
point::move(offx, offy);
}
float getx()const { return point::getx(); }
float gety()const { return point::gety(); }
float getw()const { return w; }
float geth()const { return h; }
private:
float w,h;
};
#include "pch.h"
#include <iostream>
#include"point.h"
#include"rectangle.h"

using namespace std;

int main()
{
rectangle rect;
rect.initrectangle(2, 3, 20, 10);
rect.move(3, 2);
cout << "the data of rect(x,y,w,h)" << endl;
cout << rect.getx() << ","
<< rect.gety() << ","
<< rect.getw() << ","
<< rect.geth() << endl;
return 0;
}


## 3.问题总结：

posted @ 2019-10-12 10:21  超级无敌57  阅读(106)  评论(0编辑  收藏  举报