哪位大神知道这个C++程序怎么写?求解🙂
#include <iostream>
using namespace std;
class Rect
{
private:
int x;
int y;
int w;
int h;
public:
Rect(int x,int y,int w,int h)
{
this->x = x;
this->y = y;
this->w = w;
this->h = h;
}
void move(int x,int y)
{
this->x = x;
this->y = y;
}
void size(int w,int h)
{
this->w = w;
this->h = h;
}
int* where()
{
int* a = new int[2];
a[0] = x + w;
a[1] = y - h;
return a;
}
int area()
{
return w * h;
}
};
int main()
{
Rect r(5,5,2,3);
int *a = r.where();
cout << a[0] << " " << a[1] << " " << r.area() << endl;
r.size(3,3);
r.move(4,4);
a = r.where();
cout << a[0] << " " << a[1] << " " << r.area() << endl;
return 0;
}