diff --git a/main/circle.h b/main/circle.h index 94dc8e4..e9ca195 100644 --- a/main/circle.h +++ b/main/circle.h @@ -14,8 +14,8 @@ class Circle: public Figure void setA(Point _a); void setR(double _r); Point getA(); - double getR(); - double getArea(); + virtual double getR(); + virtual double getArea(); }; diff --git a/main/diamond.h b/main/diamond.h index 254d83a..7fc9da6 100644 --- a/main/diamond.h +++ b/main/diamond.h @@ -6,12 +6,12 @@ class Diamond: public Figure { private: - Point points[3]; + Point points[4]; public: Diamond(Point _a, Point _b, Point _c, Point _d); - double getCircumference(); - double getArea(); + virtual double getCircumference(); + virtual double getArea(); }; #endif \ No newline at end of file diff --git a/main/factory.cpp b/main/factory.cpp new file mode 100644 index 0000000..1e8fbf9 --- /dev/null +++ b/main/factory.cpp @@ -0,0 +1,4 @@ +#include "factory.h" +#include "factoryfigure.h" +#include "factoryfiguresspatial.h" + diff --git a/main/factory.h b/main/factory.h new file mode 100644 index 0000000..ef7a904 --- /dev/null +++ b/main/factory.h @@ -0,0 +1,18 @@ +#ifndef factory_h +#define factory_h + + + +class factory +{ + public: + + + +}; + + + + + +#endif \ No newline at end of file diff --git a/main/factoryfigure.cpp b/main/factoryfigure.cpp new file mode 100644 index 0000000..a2a6cc8 --- /dev/null +++ b/main/factoryfigure.cpp @@ -0,0 +1,34 @@ +#include "factoryfigure.h" + + +FactoryFigure::FactoryFigure(figureType f,Point _a,Point _b,Point _c){ + if(f==triangle){ + this->a= new Triangle(_a,_b,_c); + } +} +FactoryFigure::FactoryFigure(figureType f,Point _a,Point _b,Point _c,Point _d){ + switch(f){ + case diamond: + this->a= new Diamond(_a,_b,_c,_d); + break; + case square: + this->a= new Square(_a,_b,_c,_d); + break; + case tetragon: + this->a= new Tetragon(_a,_b,_c,_d); + break; + case trapeze: + this->a= new Trapeze(_a,_b,_c,_d); + break; + } +} +FactoryFigure::FactoryFigure(figureType f,Point _a,double _r){ + if(f==circle){ + this->a= new Circle(_a,_r); + } +} +FactoryFigure::FactoryFigure(figureType f,Point _a,Point _b,Point _c,Point _d,Point _e){ + if(f==pentagon){ + this->a= new Pentagon(_a,_b,_c,_d,_e); + } +} diff --git a/main/factoryfigure.h b/main/factoryfigure.h new file mode 100644 index 0000000..d27297c --- /dev/null +++ b/main/factoryfigure.h @@ -0,0 +1,35 @@ +#ifndef factoryfigure_h +#define factoryfigure_h +#include "figure.h" +#include "point.h" +#include "triangle.h" +#include "diamond.h" +#include "square.h" +#include "tetragon.h" +#include "trapeze.h" +#include "circle.h" +#include "pentagon.h" + + +enum figureType +{ + circle, + diamond, + pentagon, + square, + tetragon, + trapeze, + triangle +}; + +class FactoryFigure +{ +public: + Figure *a; + FactoryFigure(figureType f,Point _a,Point _b,Point _c); + FactoryFigure(figureType f,Point _a,Point _b,Point _c,Point _d); + FactoryFigure(figureType f,Point _a,double _r); + FactoryFigure(figureType f,Point _a,Point _b,Point _c,Point _d,Point _e); +}; + +#endif diff --git a/main/factoryfiguresspatial.cpp b/main/factoryfiguresspatial.cpp new file mode 100644 index 0000000..620f3d2 --- /dev/null +++ b/main/factoryfiguresspatial.cpp @@ -0,0 +1,56 @@ +#include "factoryfiguresspatial.h" + + +FactoryFigureSpatial::FactoryFigureSpatial(figureSpatialType f,PointSpatial _a,PointSpatial _b,PointSpatial _c,PointSpatial _d) + +{ + if ( f == pyramidtriangular ) + { + this->a = new PyramidTriangular(_a,_b,_c,_d); + } + + +} +FactoryFigureSpatial::FactoryFigureSpatial(figureSpatialType f,PointSpatial _a,PointSpatial _b,PointSpatial _c,PointSpatial _d,PointSpatial _e) +{ + if ( f == pyramidtetragonal ) + { + this->a = new PyramidTetragonal(_a,_b,_c,_d,_e); + } + + + +} +FactoryFigureSpatial::FactoryFigureSpatial(figureSpatialType f,PointSpatial _a,PointSpatial _b,PointSpatial _c,PointSpatial _d,PointSpatial _e,PointSpatial _f) +{ + if ( f == pyramidpentagonal ) + { + this->a = new PyramidPentagonal(_a,_b,_c,_d,_e,_f); + } + else if ( f == prismtriangular ) + { + + this->a = new PrismTriangular(_a,_b,_c,_d,_e,_f); + } + + +} +FactoryFigureSpatial::FactoryFigureSpatial(figureSpatialType f,PointSpatial _a,PointSpatial _b,PointSpatial _c,PointSpatial _d,PointSpatial _e,PointSpatial _f, PointSpatial _g,PointSpatial _h) +{ + + if ( f == prismtetragonal ) + { + this->a = new PrismTetragonal(_a,_b,_c,_d,_e,_f,_g,_h); + } + +} + +FactoryFigureSpatial::FactoryFigureSpatial(figureSpatialType f,PointSpatial _a,PointSpatial _b,PointSpatial _c,PointSpatial _d,PointSpatial _e,PointSpatial _f, PointSpatial _g,PointSpatial _h,PointSpatial _i,PointSpatial _j) +{ + + if ( f == prismpentagonal ) + { + this->a = new PrismPentagonal(_a,_b,_c,_d,_e,_f,_g,_h,_i,_j); + } + +} diff --git a/main/factoryfiguresspatial.h b/main/factoryfiguresspatial.h new file mode 100644 index 0000000..0c46462 --- /dev/null +++ b/main/factoryfiguresspatial.h @@ -0,0 +1,36 @@ +#ifndef factoryfigurespatial_h +#define factoryfigurespatial_h +#include "figurespatial.h" +#include "pointspatial.h" +#include "prismpentagonal.h" +#include "prismtetragonal.h" +#include "prismtriangular.h" +#include "pyramidtetragonal.h" +#include "pyramidpentagonal.h" +#include "pyramidtriangular.h" + + +enum figureSpatialType +{ + pyramidtriangular, + prismpentagonal, + prismtetragonal, + prismtriangular, + pyramidpentagonal, + pyramidtetragonal +}; + + +class FactoryFigureSpatial +{ +public: + FigureSpatial *a; + FactoryFigureSpatial(figureSpatialType f,PointSpatial _a,PointSpatial _b,PointSpatial _c,PointSpatial _d); + FactoryFigureSpatial(figureSpatialType f,PointSpatial _a,PointSpatial _b,PointSpatial _c,PointSpatial _d,PointSpatial _e); + FactoryFigureSpatial(figureSpatialType f,PointSpatial _a,PointSpatial _b,PointSpatial _c,PointSpatial _d,PointSpatial _e,PointSpatial _f); + FactoryFigureSpatial(figureSpatialType f,PointSpatial _a,PointSpatial _b,PointSpatial _c,PointSpatial _d,PointSpatial _e,PointSpatial _f, PointSpatial _g,PointSpatial _h); + FactoryFigureSpatial(figureSpatialType f,PointSpatial _a,PointSpatial _b,PointSpatial _c,PointSpatial _d,PointSpatial _e,PointSpatial _f, PointSpatial _g,PointSpatial _h,PointSpatial _i,PointSpatial _j); + +}; + +#endif \ No newline at end of file diff --git a/main/figure.h b/main/figure.h index cb99ec2..477ceeb 100644 --- a/main/figure.h +++ b/main/figure.h @@ -3,8 +3,10 @@ class Figure { - double getCircumference(); - double getArea(); +public: + + virtual double getCircumference(); + virtual double getArea(); }; #endif diff --git a/main/figurespatial.h b/main/figurespatial.h index b382ca7..02007e7 100644 --- a/main/figurespatial.h +++ b/main/figurespatial.h @@ -3,8 +3,10 @@ class FigureSpatial { - double getCircumference(); - double getVolume(); +public: + + virtual double getCircumference(); + virtual double getVolume(); }; #endif diff --git a/main/library.h b/main/library.h index 10d49cb..4f1bd02 100644 --- a/main/library.h +++ b/main/library.h @@ -1,7 +1,6 @@ #ifndef library_h #define library_h -#include #include #include "point.h" #include "pointspatial.h" @@ -14,7 +13,7 @@ #include "triangle.h" #include "figure.h" #include "figurespatial.h" -#include "piramidtriangular.h" +#include "pyramidtriangular.h" #include "pyramidtetragonal.h" #include "pyramidpentagonal.h" #include "prismpentagonal.h" diff --git a/main/main.cpp b/main/main.cpp index ad51233..6fce125 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -1,23 +1,137 @@ -#include "library.h" +#include +#include +#include +#include +#include +#include "factoryfigure.h" +#include "factoryfiguresspatial.h" +#include "tools.h" -//using namespace std; +using namespace std; -int main() + +int main( int argc, char *argv[] ) { + if ( argc >= 2 ) + { + if ( !strcmp(argv[1],"triangle") && ( argc == 6) ) + { + if ( !strcmp(argv[2],"area") ) + { + char **part; + Point points[3]; + + part=str_split(argv[3], ';'); + points[0] = Point(atof(part[0]),atof(part[1])); + part=str_split(argv[4], ';'); + points[1] = Point(atof(part[0]),atof(part[1])); + part=str_split(argv[5], ';'); + points[2] = Point(atof(part[0]),atof(part[1])); + FactoryFigure test(triangle,points[0],points[1],points[2]); + + cout<getArea()<getCircumference()<getArea()<getCircumference()<getArea()<getCircumference()< + + + - + @@ -76,17 +79,21 @@ + + + + - + @@ -96,6 +103,7 @@ + diff --git a/main/main.vcxproj.filters b/main/main.vcxproj.filters index 8a9e21e..f3bfd60 100644 --- a/main/main.vcxproj.filters +++ b/main/main.vcxproj.filters @@ -96,15 +96,27 @@ Source Files\figure spatial\figures spatial - - Source Files\figure spatial\figures spatial - Source Files\figure Source Files\figure\figures + + Source Files + + + Source Files\figure spatial\figures spatial + + + Source Files\figure + + + Source Files\figure spatial + + + Source Files + @@ -116,9 +128,6 @@ Header Files\figurespatial - - Header Files\figurespatial\figures - Header Files\figurespatial\figures @@ -161,5 +170,20 @@ Header Files + + Header Files + + + Header Files\figurespatial\figures + + + Header Files\figurespatial + + + Header Files\figure + + + Header Files + \ No newline at end of file diff --git a/main/pentagon.h b/main/pentagon.h index 2539c2f..3858cad 100644 --- a/main/pentagon.h +++ b/main/pentagon.h @@ -9,7 +9,7 @@ class Pentagon: public Figure Point points[5]; public: Pentagon(Point _a, Point _b, Point _c, Point _d, Point _e); - double getCircumference(); - double getArea(); + virtual double getCircumference(); + virtual double getArea(); }; #endif \ No newline at end of file diff --git a/main/point.cpp b/main/point.cpp index e4e466e..3605c9a 100644 --- a/main/point.cpp +++ b/main/point.cpp @@ -1,7 +1,7 @@ #include "point.h" -Point::Point(double _x, double _y){ + Point::Point(double _x, double _y){ this->x = _x; this->y = _y; } diff --git a/main/prismpentagonal.h b/main/prismpentagonal.h index 6424748..72d1a7a 100644 --- a/main/prismpentagonal.h +++ b/main/prismpentagonal.h @@ -6,10 +6,10 @@ class PrismPentagonal: public FigureSpatial { private: - PointSpatial points[9]; + PointSpatial points[10]; public: PrismPentagonal(PointSpatial _a, PointSpatial _b, PointSpatial _c, PointSpatial _d, PointSpatial _e, PointSpatial _f, PointSpatial _g, PointSpatial _h, PointSpatial _i, PointSpatial _j); - double getCircumference(); - double getVolume(); + virtual double getCircumference(); + virtual double getVolume(); }; #endif \ No newline at end of file diff --git a/main/prismtetragonal.h b/main/prismtetragonal.h index 02105b0..17fa90e 100644 --- a/main/prismtetragonal.h +++ b/main/prismtetragonal.h @@ -6,10 +6,10 @@ class PrismTetragonal: public FigureSpatial { private: - PointSpatial points[7]; + PointSpatial points[8]; public: PrismTetragonal(PointSpatial _a, PointSpatial _b, PointSpatial _c, PointSpatial _d, PointSpatial _e, PointSpatial _f, PointSpatial _g, PointSpatial _h); - double getCircumference(); - double getVolume(); + virtual double getCircumference(); + virtual double getVolume(); }; #endif diff --git a/main/prismtriangular.h b/main/prismtriangular.h index 61ce2a2..931839e 100644 --- a/main/prismtriangular.h +++ b/main/prismtriangular.h @@ -6,11 +6,11 @@ class PrismTriangular: public FigureSpatial { private: - PointSpatial points[5]; + PointSpatial points[6]; public: PrismTriangular(PointSpatial _a, PointSpatial _b, PointSpatial _c, PointSpatial _d, PointSpatial _e, PointSpatial _f); - double getCircumference(); - double getVolume(); + virtual double getCircumference(); + virtual double getVolume(); }; #endif \ No newline at end of file diff --git a/main/pyramidpentagonal.h b/main/pyramidpentagonal.h index 517b8f6..a6626b0 100644 --- a/main/pyramidpentagonal.h +++ b/main/pyramidpentagonal.h @@ -6,11 +6,11 @@ class PyramidPentagonal: public FigureSpatial { private: - PointSpatial points[5]; + PointSpatial points[6]; public: PyramidPentagonal(PointSpatial _a, PointSpatial _b, PointSpatial _c, PointSpatial _d, PointSpatial _e, PointSpatial _f); - double getCircumference(); - double getVolume(); + virtual double getCircumference(); + virtual double getVolume(); }; #endif diff --git a/main/pyramidtetragonal.h b/main/pyramidtetragonal.h index f4eddeb..d939042 100644 --- a/main/pyramidtetragonal.h +++ b/main/pyramidtetragonal.h @@ -7,11 +7,11 @@ class PyramidTetragonal: public FigureSpatial { private: - PointSpatial points[4]; + PointSpatial points[5]; public: PyramidTetragonal(PointSpatial _a, PointSpatial _b, PointSpatial _c, PointSpatial _d, PointSpatial _e); - double getCircumference(); - double getVolume(); + virtual double getCircumference(); + virtual double getVolume(); }; #endif diff --git a/main/piramidtriangular.cpp b/main/pyramidtriangular.cpp similarity index 98% rename from main/piramidtriangular.cpp rename to main/pyramidtriangular.cpp index 024ffbe..969686f 100644 --- a/main/piramidtriangular.cpp +++ b/main/pyramidtriangular.cpp @@ -1,4 +1,4 @@ -#include "piramidtriangular.h" +#include "pyramidtriangular.h" #include PyramidTriangular::PyramidTriangular(PointSpatial _a, PointSpatial _b, PointSpatial _c, PointSpatial _d){ diff --git a/main/piramidtriangular.h b/main/pyramidtriangular.h similarity index 59% rename from main/piramidtriangular.h rename to main/pyramidtriangular.h index ab5e570..7c0c362 100644 --- a/main/piramidtriangular.h +++ b/main/pyramidtriangular.h @@ -1,15 +1,15 @@ -#ifndef piramidtriangular_h -#define piramidtriangular_h +#ifndef pyramidtriangular_h +#define pyramidtriangular_h #include "figurespatial.h" #include "pointspatial.h" class PyramidTriangular: public FigureSpatial { private: - PointSpatial points[3]; + PointSpatial points[4]; public: PyramidTriangular(PointSpatial _a, PointSpatial _b, PointSpatial _c, PointSpatial _d); - double getCircumference(); - double getVolume(); + virtual double getCircumference(); + virtual double getVolume(); }; #endif diff --git a/main/square.h b/main/square.h index a9c27ba..ce54df3 100644 --- a/main/square.h +++ b/main/square.h @@ -6,10 +6,10 @@ class Square: public Figure { private: - Point points[3]; + Point points[4]; public: Square(Point _a, Point _b, Point _c, Point _d); - double getCircumference(); - double getArea(); + virtual double getCircumference(); + virtual double getArea(); }; #endif \ No newline at end of file diff --git a/main/tetragon.h b/main/tetragon.h index 4490d4f..be62e9d 100644 --- a/main/tetragon.h +++ b/main/tetragon.h @@ -6,11 +6,11 @@ class Tetragon: public Figure { private: - Point points[3]; + Point points[4]; public: Tetragon(Point _a, Point _b, Point _c, Point _d); - double getCircumference(); - double getArea(); + virtual double getCircumference(); + virtual double getArea(); }; #endif \ No newline at end of file diff --git a/main/tools.cpp b/main/tools.cpp new file mode 100644 index 0000000..40e707a --- /dev/null +++ b/main/tools.cpp @@ -0,0 +1,53 @@ +#include "tools.h" +#include +#include +#include + +char** str_split(char* a_str, const char a_delim) +{ + char** result = 0; + size_t count = 0; + char* tmp = a_str; + char* last_comma = 0; + char delim[2]; + delim[0] = a_delim; + delim[1] = 0; + + /* Count how many elements will be extracted. */ + while (*tmp) + { + if (a_delim == *tmp) + { + count++; + last_comma = tmp; + } + tmp++; + } + + /* Add space for trailing token. */ + count += last_comma < (a_str + strlen(a_str) - 1); + + /* Add space for terminating null string so caller + knows where the list of returned strings ends. */ + count++; + + result = (char**)malloc(sizeof(char*) * count); + + if (result) + { + size_t idx = 0; + char* token = strtok(a_str, delim); + + while (token) + { + assert(idx < count); + *(result + idx++) = strdup(token); + token = strtok(0, delim); + } + assert(idx == count - 1); + *(result + idx) = 0; + } + + return result; +} + diff --git a/main/tools.h b/main/tools.h new file mode 100644 index 0000000..ea17db0 --- /dev/null +++ b/main/tools.h @@ -0,0 +1,5 @@ +#ifndef tools_h +#define tools_h + +char** str_split(char* a_str, const char a_delim); +#endif \ No newline at end of file diff --git a/main/trapeze.h b/main/trapeze.h index 2fa4059..fb3e030 100644 --- a/main/trapeze.h +++ b/main/trapeze.h @@ -6,11 +6,11 @@ class Trapeze: public Figure { private: - Point points[3]; + Point points[4]; public: Trapeze(Point _a, Point _b, Point _c, Point _d); - double getCircumference(); - double getArea(); + virtual double getCircumference(); + virtual double getArea(); }; #endif \ No newline at end of file diff --git a/main/triangle.cpp b/main/triangle.cpp index 5c860fe..b75aa32 100644 --- a/main/triangle.cpp +++ b/main/triangle.cpp @@ -11,20 +11,26 @@ Triangle::Triangle(Point _a, Point _b, Point _c){ double Triangle::getCircumference() { double cir = 0; + int a,b; for(int i=0;i<3;i++){ // cir triangle + a = (i%3); + b = ((i+1)%3); cir += sqrt( - ( points[(i)%3].getX() - points[(i+1)%3].getX() ) * ( points[(i)%3].getX() - points[(i+1)%3].getX() ) + - ( points[(i)%3].getY() - points[(i+1)%3].getY() ) * ( points[(i)%3].getY() - points[(i+1)%3].getY() ) + ( points[a].getX() - points[b].getX() ) * ( points[a].getX() - points[b].getX() ) + + ( points[a].getY() - points[b].getY() ) * ( points[a].getY() - points[b].getY() ) ); } return cir; } double Triangle::getArea() { - double area = 0; - area = sqrt( - ( points[0].getX() - points[1].getX() ) * ( points[0].getX() - points[1].getX() ) + - ( points[0].getY() - points[1].getY() ) * ( points[0].getY() - points[1].getY() ) - ); - return area * area * sqrt(double(3)) /4; + double area = 0; + double p = getCircumference()/2; + area = sqrt( + p * + (p - sqrt(pow( points[0].getX()-points[1].getX() , 2.0 ) + pow( points[0].getY() - points[1].getY() , 2.0)))* + (p - sqrt(pow( points[1].getX()-points[2].getX() , 2.0 ) + pow( points[1].getY() - points[2].getY() , 2.0 )))* + (p - sqrt(pow( points[2].getX()-points[0].getX() , 2.0 ) + pow( points[2].getY() - points[0].getY() , 2.0))) + ); + return area; } \ No newline at end of file diff --git a/main/triangle.h b/main/triangle.h index 6934b6e..8c887af 100644 --- a/main/triangle.h +++ b/main/triangle.h @@ -6,10 +6,10 @@ class Triangle: public Figure { private: - Point points[2]; + Point points[3]; public: Triangle(Point _a, Point _b, Point _c); - double getCircumference(); - double getArea(); + virtual double getCircumference(); + virtual double getArea(); }; #endif