jezvgg hace 11 meses
padre
commit
737828bd69
Se han modificado 3 ficheros con 26 adiciones y 5 borrados
  1. 8 5
      Circle.cpp
  2. 8 0
      Circle.h
  3. 10 0
      circle_main.cpp

+ 8 - 5
Circle.cpp

@@ -3,19 +3,22 @@
 
 Circle::Circle(double center_x, double center_y, double radius)
 {
-    centerX = center_x;
-    centerY = center_y;
-    Radius = radius;
+    init(center_x, center_y, radius);
+}
+
+Circle::Circle(struct Point p, double radius)
+{
+    init(p.x, p.y, radius);
 }
 
 double Circle::calc_area()
 {
-    return 0.1;
+    return 3.14 * (Radius * Radius);
 }
 
 double Circle::calc_perimiter()
 {
-    return 0.1;
+    return 2.0 * 3.14 * Radius;
 }
 
 void Circle::name()

+ 8 - 0
Circle.h

@@ -5,6 +5,14 @@ class Circle: public Figure
     private:
     double centerX, centerY, Radius;
 
+    template <typename T>
+    void init(T center_x, T center_y, T radius)
+    {
+        centerX = double(center_x);
+        centerY = double(center_y);
+        Radius = double(radius);
+    }
+
     public:
     Circle(double center_x, double center_y, double radius);
     Circle(struct Point center, double radius);

+ 10 - 0
circle_main.cpp

@@ -1,9 +1,19 @@
 #include "Circle.h"
+#include <iostream>
 
 using namespace std;
 
 int main() {
     Circle c(23, 24, 5);
+    struct Point p;
+    p.x = 3.5;
+    p.y = 5.6;
+    Circle c2(p, 5.0);
+    cout << c.calc_area() << endl;
+    cout << c.calc_perimiter() << endl;
     c.name();
+    cout << "c2 " << c2.calc_area() << endl;
+    cout << "c2 " <<c2.calc_perimiter() << endl;
+    c2.name();
     return 0;
 }