Browse Source

add Figure implimentation

jezvgg 11 months ago
parent
commit
3620f7b028
4 changed files with 27 additions and 19 deletions
  1. 1 0
      Ellips.cpp
  2. 7 0
      Figure.cpp
  3. 2 5
      Figure.h
  4. 17 14
      makefile

+ 1 - 0
Ellips.cpp

@@ -1,5 +1,6 @@
 #include "Ellips.h"
 #include <iostream>
+#include <math.h>
 
 double Ellips::calc_area()
 {

+ 7 - 0
Figure.cpp

@@ -0,0 +1,7 @@
+#include "Figure.h"
+#include <math.h>
+
+double Figure::l2(double x1, double y1, double x2, double y2)
+{
+    return sqrt((x2 - x1)*(x2 - x1) + (y2 - y1)*(y2 - y1)); 
+}

+ 2 - 5
Figure.h

@@ -1,6 +1,5 @@
 #ifndef _GEOMETRY_H
 #define _GEOMETRY_H
-#include <math.h>
 
 struct Point
 {
@@ -11,14 +10,12 @@ struct Point
 class Figure
 {
     protected:
-    double l2(double x1, double y1, double x2, double y2)
-    {
-        return sqrt((x2 - x1)*(x2 - x1) + (y2 - y1)*(y2 - y1)); 
-    }
+    double l2(double x1, double y1, double x2, double y2);
 
     public:
     virtual double calc_area() = 0;
     virtual double calc_perimiter() = 0;
     virtual void name() = 0;
 };
+
 #endif

+ 17 - 14
makefile

@@ -1,11 +1,11 @@
-all: Circle.o Triangle.o Rectangle.o Ellips.o main.o
-	g++ Circle.o Triangle.o Rectangle.o Ellips.o main.o
+all: Figure.o Circle.o Triangle.o Rectangle.o Ellips.o main.o
+	g++ Figure.o Circle.o Triangle.o Rectangle.o Ellips.o main.o
 
 main.o: main.cpp
 	g++ -c main.cpp
 
-circle: Circle.o circle_main.o
-	g++ Circle.o circle_main.o
+circle: Figure.o Circle.o circle_main.o
+	g++ Figure.o Circle.o circle_main.o
 
 circle_main.o: circle_main.cpp
 	g++ -c circle_main.cpp
@@ -13,8 +13,8 @@ circle_main.o: circle_main.cpp
 Circle.o: circle_main.cpp
 	g++ -c Circle.cpp
 
-triangle: Triangle.o triangle_main.o
-	g++ Triangle.o triangle_main.o
+triangle: Figure.o Triangle.o triangle_main.o
+	g++ Figure.o Triangle.o triangle_main.o
 
 triangle_main.o: triangle_main.cpp
 	g++ -c triangle_main.cpp
@@ -22,23 +22,26 @@ 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: Figure.o Rectangle.o rectangle_main.o
+	g++ Figure.o Rectangle.o rectangle_main.o
 
 rectangle_main.o: rectangle_main.cpp
 	g++ -c rectangle_main.cpp
 
-Rectangle.o: Rectangle.cpp
-	g++ -c Rectangle.cpp
+Rectangle.o: Figure.o Rectangle.cpp
+	g++ -c Figure.o Rectangle.cpp
 
-ellips: Ellips.o ellips_main.o
-	g++ Ellips.o ellips_main.o
+ellips: Figure.o Ellips.o ellips_main.o
+	g++ Figure.o Ellips.o ellips_main.o
 
 ellips_main.o: ellips_main.cpp
 	g++ -c ellips_main.cpp
 
-Ellips.o: Ellips.cpp
-	g++ -c Ellips.cpp
+Ellips.o: Figure.o Ellips.cpp
+	g++ -c Figure.o Ellips.cpp
+
+Figure.o: Figure.cpp
+	g++ -c Figure.cpp
 
 clean:
 	rm -rf *.o all