33 lines
793 B
C++
33 lines
793 B
C++
|
|
#include "Shape.h"
|
|
#include "Composite.h"
|
|
|
|
Composite::Composite(Shape* s) : Shape(), ptrShape(s), ptrNext(nullptr) {
|
|
}
|
|
|
|
void Composite::add(Shape* s) {
|
|
if (!ptrShape) ptrShape = s;
|
|
else {
|
|
if (!ptrNext) ptrNext = new Composite(s);
|
|
else ptrNext->add(s);
|
|
}
|
|
}
|
|
|
|
double Composite::area() const {
|
|
if (!ptrNext) return ptrShape->area();
|
|
else return ptrShape->area() + ptrNext->area();
|
|
}
|
|
|
|
void Composite::print() const {
|
|
if (ptrShape) ptrShape->print();
|
|
if (ptrNext) ptrNext->print();
|
|
}
|
|
void Composite::relMove(int x1, int y1) {
|
|
if (ptrShape) ptrShape->relMove(x1, y1);
|
|
if (ptrNext) ptrNext->relMove(x1, y1);
|
|
}
|
|
|
|
void Composite::deleteRec() {
|
|
if (ptrShape) delete ptrShape;
|
|
if (ptrNext) ptrNext->deleteRec();
|
|
} |