Website Summary Files Commits Branches @commit @diff @stats
path: root / Polymorphism / Shape.cpp
diff options
context:
space:
mode:
Commit495fe9ae299e81c213161d992d05cc11a403a1d7 (patch)
Author
 Angel Dimitriev <achi_d@abv.bg>
2020-05-20 03:02:00 +0300
Committer
 GitHub <noreply@github.com>
2020-05-20 03:02:00 +0300
Files8d71f8728ddfcf86d34ec1690b144067a3e43887 /Polymorphism/Shape.cpp
Object-oriented_programming_FMI-495fe9ae299e81c213161d992d05cc11a403a1d7.tar
Object-oriented_programming_FMI-495fe9ae299e81c213161d992d05cc11a403a1d7.tar.gz
Object-oriented_programming_FMI-495fe9ae299e81c213161d992d05cc11a403a1d7.zip
Parentb7a69d6934a940bcdd8a61df3e6d1df439dc1b0a (diff)
Add files via upload
1 files changed, 50 insertions, 0 deletions
-rw-r--r--Polymorphism/Shape.cpp50
diff --git a/Polymorphism/Shape.cpp b/Polymorphism/Shape.cpp
new file mode 100644
index 0000000..787ec82
--- /dev/null
+++ b/Polymorphism/Shape.cpp
@@ -0,0 +1,50 @@
+#include "Shape.h"
+
+Shape::Shape(int pointsCount)
+{
+ points = new Point[pointsCount];
+ this->pointsCount = pointsCount;
+}
+
+void Shape::setPoint(int x, int y, int ind)
+{
+ Point current(x, y);
+ points[ind] = current;
+
+}
+
+const Point& Shape::getPoint(int ind)
+{
+ return points[ind];
+}
+
+void Shape::CopyFrom(const Shape& other)
+{
+ points = new Point[other.pointsCount];
+ pointsCount = other.pointsCount;
+
+ for (int i = 0; i < pointsCount; i++)
+ points[i] = other.points[i];
+}
+void Shape::Free()
+{
+ delete[] points;
+ pointsCount = 0;
+}
+Shape::Shape(const Shape& other)
+{
+ CopyFrom(other);
+}
+Shape& Shape::operator=(const Shape& other)
+{
+ if (this != &other)
+ {
+ Free();
+ CopyFrom(other);
+ }
+ return *this;
+}
+Shape::~Shape()
+{
+ Free();
+}