jezvgg 1 рік тому
батько
коміт
22cc8643ae
4 змінених файлів з 76 додано та 0 видалено
  1. 22 0
      Rectangle.cpp
  2. 32 0
      Rectangle.h
  3. 9 0
      makefile
  4. 13 0
      rectangle_main.cpp

+ 22 - 0
Rectangle.cpp

@@ -0,0 +1,22 @@
+#include "Rectangle.h"
+#include <iostream>
+
+Rectangle::Rectangle(struct Point f, struct Point s, struct Point t, struct Point fo)
+{
+    init(f.x, f.y, s.x, s.y, t.x, t.y, fo.x, fo.y);
+}
+
+double Rectangle::calc_area()
+{
+    return l2(x1, y1, x2, y2) * l2(x3, y3, x4, y4);
+}
+
+double Rectangle::calc_perimiter()
+{
+    return l2(x1, y1, x2, y2) * 2 + l2(x3, y3, x4, y4) * 2;
+}
+
+void Rectangle::name()
+{
+    std::cout << "Rectangle" << std::endl;
+}

+ 32 - 0
Rectangle.h

@@ -0,0 +1,32 @@
+#include "Figure.h"
+
+class Rectangle: public Figure
+{
+    private:
+    double x1, y1, x2, y2, x3, y3, x4, y4;
+
+    template <typename T>
+    void init(T X1, T Y1, T X2, T Y2, T X3, T Y3, T X4, T Y4)
+    {
+        x1 = double(X1);
+        y1 = double(Y1);
+        x2 = double(X2);
+        y2 = double(Y2);
+        x3 = double(X3);
+        y3 = double(Y3);
+        x4 = double(X4);
+        y4 = double(Y4);
+    }
+
+    public:
+    template <typename T>
+    Rectangle(T X1, T Y1, T X2, T Y2, T X3, T Y3, T X4, T Y4)
+    {
+        init(X1, Y1, X2, Y2, X3, Y3, X4, Y4);
+    }
+    Rectangle(struct Point f, struct Point s, struct Point t, struct Point fo);
+
+    double calc_area();
+    double calc_perimiter();
+    void name();
+};

+ 9 - 0
makefile

@@ -16,5 +16,14 @@ triangle_main.o: triangle_main.cpp
 Triangle.o: Triangle.cpp
 	g++ -c Triangle.cpp
 
+rectangle: Rectangle.o rectangle_main.o
+	g++ Rectangle.o rectangle_main.o
+
+rectangle_main.o: rectangle_main.cpp
+	g++ -c rectangle_main.cpp
+
+Rectangle.o: Rectangle.cpp
+	g++ -c Rectangle.cpp
+
 clean:
 	rm -rf *.o all

+ 13 - 0
rectangle_main.cpp

@@ -0,0 +1,13 @@
+#include "Rectangle.h"
+#include <iostream>
+
+using namespace std;
+
+int main()
+{
+    Rectangle r(0, 0, 0, 1, 1, 1, 1, 0);
+    cout << r.calc_area() << endl;
+    cout << r.calc_perimiter() << endl;
+    r.name();
+    return 0;
+}