jezvgg 11 months ago
parent
commit
0e9c5c7801
4 changed files with 76 additions and 0 deletions
  1. 24 0
      Polygon.cpp
  2. 32 0
      Polygon.h
  3. 14 0
      makefile
  4. 6 0
      polygon_main.cpp

+ 24 - 0
Polygon.cpp

@@ -0,0 +1,24 @@
+#include "Polygon.h"
+#include <iostream>
+#include <algorithm>
+
+Polygon::init(vector<struct Point> init_points)
+{
+    points = init_points;
+}
+
+Polygon::Polygon(vector<struct Point> init_points)
+{
+    init(init_points);
+}
+
+void Polygon::sort_points()
+{
+    return std::sort(points.begin(), points.end(), [](struct Point lhs, struct Point rhs) {return l2(lhs.x, lhs.y, 0.0, 0.0) < l2(rhs.x, rhs.y, 0.0, 0.0); });
+}
+
+double Polygon::calc_perimiter()
+{
+    sort_points();
+    std::cout << points << std::endl;
+}

+ 32 - 0
Polygon.h

@@ -0,0 +1,32 @@
+#include "Figure.h"
+#include <vector>
+#include <string>
+
+using namespace std;
+
+class Polygon: public Figure
+{
+    private:
+    vector<Point> points;
+
+    void init(vector<struct Point> init_points);
+    void sort_points();
+
+    public:
+    template <typename T>
+    Polygon(vector<T> init_points)
+    {   
+        for(int i = 0; i < init_points.lenght; i+=2)
+            struct Point p;
+            p.x = init_points[i];
+            p.y = init_points[i+1];
+            points.push_back(p);
+    }
+
+    Polygon(vector<struct Point> init_points);
+    Polygon(string file_path);
+
+    double calc_area();
+    double calc_perimiter();
+    void name();
+};

+ 14 - 0
makefile

@@ -40,6 +40,20 @@ ellips_main.o: ellips_main.cpp
 Ellips.o: Figure.o Ellips.cpp
 	g++ -c Figure.o Ellips.cpp
 
+
+polygon: Figure.o Polygon.o polygon_main.o
+	g++ Figure.o Polygon.o polygon_main.o
+
+
+polygon_main.o: polygon_main.cpp
+	g++ polygon_main.cpp
+
+
+Polygon.o: Figure.o Polygon.cpp
+	g++ -c Figure.o Polygon.cpp
+
+
+
 Figure.o: Figure.cpp
 	g++ -c Figure.cpp
 

+ 6 - 0
polygon_main.cpp

@@ -0,0 +1,6 @@
+#include "Polygon.h"
+#include <vector>
+
+int main() {
+    return 0;
+}