From 86f07e7b23559e5417550a58dbe6f04d141f2680 Mon Sep 17 00:00:00 2001 From: Johannes Theiner Date: Sat, 3 Nov 2018 16:08:14 +0100 Subject: [PATCH] CMakeLists aufgeteilt --- src/01_ENV/CMakeLists.txt | 3 + src/02_MENT/CMakeLists.txt | 2 + src/03_FLOW/CMakeLists.txt | 2 + src/04_UDEF/CMakeLists.txt | 4 + src/05_OO/CMakeLists.txt | 2 + src/05_OO/Testat/shapes_main.cpp | 160 --------------------------- src/05_OO/a/CMakeLists.txt | 31 ++++++ src/05_OO/{ => a}/MP/Circle.cpp | 0 src/05_OO/{ => a}/MP/Circle.h | 0 src/05_OO/{ => a}/MP/Point.cpp | 0 src/05_OO/{ => a}/MP/Point.h | 0 src/05_OO/{ => a}/MP/Position.h | 0 src/05_OO/{ => a}/MP/Rectangle.cpp | 0 src/05_OO/{ => a}/MP/Rectangle.h | 0 src/05_OO/{ => a}/MP/Scene.cpp | 0 src/05_OO/{ => a}/MP/Scene.h | 0 src/05_OO/{ => a}/MP/Shape.cpp | 0 src/05_OO/{ => a}/MP/Shape.h | 2 +- src/05_OO/{ => a}/MP/shapes_main.cpp | 0 src/05_OO/a/Testat/Circle.cpp | 26 +++++ src/05_OO/a/Testat/Circle.h | 14 +++ src/05_OO/a/Testat/Point.cpp | 8 ++ src/05_OO/a/Testat/Point.h | 14 +++ src/05_OO/a/Testat/Position.h | 14 +++ src/05_OO/a/Testat/Rectangle.cpp | 23 ++++ src/05_OO/a/Testat/Rectangle.h | 18 +++ src/05_OO/a/Testat/Scene.cpp | 19 ++++ src/05_OO/a/Testat/Scene.h | 17 +++ src/05_OO/a/Testat/Shape.cpp | 9 ++ src/05_OO/a/Testat/Shape.h | 17 +++ src/05_OO/a/Testat/shapes_main.cpp | 34 ++++++ src/05_OO/b/CMakeLists.txt | 31 ++++++ src/05_OO/b/MP/Circle.cpp | 26 +++++ src/05_OO/b/MP/Circle.h | 14 +++ src/05_OO/b/MP/Point.cpp | 8 ++ src/05_OO/b/MP/Point.h | 14 +++ src/05_OO/b/MP/Position.h | 14 +++ src/05_OO/b/MP/Rectangle.cpp | 23 ++++ src/05_OO/b/MP/Rectangle.h | 18 +++ src/05_OO/b/MP/Scene.cpp | 19 ++++ src/05_OO/b/MP/Scene.h | 17 +++ src/05_OO/b/MP/Shape.cpp | 9 ++ src/05_OO/b/MP/Shape.h | 17 +++ src/05_OO/b/MP/shapes_main.cpp | 34 ++++++ src/05_OO/b/Testat/Circle.cpp | 26 +++++ src/05_OO/b/Testat/Circle.h | 14 +++ src/05_OO/b/Testat/Point.cpp | 8 ++ src/05_OO/b/Testat/Point.h | 14 +++ src/05_OO/b/Testat/Position.h | 14 +++ src/05_OO/b/Testat/Rectangle.cpp | 23 ++++ src/05_OO/b/Testat/Rectangle.h | 18 +++ src/05_OO/b/Testat/Scene.cpp | 19 ++++ src/05_OO/b/Testat/Scene.h | 17 +++ src/05_OO/b/Testat/Shape.cpp | 9 ++ src/05_OO/b/Testat/Shape.h | 17 +++ src/05_OO/b/Testat/shapes_main.cpp | 34 ++++++ src/06_POLY/CMakeLists.txt | 2 + src/07_STD/CMakeLists.txt | 2 + src/08_PTRN/CMakeLists.txt | 0 src/10_PITF/CMakeLists.txt | 0 src/11_PUTT/CMakeLists.txt | 1 + src/CMakeLists.txt | 36 ++---- 62 files changed, 731 insertions(+), 186 deletions(-) create mode 100644 src/01_ENV/CMakeLists.txt create mode 100644 src/02_MENT/CMakeLists.txt create mode 100644 src/03_FLOW/CMakeLists.txt create mode 100644 src/04_UDEF/CMakeLists.txt create mode 100644 src/05_OO/CMakeLists.txt delete mode 100644 src/05_OO/Testat/shapes_main.cpp create mode 100644 src/05_OO/a/CMakeLists.txt rename src/05_OO/{ => a}/MP/Circle.cpp (100%) rename src/05_OO/{ => a}/MP/Circle.h (100%) rename src/05_OO/{ => a}/MP/Point.cpp (100%) rename src/05_OO/{ => a}/MP/Point.h (100%) rename src/05_OO/{ => a}/MP/Position.h (100%) rename src/05_OO/{ => a}/MP/Rectangle.cpp (100%) rename src/05_OO/{ => a}/MP/Rectangle.h (100%) rename src/05_OO/{ => a}/MP/Scene.cpp (100%) rename src/05_OO/{ => a}/MP/Scene.h (100%) rename src/05_OO/{ => a}/MP/Shape.cpp (100%) rename src/05_OO/{ => a}/MP/Shape.h (83%) rename src/05_OO/{ => a}/MP/shapes_main.cpp (100%) create mode 100644 src/05_OO/a/Testat/Circle.cpp create mode 100644 src/05_OO/a/Testat/Circle.h create mode 100644 src/05_OO/a/Testat/Point.cpp create mode 100644 src/05_OO/a/Testat/Point.h create mode 100644 src/05_OO/a/Testat/Position.h create mode 100644 src/05_OO/a/Testat/Rectangle.cpp create mode 100644 src/05_OO/a/Testat/Rectangle.h create mode 100644 src/05_OO/a/Testat/Scene.cpp create mode 100644 src/05_OO/a/Testat/Scene.h create mode 100644 src/05_OO/a/Testat/Shape.cpp create mode 100644 src/05_OO/a/Testat/Shape.h create mode 100644 src/05_OO/a/Testat/shapes_main.cpp create mode 100644 src/05_OO/b/CMakeLists.txt create mode 100644 src/05_OO/b/MP/Circle.cpp create mode 100644 src/05_OO/b/MP/Circle.h create mode 100644 src/05_OO/b/MP/Point.cpp create mode 100644 src/05_OO/b/MP/Point.h create mode 100644 src/05_OO/b/MP/Position.h create mode 100644 src/05_OO/b/MP/Rectangle.cpp create mode 100644 src/05_OO/b/MP/Rectangle.h create mode 100644 src/05_OO/b/MP/Scene.cpp create mode 100644 src/05_OO/b/MP/Scene.h create mode 100644 src/05_OO/b/MP/Shape.cpp create mode 100644 src/05_OO/b/MP/Shape.h create mode 100644 src/05_OO/b/MP/shapes_main.cpp create mode 100644 src/05_OO/b/Testat/Circle.cpp create mode 100644 src/05_OO/b/Testat/Circle.h create mode 100644 src/05_OO/b/Testat/Point.cpp create mode 100644 src/05_OO/b/Testat/Point.h create mode 100644 src/05_OO/b/Testat/Position.h create mode 100644 src/05_OO/b/Testat/Rectangle.cpp create mode 100644 src/05_OO/b/Testat/Rectangle.h create mode 100644 src/05_OO/b/Testat/Scene.cpp create mode 100644 src/05_OO/b/Testat/Scene.h create mode 100644 src/05_OO/b/Testat/Shape.cpp create mode 100644 src/05_OO/b/Testat/Shape.h create mode 100644 src/05_OO/b/Testat/shapes_main.cpp create mode 100644 src/06_POLY/CMakeLists.txt create mode 100644 src/07_STD/CMakeLists.txt create mode 100644 src/08_PTRN/CMakeLists.txt create mode 100644 src/10_PITF/CMakeLists.txt create mode 100644 src/11_PUTT/CMakeLists.txt diff --git a/src/01_ENV/CMakeLists.txt b/src/01_ENV/CMakeLists.txt new file mode 100644 index 0000000..63f9fdf --- /dev/null +++ b/src/01_ENV/CMakeLists.txt @@ -0,0 +1,3 @@ +add_executable(01_ENV_MP MP/main.c MP/func1.c) +target_link_libraries(01_ENV_MP m) +add_executable(01_ENV_Testat Testat/main.c Testat/func1.c) \ No newline at end of file diff --git a/src/02_MENT/CMakeLists.txt b/src/02_MENT/CMakeLists.txt new file mode 100644 index 0000000..a02c50f --- /dev/null +++ b/src/02_MENT/CMakeLists.txt @@ -0,0 +1,2 @@ +add_executable(02_MENT_MP MP/main_02_MENT.cpp) +add_executable(02_MENT_Testat Testat/main_02_MENT.cpp) \ No newline at end of file diff --git a/src/03_FLOW/CMakeLists.txt b/src/03_FLOW/CMakeLists.txt new file mode 100644 index 0000000..2b24f1b --- /dev/null +++ b/src/03_FLOW/CMakeLists.txt @@ -0,0 +1,2 @@ +add_executable(03_FLOW_MP MP/main_mp2_FLOW_a.cpp ../helpers/AnsiConsole.cpp) +add_executable(03_FLOW_Testat Testat/main_mp2_FLOW_a.cpp ../helpers/AnsiConsole.cpp) \ No newline at end of file diff --git a/src/04_UDEF/CMakeLists.txt b/src/04_UDEF/CMakeLists.txt new file mode 100644 index 0000000..6da8d75 --- /dev/null +++ b/src/04_UDEF/CMakeLists.txt @@ -0,0 +1,4 @@ +add_executable(04_UDEF_MP MP/main_04_UDEF_e.cpp) +target_link_libraries(04_UDEF_MP m) +add_executable(04_UDEF_Testat Testat/main_04_UDEF_e.cpp) +target_link_libraries(04_UDEF_Testat m) \ No newline at end of file diff --git a/src/05_OO/CMakeLists.txt b/src/05_OO/CMakeLists.txt new file mode 100644 index 0000000..906bb6f --- /dev/null +++ b/src/05_OO/CMakeLists.txt @@ -0,0 +1,2 @@ +add_subdirectory(a) +add_subdirectory(b) \ No newline at end of file diff --git a/src/05_OO/Testat/shapes_main.cpp b/src/05_OO/Testat/shapes_main.cpp deleted file mode 100644 index f09dcb8..0000000 --- a/src/05_OO/Testat/shapes_main.cpp +++ /dev/null @@ -1,160 +0,0 @@ -#include "../../helpers/AnsiConsole.h" -#include -#include - -struct Position { - int x; - int y; - - explicit Position(int x_ = 0, int y_ = 0) { - x = x_; - y = y_; - } -}; - -class Shape { -protected: - Position position; - Colors color; -public: - Shape(Position position, Colors color); - virtual ~Shape(); - virtual void draw() = 0; -}; - -Shape::Shape(Position position, Colors color) { - this->position = position; - this->color = color; -} - -Shape::~Shape() = default; - -class Point : public Shape{ - -public: - explicit Point(int x, int y, Colors color); - void draw() override; -}; - -Point::Point(int x, int y, Colors color) : Shape(Position(x, y), color) { - -} - -void Point::draw() { - ansiConsole.printText(position.x, position.y, "*", color); -} - -class Circle : public Shape{ -protected: - int _radius; -public: - explicit Circle(int x = 0, int y = 0, int radius = 0, Colors color = Colors::GREEN); - - void draw() override; -}; - -Circle::Circle(int x, int y, int radius, Colors color) : Shape(Position(x, y), color) { - _radius = radius; -} - -void Circle::draw() { - /* see https://de.wikibooks.org/wiki/Formelsammlung_Mathematik:_Geometrie - * Höhensatz des Euklid - * */ - int x_start = position.x - _radius / 2; - int x_stop = position.x + _radius / 2; - - for (int i = x_start; i <= x_stop; i++) { - double x_relative = double(i) - double(x_start); - double h = sqrt(x_relative * (x_stop - x_start - x_relative)); - ansiConsole.printText(position.x + int(x_relative) - _radius / 2, - static_cast(position.y + h), "#", - color); - ansiConsole.printText(position.x + int(x_relative) - _radius / 2, - static_cast(position.y - h), "#", - color); - - } -} - -class Rectangle : public Shape{ -protected: - int width; - int height; - -public: - explicit Rectangle(int x = 0, int y = 0, int width = 0, int height = 0, Colors color = Colors::WHITE); - void draw() override; -}; - -Rectangle::Rectangle(int x, int y, int width, int height, Colors color) : Shape(Position(x, y), color) { - this->width = width; - this->height = height; -} - -void Rectangle::draw() { - int x_start = position.x - (width / 2); - int x_stop = position.x + (width / 2); - - int y_start = position.y - (height / 2); - int y_stop = position.y + (height / 2); - - for(int i = x_start; i <= x_stop; i++) { - ansiConsole.printText(i, position.y - (height / 2), "#", color); - ansiConsole.printText(i, position.y + (height / 2), "#", color); - } - for(int i = y_start; i< y_stop; i++) { - ansiConsole.printText(position.x + (width / 2), i, "#", color); - ansiConsole.printText(position.x - (width / 2), i, "#", color); - } -} - -class Scene { -private: - std::vector shapes; -public: - explicit Scene(std::vector shapes); - void draw(); - ~Scene(); -}; - -Scene::Scene(std::vector shapes) : shapes(std::move(shapes)) { - -} - -void Scene::draw() { - ansiConsole.clearScreen(); - for(Shape* shape : shapes) { - shape->draw(); - } -} - -Scene::~Scene() { - for(Shape* shape : shapes) { - delete shape; - } -} - -int main(int argc, char **argv) { - std::vector shapes; - - shapes.push_back(new Point(30, 10, Colors::RED)); - shapes.push_back(new Point(28, 8, Colors::BLUE)); - shapes.push_back(new Point(32, 8, Colors::BLUE)); - - - shapes.push_back(new Circle(30, 10, 10, Colors::WHITE)); - shapes.push_back(new Circle(30, 20, 15, Colors::GREEN)); - - - shapes.push_back(new Rectangle(5, 21, 10, 10, Colors::MAGENTA)); - - - auto *s = new Scene(shapes); - s->draw(); - - delete s; - - - return 0; -} diff --git a/src/05_OO/a/CMakeLists.txt b/src/05_OO/a/CMakeLists.txt new file mode 100644 index 0000000..2582519 --- /dev/null +++ b/src/05_OO/a/CMakeLists.txt @@ -0,0 +1,31 @@ +add_executable(05_OOa_MP + MP/shapes_main.cpp + MP/Shape.cpp + MP/Position.h + MP/Shape.h + MP/Point.cpp + MP/Point.h + MP/Circle.cpp + MP/Circle.h + MP/Rectangle.cpp + MP/Rectangle.h + MP/Scene.cpp + MP/Scene.h + ../../helpers/AnsiConsole.cpp + ) + +add_executable(05_OOa_Testat + Testat/shapes_main.cpp + Testat/Shape.cpp + Testat/Position.h + Testat/Shape.h + Testat/Point.cpp + Testat/Point.h + Testat/Circle.cpp + Testat/Circle.h + Testat/Rectangle.cpp + Testat/Rectangle.h + Testat/Scene.cpp + Testat/Scene.h + ../../helpers/AnsiConsole.cpp + ) \ No newline at end of file diff --git a/src/05_OO/MP/Circle.cpp b/src/05_OO/a/MP/Circle.cpp similarity index 100% rename from src/05_OO/MP/Circle.cpp rename to src/05_OO/a/MP/Circle.cpp diff --git a/src/05_OO/MP/Circle.h b/src/05_OO/a/MP/Circle.h similarity index 100% rename from src/05_OO/MP/Circle.h rename to src/05_OO/a/MP/Circle.h diff --git a/src/05_OO/MP/Point.cpp b/src/05_OO/a/MP/Point.cpp similarity index 100% rename from src/05_OO/MP/Point.cpp rename to src/05_OO/a/MP/Point.cpp diff --git a/src/05_OO/MP/Point.h b/src/05_OO/a/MP/Point.h similarity index 100% rename from src/05_OO/MP/Point.h rename to src/05_OO/a/MP/Point.h diff --git a/src/05_OO/MP/Position.h b/src/05_OO/a/MP/Position.h similarity index 100% rename from src/05_OO/MP/Position.h rename to src/05_OO/a/MP/Position.h diff --git a/src/05_OO/MP/Rectangle.cpp b/src/05_OO/a/MP/Rectangle.cpp similarity index 100% rename from src/05_OO/MP/Rectangle.cpp rename to src/05_OO/a/MP/Rectangle.cpp diff --git a/src/05_OO/MP/Rectangle.h b/src/05_OO/a/MP/Rectangle.h similarity index 100% rename from src/05_OO/MP/Rectangle.h rename to src/05_OO/a/MP/Rectangle.h diff --git a/src/05_OO/MP/Scene.cpp b/src/05_OO/a/MP/Scene.cpp similarity index 100% rename from src/05_OO/MP/Scene.cpp rename to src/05_OO/a/MP/Scene.cpp diff --git a/src/05_OO/MP/Scene.h b/src/05_OO/a/MP/Scene.h similarity index 100% rename from src/05_OO/MP/Scene.h rename to src/05_OO/a/MP/Scene.h diff --git a/src/05_OO/MP/Shape.cpp b/src/05_OO/a/MP/Shape.cpp similarity index 100% rename from src/05_OO/MP/Shape.cpp rename to src/05_OO/a/MP/Shape.cpp diff --git a/src/05_OO/MP/Shape.h b/src/05_OO/a/MP/Shape.h similarity index 83% rename from src/05_OO/MP/Shape.h rename to src/05_OO/a/MP/Shape.h index 2c803d3..f354055 100644 --- a/src/05_OO/MP/Shape.h +++ b/src/05_OO/a/MP/Shape.h @@ -1,7 +1,7 @@ #ifndef C_C_SHAPE_H #define C_C_SHAPE_H -#include "../../helpers/AnsiConsole.h" +#include "../../../helpers/AnsiConsole.h" #include "Position.h" class Shape { diff --git a/src/05_OO/MP/shapes_main.cpp b/src/05_OO/a/MP/shapes_main.cpp similarity index 100% rename from src/05_OO/MP/shapes_main.cpp rename to src/05_OO/a/MP/shapes_main.cpp diff --git a/src/05_OO/a/Testat/Circle.cpp b/src/05_OO/a/Testat/Circle.cpp new file mode 100644 index 0000000..5ef58f7 --- /dev/null +++ b/src/05_OO/a/Testat/Circle.cpp @@ -0,0 +1,26 @@ +#include "Circle.h" +#include + +Circle::Circle(int x, int y, int radius, Colors color) : Shape(Position(x, y), color) { + _radius = radius; +} + +void Circle::draw() { + /* see https://de.wikibooks.org/wiki/Formelsammlung_Mathematik:_Geometrie + * Höhensatz des Euklid + * */ + int x_start = position.x - _radius / 2; + int x_stop = position.x + _radius / 2; + + for (int i = x_start; i <= x_stop; i++) { + double x_relative = double(i) - double(x_start); + double h = sqrt(x_relative * (x_stop - x_start - x_relative)); + ansiConsole.printText(position.x + int(x_relative) - _radius / 2, + static_cast(position.y + h), "#", + color); + ansiConsole.printText(position.x + int(x_relative) - _radius / 2, + static_cast(position.y - h), "#", + color); + + } +} diff --git a/src/05_OO/a/Testat/Circle.h b/src/05_OO/a/Testat/Circle.h new file mode 100644 index 0000000..f0186d2 --- /dev/null +++ b/src/05_OO/a/Testat/Circle.h @@ -0,0 +1,14 @@ +#ifndef C_C_CIRCLE_H +#define C_C_CIRCLE_H + +#include "Shape.h" + +class Circle : public Shape{ +protected: + int _radius; +public: + explicit Circle(int x = 0, int y = 0, int radius = 0, Colors color = Colors::GREEN); + void draw() override; +}; + +#endif //C_C_CIRCLE_H diff --git a/src/05_OO/a/Testat/Point.cpp b/src/05_OO/a/Testat/Point.cpp new file mode 100644 index 0000000..77efe5c --- /dev/null +++ b/src/05_OO/a/Testat/Point.cpp @@ -0,0 +1,8 @@ +#include "Point.h" + +Point::Point(int x, int y, Colors color) : Shape(Position(x, y), color) { +} + +void Point::draw() { + ansiConsole.printText(position.x, position.y, "*", color); +} diff --git a/src/05_OO/a/Testat/Point.h b/src/05_OO/a/Testat/Point.h new file mode 100644 index 0000000..bc693bf --- /dev/null +++ b/src/05_OO/a/Testat/Point.h @@ -0,0 +1,14 @@ +#ifndef C_C_POINT_H +#define C_C_POINT_H + +#include "Shape.h" + +class Point : public Shape{ + +public: + explicit Point(int x, int y, Colors color); + void draw() override; +}; + + +#endif diff --git a/src/05_OO/a/Testat/Position.h b/src/05_OO/a/Testat/Position.h new file mode 100644 index 0000000..f977d98 --- /dev/null +++ b/src/05_OO/a/Testat/Position.h @@ -0,0 +1,14 @@ +#ifndef C_C_POSITION_H +#define C_C_POSITION_H + +struct Position { + int x; + int y; + + explicit Position(int x_ = 0, int y_ = 0) { + x = x_; + y = y_; + } +}; + +#endif \ No newline at end of file diff --git a/src/05_OO/a/Testat/Rectangle.cpp b/src/05_OO/a/Testat/Rectangle.cpp new file mode 100644 index 0000000..7aaa71a --- /dev/null +++ b/src/05_OO/a/Testat/Rectangle.cpp @@ -0,0 +1,23 @@ +#include "Rectangle.h" + +Rectangle::Rectangle(int x, int y, int width, int height, Colors color) : Shape(Position(x, y), color) { + this->width = width; + this->height = height; +} + +void Rectangle::draw() { + int x_start = position.x - (width / 2); + int x_stop = position.x + (width / 2); + + int y_start = position.y - (height / 2); + int y_stop = position.y + (height / 2); + + for(int i = x_start; i <= x_stop; i++) { + ansiConsole.printText(i, position.y - (height / 2), "#", color); + ansiConsole.printText(i, position.y + (height / 2), "#", color); + } + for(int i = y_start; i< y_stop; i++) { + ansiConsole.printText(position.x + (width / 2), i, "#", color); + ansiConsole.printText(position.x - (width / 2), i, "#", color); + } +} \ No newline at end of file diff --git a/src/05_OO/a/Testat/Rectangle.h b/src/05_OO/a/Testat/Rectangle.h new file mode 100644 index 0000000..f8775b9 --- /dev/null +++ b/src/05_OO/a/Testat/Rectangle.h @@ -0,0 +1,18 @@ +#include "Shape.h" + +#ifndef C_C_RECTANGLE_H +#define C_C_RECTANGLE_H + + +class Rectangle : public Shape{ +protected: + int width; + int height; + +public: + explicit Rectangle(int x = 0, int y = 0, int width = 0, int height = 0, Colors color = Colors::WHITE); + void draw() override; +}; + + +#endif //C_C_RECTANGLE_H diff --git a/src/05_OO/a/Testat/Scene.cpp b/src/05_OO/a/Testat/Scene.cpp new file mode 100644 index 0000000..9d25e7e --- /dev/null +++ b/src/05_OO/a/Testat/Scene.cpp @@ -0,0 +1,19 @@ +#include "Scene.h" +#include + +Scene::Scene(std::vector shapes) : shapes(std::move(shapes)) { + +} + +void Scene::draw() { + ansiConsole.clearScreen(); + for(Shape* shape : shapes) { + shape->draw(); + } +} + +Scene::~Scene() { + for(Shape* shape : shapes) { + delete shape; + } +} diff --git a/src/05_OO/a/Testat/Scene.h b/src/05_OO/a/Testat/Scene.h new file mode 100644 index 0000000..90e3352 --- /dev/null +++ b/src/05_OO/a/Testat/Scene.h @@ -0,0 +1,17 @@ +#include +#include "Shape.h" + +#ifndef C_C_SCENE_H +#define C_C_SCENE_H + +class Scene { +private: + std::vector shapes; +public: + explicit Scene(std::vector shapes); + void draw(); + ~Scene(); +}; + + +#endif //C_C_SCENE_H diff --git a/src/05_OO/a/Testat/Shape.cpp b/src/05_OO/a/Testat/Shape.cpp new file mode 100644 index 0000000..6fa576c --- /dev/null +++ b/src/05_OO/a/Testat/Shape.cpp @@ -0,0 +1,9 @@ +#include "Position.h" +#include "Shape.h" + +Shape::Shape(Position position, Colors color) { + this->position = position; + this->color = color; +} + +Shape::~Shape() = default; \ No newline at end of file diff --git a/src/05_OO/a/Testat/Shape.h b/src/05_OO/a/Testat/Shape.h new file mode 100644 index 0000000..f354055 --- /dev/null +++ b/src/05_OO/a/Testat/Shape.h @@ -0,0 +1,17 @@ +#ifndef C_C_SHAPE_H +#define C_C_SHAPE_H + +#include "../../../helpers/AnsiConsole.h" +#include "Position.h" + +class Shape { +protected: + Position position; + Colors color; +public: + Shape(Position position, Colors color); + virtual ~Shape(); + virtual void draw() = 0; +}; + +#endif \ No newline at end of file diff --git a/src/05_OO/a/Testat/shapes_main.cpp b/src/05_OO/a/Testat/shapes_main.cpp new file mode 100644 index 0000000..20dbcde --- /dev/null +++ b/src/05_OO/a/Testat/shapes_main.cpp @@ -0,0 +1,34 @@ +#include +#include "Shape.h" +#include "Point.h" +#include "Circle.h" +#include "Rectangle.h" +#include "Scene.h" + +int main(int argc, char **argv) { + std::vector shapes; + + shapes.push_back(new Point(30, 10, Colors::RED)); + shapes.push_back(new Point(28, 8, Colors::BLUE)); + shapes.push_back(new Point(32, 8, Colors::BLUE)); + + + shapes.push_back(new Circle(30, 10, 10, Colors::WHITE)); + shapes.push_back(new Circle(30, 20, 15, Colors::GREEN)); + + + shapes.push_back(new Rectangle(5, 21, 10, 10, Colors::MAGENTA)); + + shapes.push_back(new Point(5, 10, Colors::WHITE)); + shapes.push_back(new Point(15, 7, Colors::WHITE)); + shapes.push_back(new Point(7, 5, Colors::WHITE)); + + + auto *s = new Scene(shapes); + s->draw(); + + delete s; + + + return 0; +} diff --git a/src/05_OO/b/CMakeLists.txt b/src/05_OO/b/CMakeLists.txt new file mode 100644 index 0000000..f5a417e --- /dev/null +++ b/src/05_OO/b/CMakeLists.txt @@ -0,0 +1,31 @@ +add_executable(05_OOb_MP + MP/shapes_main.cpp + MP/Shape.cpp + MP/Position.h + MP/Shape.h + MP/Point.cpp + MP/Point.h + MP/Circle.cpp + MP/Circle.h + MP/Rectangle.cpp + MP/Rectangle.h + MP/Scene.cpp + MP/Scene.h + ../../helpers/AnsiConsole.cpp + ) + +add_executable(05_OOb_Testat + Testat/shapes_main.cpp + Testat/Shape.cpp + Testat/Position.h + Testat/Shape.h + Testat/Point.cpp + Testat/Point.h + Testat/Circle.cpp + Testat/Circle.h + Testat/Rectangle.cpp + Testat/Rectangle.h + Testat/Scene.cpp + Testat/Scene.h + ../../helpers/AnsiConsole.cpp + ) \ No newline at end of file diff --git a/src/05_OO/b/MP/Circle.cpp b/src/05_OO/b/MP/Circle.cpp new file mode 100644 index 0000000..5ef58f7 --- /dev/null +++ b/src/05_OO/b/MP/Circle.cpp @@ -0,0 +1,26 @@ +#include "Circle.h" +#include + +Circle::Circle(int x, int y, int radius, Colors color) : Shape(Position(x, y), color) { + _radius = radius; +} + +void Circle::draw() { + /* see https://de.wikibooks.org/wiki/Formelsammlung_Mathematik:_Geometrie + * Höhensatz des Euklid + * */ + int x_start = position.x - _radius / 2; + int x_stop = position.x + _radius / 2; + + for (int i = x_start; i <= x_stop; i++) { + double x_relative = double(i) - double(x_start); + double h = sqrt(x_relative * (x_stop - x_start - x_relative)); + ansiConsole.printText(position.x + int(x_relative) - _radius / 2, + static_cast(position.y + h), "#", + color); + ansiConsole.printText(position.x + int(x_relative) - _radius / 2, + static_cast(position.y - h), "#", + color); + + } +} diff --git a/src/05_OO/b/MP/Circle.h b/src/05_OO/b/MP/Circle.h new file mode 100644 index 0000000..f0186d2 --- /dev/null +++ b/src/05_OO/b/MP/Circle.h @@ -0,0 +1,14 @@ +#ifndef C_C_CIRCLE_H +#define C_C_CIRCLE_H + +#include "Shape.h" + +class Circle : public Shape{ +protected: + int _radius; +public: + explicit Circle(int x = 0, int y = 0, int radius = 0, Colors color = Colors::GREEN); + void draw() override; +}; + +#endif //C_C_CIRCLE_H diff --git a/src/05_OO/b/MP/Point.cpp b/src/05_OO/b/MP/Point.cpp new file mode 100644 index 0000000..77efe5c --- /dev/null +++ b/src/05_OO/b/MP/Point.cpp @@ -0,0 +1,8 @@ +#include "Point.h" + +Point::Point(int x, int y, Colors color) : Shape(Position(x, y), color) { +} + +void Point::draw() { + ansiConsole.printText(position.x, position.y, "*", color); +} diff --git a/src/05_OO/b/MP/Point.h b/src/05_OO/b/MP/Point.h new file mode 100644 index 0000000..bc693bf --- /dev/null +++ b/src/05_OO/b/MP/Point.h @@ -0,0 +1,14 @@ +#ifndef C_C_POINT_H +#define C_C_POINT_H + +#include "Shape.h" + +class Point : public Shape{ + +public: + explicit Point(int x, int y, Colors color); + void draw() override; +}; + + +#endif diff --git a/src/05_OO/b/MP/Position.h b/src/05_OO/b/MP/Position.h new file mode 100644 index 0000000..f977d98 --- /dev/null +++ b/src/05_OO/b/MP/Position.h @@ -0,0 +1,14 @@ +#ifndef C_C_POSITION_H +#define C_C_POSITION_H + +struct Position { + int x; + int y; + + explicit Position(int x_ = 0, int y_ = 0) { + x = x_; + y = y_; + } +}; + +#endif \ No newline at end of file diff --git a/src/05_OO/b/MP/Rectangle.cpp b/src/05_OO/b/MP/Rectangle.cpp new file mode 100644 index 0000000..7aaa71a --- /dev/null +++ b/src/05_OO/b/MP/Rectangle.cpp @@ -0,0 +1,23 @@ +#include "Rectangle.h" + +Rectangle::Rectangle(int x, int y, int width, int height, Colors color) : Shape(Position(x, y), color) { + this->width = width; + this->height = height; +} + +void Rectangle::draw() { + int x_start = position.x - (width / 2); + int x_stop = position.x + (width / 2); + + int y_start = position.y - (height / 2); + int y_stop = position.y + (height / 2); + + for(int i = x_start; i <= x_stop; i++) { + ansiConsole.printText(i, position.y - (height / 2), "#", color); + ansiConsole.printText(i, position.y + (height / 2), "#", color); + } + for(int i = y_start; i< y_stop; i++) { + ansiConsole.printText(position.x + (width / 2), i, "#", color); + ansiConsole.printText(position.x - (width / 2), i, "#", color); + } +} \ No newline at end of file diff --git a/src/05_OO/b/MP/Rectangle.h b/src/05_OO/b/MP/Rectangle.h new file mode 100644 index 0000000..f8775b9 --- /dev/null +++ b/src/05_OO/b/MP/Rectangle.h @@ -0,0 +1,18 @@ +#include "Shape.h" + +#ifndef C_C_RECTANGLE_H +#define C_C_RECTANGLE_H + + +class Rectangle : public Shape{ +protected: + int width; + int height; + +public: + explicit Rectangle(int x = 0, int y = 0, int width = 0, int height = 0, Colors color = Colors::WHITE); + void draw() override; +}; + + +#endif //C_C_RECTANGLE_H diff --git a/src/05_OO/b/MP/Scene.cpp b/src/05_OO/b/MP/Scene.cpp new file mode 100644 index 0000000..9d25e7e --- /dev/null +++ b/src/05_OO/b/MP/Scene.cpp @@ -0,0 +1,19 @@ +#include "Scene.h" +#include + +Scene::Scene(std::vector shapes) : shapes(std::move(shapes)) { + +} + +void Scene::draw() { + ansiConsole.clearScreen(); + for(Shape* shape : shapes) { + shape->draw(); + } +} + +Scene::~Scene() { + for(Shape* shape : shapes) { + delete shape; + } +} diff --git a/src/05_OO/b/MP/Scene.h b/src/05_OO/b/MP/Scene.h new file mode 100644 index 0000000..90e3352 --- /dev/null +++ b/src/05_OO/b/MP/Scene.h @@ -0,0 +1,17 @@ +#include +#include "Shape.h" + +#ifndef C_C_SCENE_H +#define C_C_SCENE_H + +class Scene { +private: + std::vector shapes; +public: + explicit Scene(std::vector shapes); + void draw(); + ~Scene(); +}; + + +#endif //C_C_SCENE_H diff --git a/src/05_OO/b/MP/Shape.cpp b/src/05_OO/b/MP/Shape.cpp new file mode 100644 index 0000000..6fa576c --- /dev/null +++ b/src/05_OO/b/MP/Shape.cpp @@ -0,0 +1,9 @@ +#include "Position.h" +#include "Shape.h" + +Shape::Shape(Position position, Colors color) { + this->position = position; + this->color = color; +} + +Shape::~Shape() = default; \ No newline at end of file diff --git a/src/05_OO/b/MP/Shape.h b/src/05_OO/b/MP/Shape.h new file mode 100644 index 0000000..f354055 --- /dev/null +++ b/src/05_OO/b/MP/Shape.h @@ -0,0 +1,17 @@ +#ifndef C_C_SHAPE_H +#define C_C_SHAPE_H + +#include "../../../helpers/AnsiConsole.h" +#include "Position.h" + +class Shape { +protected: + Position position; + Colors color; +public: + Shape(Position position, Colors color); + virtual ~Shape(); + virtual void draw() = 0; +}; + +#endif \ No newline at end of file diff --git a/src/05_OO/b/MP/shapes_main.cpp b/src/05_OO/b/MP/shapes_main.cpp new file mode 100644 index 0000000..20dbcde --- /dev/null +++ b/src/05_OO/b/MP/shapes_main.cpp @@ -0,0 +1,34 @@ +#include +#include "Shape.h" +#include "Point.h" +#include "Circle.h" +#include "Rectangle.h" +#include "Scene.h" + +int main(int argc, char **argv) { + std::vector shapes; + + shapes.push_back(new Point(30, 10, Colors::RED)); + shapes.push_back(new Point(28, 8, Colors::BLUE)); + shapes.push_back(new Point(32, 8, Colors::BLUE)); + + + shapes.push_back(new Circle(30, 10, 10, Colors::WHITE)); + shapes.push_back(new Circle(30, 20, 15, Colors::GREEN)); + + + shapes.push_back(new Rectangle(5, 21, 10, 10, Colors::MAGENTA)); + + shapes.push_back(new Point(5, 10, Colors::WHITE)); + shapes.push_back(new Point(15, 7, Colors::WHITE)); + shapes.push_back(new Point(7, 5, Colors::WHITE)); + + + auto *s = new Scene(shapes); + s->draw(); + + delete s; + + + return 0; +} diff --git a/src/05_OO/b/Testat/Circle.cpp b/src/05_OO/b/Testat/Circle.cpp new file mode 100644 index 0000000..5ef58f7 --- /dev/null +++ b/src/05_OO/b/Testat/Circle.cpp @@ -0,0 +1,26 @@ +#include "Circle.h" +#include + +Circle::Circle(int x, int y, int radius, Colors color) : Shape(Position(x, y), color) { + _radius = radius; +} + +void Circle::draw() { + /* see https://de.wikibooks.org/wiki/Formelsammlung_Mathematik:_Geometrie + * Höhensatz des Euklid + * */ + int x_start = position.x - _radius / 2; + int x_stop = position.x + _radius / 2; + + for (int i = x_start; i <= x_stop; i++) { + double x_relative = double(i) - double(x_start); + double h = sqrt(x_relative * (x_stop - x_start - x_relative)); + ansiConsole.printText(position.x + int(x_relative) - _radius / 2, + static_cast(position.y + h), "#", + color); + ansiConsole.printText(position.x + int(x_relative) - _radius / 2, + static_cast(position.y - h), "#", + color); + + } +} diff --git a/src/05_OO/b/Testat/Circle.h b/src/05_OO/b/Testat/Circle.h new file mode 100644 index 0000000..f0186d2 --- /dev/null +++ b/src/05_OO/b/Testat/Circle.h @@ -0,0 +1,14 @@ +#ifndef C_C_CIRCLE_H +#define C_C_CIRCLE_H + +#include "Shape.h" + +class Circle : public Shape{ +protected: + int _radius; +public: + explicit Circle(int x = 0, int y = 0, int radius = 0, Colors color = Colors::GREEN); + void draw() override; +}; + +#endif //C_C_CIRCLE_H diff --git a/src/05_OO/b/Testat/Point.cpp b/src/05_OO/b/Testat/Point.cpp new file mode 100644 index 0000000..77efe5c --- /dev/null +++ b/src/05_OO/b/Testat/Point.cpp @@ -0,0 +1,8 @@ +#include "Point.h" + +Point::Point(int x, int y, Colors color) : Shape(Position(x, y), color) { +} + +void Point::draw() { + ansiConsole.printText(position.x, position.y, "*", color); +} diff --git a/src/05_OO/b/Testat/Point.h b/src/05_OO/b/Testat/Point.h new file mode 100644 index 0000000..bc693bf --- /dev/null +++ b/src/05_OO/b/Testat/Point.h @@ -0,0 +1,14 @@ +#ifndef C_C_POINT_H +#define C_C_POINT_H + +#include "Shape.h" + +class Point : public Shape{ + +public: + explicit Point(int x, int y, Colors color); + void draw() override; +}; + + +#endif diff --git a/src/05_OO/b/Testat/Position.h b/src/05_OO/b/Testat/Position.h new file mode 100644 index 0000000..f977d98 --- /dev/null +++ b/src/05_OO/b/Testat/Position.h @@ -0,0 +1,14 @@ +#ifndef C_C_POSITION_H +#define C_C_POSITION_H + +struct Position { + int x; + int y; + + explicit Position(int x_ = 0, int y_ = 0) { + x = x_; + y = y_; + } +}; + +#endif \ No newline at end of file diff --git a/src/05_OO/b/Testat/Rectangle.cpp b/src/05_OO/b/Testat/Rectangle.cpp new file mode 100644 index 0000000..7aaa71a --- /dev/null +++ b/src/05_OO/b/Testat/Rectangle.cpp @@ -0,0 +1,23 @@ +#include "Rectangle.h" + +Rectangle::Rectangle(int x, int y, int width, int height, Colors color) : Shape(Position(x, y), color) { + this->width = width; + this->height = height; +} + +void Rectangle::draw() { + int x_start = position.x - (width / 2); + int x_stop = position.x + (width / 2); + + int y_start = position.y - (height / 2); + int y_stop = position.y + (height / 2); + + for(int i = x_start; i <= x_stop; i++) { + ansiConsole.printText(i, position.y - (height / 2), "#", color); + ansiConsole.printText(i, position.y + (height / 2), "#", color); + } + for(int i = y_start; i< y_stop; i++) { + ansiConsole.printText(position.x + (width / 2), i, "#", color); + ansiConsole.printText(position.x - (width / 2), i, "#", color); + } +} \ No newline at end of file diff --git a/src/05_OO/b/Testat/Rectangle.h b/src/05_OO/b/Testat/Rectangle.h new file mode 100644 index 0000000..f8775b9 --- /dev/null +++ b/src/05_OO/b/Testat/Rectangle.h @@ -0,0 +1,18 @@ +#include "Shape.h" + +#ifndef C_C_RECTANGLE_H +#define C_C_RECTANGLE_H + + +class Rectangle : public Shape{ +protected: + int width; + int height; + +public: + explicit Rectangle(int x = 0, int y = 0, int width = 0, int height = 0, Colors color = Colors::WHITE); + void draw() override; +}; + + +#endif //C_C_RECTANGLE_H diff --git a/src/05_OO/b/Testat/Scene.cpp b/src/05_OO/b/Testat/Scene.cpp new file mode 100644 index 0000000..9d25e7e --- /dev/null +++ b/src/05_OO/b/Testat/Scene.cpp @@ -0,0 +1,19 @@ +#include "Scene.h" +#include + +Scene::Scene(std::vector shapes) : shapes(std::move(shapes)) { + +} + +void Scene::draw() { + ansiConsole.clearScreen(); + for(Shape* shape : shapes) { + shape->draw(); + } +} + +Scene::~Scene() { + for(Shape* shape : shapes) { + delete shape; + } +} diff --git a/src/05_OO/b/Testat/Scene.h b/src/05_OO/b/Testat/Scene.h new file mode 100644 index 0000000..90e3352 --- /dev/null +++ b/src/05_OO/b/Testat/Scene.h @@ -0,0 +1,17 @@ +#include +#include "Shape.h" + +#ifndef C_C_SCENE_H +#define C_C_SCENE_H + +class Scene { +private: + std::vector shapes; +public: + explicit Scene(std::vector shapes); + void draw(); + ~Scene(); +}; + + +#endif //C_C_SCENE_H diff --git a/src/05_OO/b/Testat/Shape.cpp b/src/05_OO/b/Testat/Shape.cpp new file mode 100644 index 0000000..6fa576c --- /dev/null +++ b/src/05_OO/b/Testat/Shape.cpp @@ -0,0 +1,9 @@ +#include "Position.h" +#include "Shape.h" + +Shape::Shape(Position position, Colors color) { + this->position = position; + this->color = color; +} + +Shape::~Shape() = default; \ No newline at end of file diff --git a/src/05_OO/b/Testat/Shape.h b/src/05_OO/b/Testat/Shape.h new file mode 100644 index 0000000..f354055 --- /dev/null +++ b/src/05_OO/b/Testat/Shape.h @@ -0,0 +1,17 @@ +#ifndef C_C_SHAPE_H +#define C_C_SHAPE_H + +#include "../../../helpers/AnsiConsole.h" +#include "Position.h" + +class Shape { +protected: + Position position; + Colors color; +public: + Shape(Position position, Colors color); + virtual ~Shape(); + virtual void draw() = 0; +}; + +#endif \ No newline at end of file diff --git a/src/05_OO/b/Testat/shapes_main.cpp b/src/05_OO/b/Testat/shapes_main.cpp new file mode 100644 index 0000000..20dbcde --- /dev/null +++ b/src/05_OO/b/Testat/shapes_main.cpp @@ -0,0 +1,34 @@ +#include +#include "Shape.h" +#include "Point.h" +#include "Circle.h" +#include "Rectangle.h" +#include "Scene.h" + +int main(int argc, char **argv) { + std::vector shapes; + + shapes.push_back(new Point(30, 10, Colors::RED)); + shapes.push_back(new Point(28, 8, Colors::BLUE)); + shapes.push_back(new Point(32, 8, Colors::BLUE)); + + + shapes.push_back(new Circle(30, 10, 10, Colors::WHITE)); + shapes.push_back(new Circle(30, 20, 15, Colors::GREEN)); + + + shapes.push_back(new Rectangle(5, 21, 10, 10, Colors::MAGENTA)); + + shapes.push_back(new Point(5, 10, Colors::WHITE)); + shapes.push_back(new Point(15, 7, Colors::WHITE)); + shapes.push_back(new Point(7, 5, Colors::WHITE)); + + + auto *s = new Scene(shapes); + s->draw(); + + delete s; + + + return 0; +} diff --git a/src/06_POLY/CMakeLists.txt b/src/06_POLY/CMakeLists.txt new file mode 100644 index 0000000..2263977 --- /dev/null +++ b/src/06_POLY/CMakeLists.txt @@ -0,0 +1,2 @@ +add_executable(06_POLY_MP MP/shapes_main.cpp ../helpers/AnsiConsole.cpp) +add_executable(06_POLY_Testat Testat/shapes_main.cpp ../helpers/AnsiConsole.cpp) \ No newline at end of file diff --git a/src/07_STD/CMakeLists.txt b/src/07_STD/CMakeLists.txt new file mode 100644 index 0000000..1c1d2b1 --- /dev/null +++ b/src/07_STD/CMakeLists.txt @@ -0,0 +1,2 @@ +add_executable(07_STD_MP MP/grundgeruest.cpp) +add_executable(07_STD_Testat Testat/grundgeruest.cpp) \ No newline at end of file diff --git a/src/08_PTRN/CMakeLists.txt b/src/08_PTRN/CMakeLists.txt new file mode 100644 index 0000000..e69de29 diff --git a/src/10_PITF/CMakeLists.txt b/src/10_PITF/CMakeLists.txt new file mode 100644 index 0000000..e69de29 diff --git a/src/11_PUTT/CMakeLists.txt b/src/11_PUTT/CMakeLists.txt new file mode 100644 index 0000000..f86e1b2 --- /dev/null +++ b/src/11_PUTT/CMakeLists.txt @@ -0,0 +1 @@ +add_executable(11_PUTT Test.cpp) \ No newline at end of file diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4fd107a..2e92826 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,26 +1,14 @@ -add_executable(01_ENV_MP 01_ENV/MP/main.c 01_ENV/MP/func1.c) -target_link_libraries(01_ENV_MP m) -add_executable(01_ENV_Testat 01_ENV/Testat/main.c 01_ENV/Testat/func1.c) +add_subdirectory(01_ENV) +add_subdirectory(02_MENT) +add_subdirectory(03_FLOW) +add_subdirectory(04_UDEF) +add_subdirectory(05_OO) +add_subdirectory(06_POLY) +add_subdirectory(07_STD) +add_subdirectory(08_PTRN) +add_subdirectory(10_PITF) -add_executable(02_MENT_MP 02_MENT/MP/main_02_MENT.cpp) -add_executable(02_MENT_Testat 02_MENT/Testat/main_02_MENT.cpp) - -add_executable(03_FLOW_MP 03_FLOW/MP/main_mp2_FLOW_a.cpp helpers/AnsiConsole.cpp) -add_executable(03_FLOW_Testat 03_FLOW/Testat/main_mp2_FLOW_a.cpp helpers/AnsiConsole.cpp) - -add_executable(04_UDEF_MP 04_UDEF/MP/main_04_UDEF_e.cpp) -target_link_libraries(04_UDEF_MP m) -add_executable(04_UDEF_Testat 04_UDEF/Testat/main_04_UDEF_e.cpp) -target_link_libraries(04_UDEF_Testat m) - -add_executable(05_OO_MP 05_OO/MP/shapes_main.cpp helpers/AnsiConsole.cpp 05_OO/MP/Shape.cpp 05_OO/MP/Position.h 05_OO/MP/Shape.h 05_OO/MP/Point.cpp 05_OO/MP/Point.h 05_OO/MP/Circle.cpp 05_OO/MP/Circle.h 05_OO/MP/Rectangle.cpp 05_OO/MP/Rectangle.h 05_OO/MP/Scene.cpp 05_OO/MP/Scene.h) -add_executable(05_OO_Testat 05_OO/Testat/shapes_main.cpp helpers/AnsiConsole.cpp) - -add_executable(06_POLY_MP 06_POLY/MP/shapes_main.cpp helpers/AnsiConsole.cpp) -add_executable(06_POLY_Testat 06_POLY/Testat/shapes_main.cpp helpers/AnsiConsole.cpp) - -add_executable(07_STD_MP 07_STD/MP/grundgeruest.cpp) -add_executable(07_STD_Testat 07_STD/Testat/grundgeruest.cpp) +add_subdirectory(11_PUTT) #add_executable(SequenceDiagram 11_PUTT/05_OO_b/SequenceDiagramCreator.cpp 11_PUTT/05_OO_b/main.cpp) @@ -28,6 +16,4 @@ add_executable(07_STD_Testat 07_STD/Testat/grundgeruest.cpp) #add_executable(CopyOnWrite 11_PUTT/CopyOnWrite/OneByOneMatrix.cpp 11_PUTT/CopyOnWrite/LargeCowMatrix.cpp 11_PUTT/CopyOnWrite/main.cpp) -#add_executable(Banking 10_PITF/MP/banking_base_rawptr.cpp) - -add_executable(Test 11_PUTT/Test.cpp) \ No newline at end of file +#add_executable(Banking 10_PITF/MP/banking_base_rawptr.cpp) \ No newline at end of file