请在下面程序的横线处填上适当内容,以使程序完整,并使程序的输出为: The data of rect(X,Y,W,H): (6,8,3,4) #include <iostream> using namespace std; class Point { public: Point(int i = 0, int j = 0) { x = i; y = j; } void move(int xOff, int yOff) { x += xOff; y += yOff; } int getX() { return x; } int getY() { return y; } private: int x, y; }; class Rectangle : private Point { public: Rectangle(int xi, int yi, int wi, int hi) : { w = wi; h = hi; } //(1) void move(int xOff, int yOff) { ; } //(2) int getX() { ; } //(3) int getY() { ; } //(4) int getW() { ; } //(5) int getH() { ; } //(6) private: int w, h; }; int main() { Rectangle rect(1, 2, 3, 4); rect.move(5, 6); cout << "The data of rect(X,Y,W,H): (" << rect.getX() << "," << rect.getY() << "," << rect.getW() << "," << rect.getH() << ")" << endl; return 0; }
时间: 2024-01-25 15:03:28 浏览: 128
```
#include <iostream>
using namespace std;
class Point {
public:
Point(int i = 0, int j = 0) {
x = i;
y = j;
}
void move(int xOff, int yOff) {
x += xOff;
y += yOff;
}
int getX() {
return x;
}
int getY() {
return y;
}
private:
int x, y;
};
class Rectangle : private Point {
public:
Rectangle(int xi, int yi, int wi, int hi) : Point(xi, yi) {
w = wi;
h = hi;
}
void move(int xOff, int yOff) {
Point::move(xOff, yOff);
}
int getX() {
return Point::getX();
}
int getY() {
return Point::getY();
}
int getW() {
return w;
}
int getH() {
return h;
}
private:
int w, h;
};
int main() {
Rectangle rect(1, 2, 3, 4);
rect.move(5, 6);
cout << "The data of rect(X,Y,W,H): (" << rect.getX() << ","
<< rect.getY() << "," << rect.getW() << "," << rect.getH() << ")" << endl;
return 0;
}
```
输出结果为: The data of rect(X,Y,W,H): (6,8,3,4)
阅读全文