consolidate all repos to one for archive
This commit is contained in:
33
semester_2/programiranje_2/primeri/Example14/Composite.cpp
Normal file
33
semester_2/programiranje_2/primeri/Example14/Composite.cpp
Normal file
@@ -0,0 +1,33 @@
|
||||
|
||||
#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();
|
||||
}
|
||||
Reference in New Issue
Block a user