(10%)
Determine whether the following code is correct or not. If it is
correct, predict its output. If it is incorrect, point out the
mistake(s).
// Inheritance in Classes (P.433)
#include <iostream>
class CRect {
public:
int left; int top;
int right; int bottom;
CRect(int L, int T, int R, int B) {
left = L; top = T;
right = R; bottom = B;
}
};
class MyRect : public CRect {
public:
// Constructor Operation in a Derived Class (P.440)
MyRect(int L, int T, int R, int B): CRect(L, T, R, B) {}
void Move(int dx, int dy) {
left += dx; right += dx;
top += dy; bottom += dy;
}
void Print() {
std::cout << '(' << left << ',' << top << ")-("
<< right << ',' << bottom << ")\n";
}
};
int main()
{
MyRect bRect(10, 20, 30, 40);
bRect.Print();
bRect.Move(10, -5);
bRect.Print();
return 0;
}