Website Summary Files Commits Branches @commit @diff @stats
path: root / Sem. 13 / ShapeCollection / Shape.cpp
diff options
context:
space:
mode:
Commit110481bee48bdb18f3d635cbc507aac1acc7c694 (patch)
Author
 angeld55 <angel_dimitriev@abv.bg>
2022-05-24 20:10:50 +0300
Committer
 angeld55 <angel_dimitriev@abv.bg>
2022-05-24 20:10:50 +0300
Filesbe2cdf7f8769afd0f456776871b16fe8868ae67b /Sem. 13/ShapeCollection/Shape.cpp
Object-oriented_programming_FMI-110481bee48bdb18f3d635cbc507aac1acc7c694.tar
Object-oriented_programming_FMI-110481bee48bdb18f3d635cbc507aac1acc7c694.tar.gz
Object-oriented_programming_FMI-110481bee48bdb18f3d635cbc507aac1acc7c694.zip
Parentc1a310e69933035fb385f52275e9b80cdad695fc (diff)
added shapes collection
1 files changed, 54 insertions, 0 deletions
-rw-r--r--Sem. 13/ShapeCollection/Shape.cpp54
diff --git a/Sem. 13/ShapeCollection/Shape.cpp b/Sem. 13/ShapeCollection/Shape.cpp
new file mode 100644
index 0000000..468c621
--- /dev/null
+++ b/Sem. 13/ShapeCollection/Shape.cpp
@@ -0,0 +1,54 @@
+#include "Shape.h"
+
+Shape::Shape(size_t pointsCount) : pointsCount(pointsCount)
+{
+ points = new point[pointsCount]; // [0,0], [0,0]....
+}
+
+void Shape::copyFrom(const Shape& other)
+{
+ points = new point[other.pointsCount];
+
+ for (int i = 0; i < other.pointsCount; i++)
+ points[i] = other.points[i];
+
+ pointsCount = other.pointsCount;
+}
+void Shape::free()
+{
+ delete[] points;
+}
+
+Shape::Shape(const Shape& other)
+{
+ copyFrom(other);
+}
+Shape& Shape::operator= (const Shape& other)
+{
+ if (this != &other)
+ {
+ free();
+ copyFrom(other);
+ }
+ return *this;
+}
+Shape::~Shape()
+{
+ free();
+}
+
+const Shape::point& Shape::getPointAtIndex(size_t index) const
+{
+ if (index >= pointsCount)
+ throw std::exception("Invalid point index!");
+
+ return points[index];
+}
+
+void Shape::setPoint(size_t pointIndex, int x, int y)
+{
+ if (pointIndex >= pointsCount)
+ throw std::exception("Invalid point index!");
+
+ points[pointIndex] = point(x, y);
+}