From db905ddc37e0a9d6a883a5ccb351de6669b5325a Mon Sep 17 00:00:00 2001 From: Jimoh Date: Wed, 29 May 2024 15:43:29 +0100 Subject: [PATCH] completed exercise two --- .../jimoh_yusuf/ex01_basics/CMakeLists.txt | 13 ++- ...> cmakeFiles-v1-62d1a7d1ad487487bb18.json} | 4 - ...=> codemodel-v2-96976ee99bf3927d8850.json} | 2 +- ...on => index-2024-05-29T14-15-11-0280.json} | 8 +- ...rdCounter-Debug-38d7e9c602ffcde1e43c.json} | 107 +++++++----------- .../ex01_basics/cmake-build-debug/.ninja_deps | Bin 24668 -> 28704 bytes .../ex01_basics/cmake-build-debug/.ninja_log | 14 ++- .../Testing/Temporary/LastTest.log | 4 +- .../ex01_basics/cmake-build-debug/build.ninja | 31 +++-- .../jimoh_yusuf/ex02_oo_basics/CMakeLists.txt | 14 +-- .../ex02_oo_basics/ShapeSorter.cpp | 5 - .../jimoh_yusuf/ex02_oo_basics/ShapeSorter.h | 16 --- .../jimoh_yusuf/ex02_oo_basics/Triangle.h | 16 --- .../jimoh_yusuf/ex02_oo_basics/src/Circle.cpp | 30 +++++ .../jimoh_yusuf/ex02_oo_basics/src/Circle.h | 27 +++++ .../ex02_oo_basics/src/Rectangle.cpp | 30 +++++ .../ex02_oo_basics/src/Rectangle.h | 25 ++++ .../ex02_oo_basics/{ => src}/Shape.h | 0 .../ex02_oo_basics/src/ShapeSorter.cpp | 42 +++++++ .../ex02_oo_basics/src/ShapeSorter.h | 21 ++++ .../ex02_oo_basics/{ => src}/Square.cpp | 2 +- .../ex02_oo_basics/{ => src}/Square.h | 0 .../ex02_oo_basics/{ => src}/Triangle.cpp | 0 .../jimoh_yusuf/ex02_oo_basics/src/Triangle.h | 19 ++++ .../jimoh_yusuf/ex02_oo_basics/src/main.cpp | 44 ++++--- 25 files changed, 316 insertions(+), 158 deletions(-) rename exercises-cpp/jimoh_yusuf/ex01_basics/cmake-build-debug/.cmake/api/v1/reply/{cmakeFiles-v1-433e391d75207a7ab675.json => cmakeFiles-v1-62d1a7d1ad487487bb18.json} (98%) rename exercises-cpp/jimoh_yusuf/ex01_basics/cmake-build-debug/.cmake/api/v1/reply/{codemodel-v2-f34bfee0fe0b58026b8f.json => codemodel-v2-96976ee99bf3927d8850.json} (93%) rename exercises-cpp/jimoh_yusuf/ex01_basics/cmake-build-debug/.cmake/api/v1/reply/{index-2024-05-29T12-28-03-0350.json => index-2024-05-29T14-15-11-0280.json} (87%) rename exercises-cpp/jimoh_yusuf/ex01_basics/cmake-build-debug/.cmake/api/v1/reply/{target-WordCounter-Debug-034c12d909577b73f735.json => target-WordCounter-Debug-38d7e9c602ffcde1e43c.json} (51%) delete mode 100644 exercises-cpp/jimoh_yusuf/ex02_oo_basics/ShapeSorter.cpp delete mode 100644 exercises-cpp/jimoh_yusuf/ex02_oo_basics/ShapeSorter.h delete mode 100644 exercises-cpp/jimoh_yusuf/ex02_oo_basics/Triangle.h create mode 100644 exercises-cpp/jimoh_yusuf/ex02_oo_basics/src/Circle.cpp create mode 100644 exercises-cpp/jimoh_yusuf/ex02_oo_basics/src/Circle.h create mode 100644 exercises-cpp/jimoh_yusuf/ex02_oo_basics/src/Rectangle.cpp create mode 100644 exercises-cpp/jimoh_yusuf/ex02_oo_basics/src/Rectangle.h rename exercises-cpp/jimoh_yusuf/ex02_oo_basics/{ => src}/Shape.h (100%) create mode 100644 exercises-cpp/jimoh_yusuf/ex02_oo_basics/src/ShapeSorter.cpp create mode 100644 exercises-cpp/jimoh_yusuf/ex02_oo_basics/src/ShapeSorter.h rename exercises-cpp/jimoh_yusuf/ex02_oo_basics/{ => src}/Square.cpp (94%) rename exercises-cpp/jimoh_yusuf/ex02_oo_basics/{ => src}/Square.h (100%) rename exercises-cpp/jimoh_yusuf/ex02_oo_basics/{ => src}/Triangle.cpp (100%) create mode 100644 exercises-cpp/jimoh_yusuf/ex02_oo_basics/src/Triangle.h diff --git a/exercises-cpp/jimoh_yusuf/ex01_basics/CMakeLists.txt b/exercises-cpp/jimoh_yusuf/ex01_basics/CMakeLists.txt index fd173b7a..9767c815 100644 --- a/exercises-cpp/jimoh_yusuf/ex01_basics/CMakeLists.txt +++ b/exercises-cpp/jimoh_yusuf/ex01_basics/CMakeLists.txt @@ -7,22 +7,27 @@ cmake_minimum_required ( VERSION 2.8.5 ) project ( WordCounter ) # Find custom cmake modules -set ( CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../../CMake") +set ( CMAKE_MODULE_PATH "../../../CMake") # Common setup -include ( CommonSetup ) + ############################################################################### # Executable ############################################################################### set ( SRC_FILES - src/main.cpp + src/main.cpp # add any additional source files here ) set ( HDR_FILES + ../ex02_oo_basics/src/Rectangle.cpp + ../ex02_oo_basics/src/Rectangle.h + ../ex02_oo_basics/src/Circle.cpp + ../ex02_oo_basics/src/Circle.h + # add any additional header files here ) -add_executable ( WordCounter ${SRC_FILES} ${HDR_FILES} ) +add_executable ( WordCounter ${SRC_FILES} ${HDR_FILES}) diff --git a/exercises-cpp/jimoh_yusuf/ex01_basics/cmake-build-debug/.cmake/api/v1/reply/cmakeFiles-v1-433e391d75207a7ab675.json b/exercises-cpp/jimoh_yusuf/ex01_basics/cmake-build-debug/.cmake/api/v1/reply/cmakeFiles-v1-62d1a7d1ad487487bb18.json similarity index 98% rename from exercises-cpp/jimoh_yusuf/ex01_basics/cmake-build-debug/.cmake/api/v1/reply/cmakeFiles-v1-433e391d75207a7ab675.json rename to exercises-cpp/jimoh_yusuf/ex01_basics/cmake-build-debug/.cmake/api/v1/reply/cmakeFiles-v1-62d1a7d1ad487487bb18.json index 39257d9f..c3e7cb1d 100644 --- a/exercises-cpp/jimoh_yusuf/ex01_basics/cmake-build-debug/.cmake/api/v1/reply/cmakeFiles-v1-433e391d75207a7ab675.json +++ b/exercises-cpp/jimoh_yusuf/ex01_basics/cmake-build-debug/.cmake/api/v1/reply/cmakeFiles-v1-62d1a7d1ad487487bb18.json @@ -149,10 +149,6 @@ "isCMake" : true, "isExternal" : true, "path" : "C:/Program Files/JetBrains/CLion 2024.1.1/bin/cmake/win/x64/share/cmake-3.28/Modules/CMakeCommonLanguageInclude.cmake" - }, - { - "isExternal" : true, - "path" : "C:/Users/gfl56326/Documents/newstarter/CMake/CommonSetup.cmake" } ], "kind" : "cmakeFiles", diff --git a/exercises-cpp/jimoh_yusuf/ex01_basics/cmake-build-debug/.cmake/api/v1/reply/codemodel-v2-f34bfee0fe0b58026b8f.json b/exercises-cpp/jimoh_yusuf/ex01_basics/cmake-build-debug/.cmake/api/v1/reply/codemodel-v2-96976ee99bf3927d8850.json similarity index 93% rename from exercises-cpp/jimoh_yusuf/ex01_basics/cmake-build-debug/.cmake/api/v1/reply/codemodel-v2-f34bfee0fe0b58026b8f.json rename to exercises-cpp/jimoh_yusuf/ex01_basics/cmake-build-debug/.cmake/api/v1/reply/codemodel-v2-96976ee99bf3927d8850.json index cfc89ee2..49940fdb 100644 --- a/exercises-cpp/jimoh_yusuf/ex01_basics/cmake-build-debug/.cmake/api/v1/reply/codemodel-v2-f34bfee0fe0b58026b8f.json +++ b/exercises-cpp/jimoh_yusuf/ex01_basics/cmake-build-debug/.cmake/api/v1/reply/codemodel-v2-96976ee99bf3927d8850.json @@ -39,7 +39,7 @@ { "directoryIndex" : 0, "id" : "WordCounter::@6890427a1f51a3e7e1df", - "jsonFile" : "target-WordCounter-Debug-034c12d909577b73f735.json", + "jsonFile" : "target-WordCounter-Debug-38d7e9c602ffcde1e43c.json", "name" : "WordCounter", "projectIndex" : 0 } diff --git a/exercises-cpp/jimoh_yusuf/ex01_basics/cmake-build-debug/.cmake/api/v1/reply/index-2024-05-29T12-28-03-0350.json b/exercises-cpp/jimoh_yusuf/ex01_basics/cmake-build-debug/.cmake/api/v1/reply/index-2024-05-29T14-15-11-0280.json similarity index 87% rename from exercises-cpp/jimoh_yusuf/ex01_basics/cmake-build-debug/.cmake/api/v1/reply/index-2024-05-29T12-28-03-0350.json rename to exercises-cpp/jimoh_yusuf/ex01_basics/cmake-build-debug/.cmake/api/v1/reply/index-2024-05-29T14-15-11-0280.json index 6edac8a6..17b97679 100644 --- a/exercises-cpp/jimoh_yusuf/ex01_basics/cmake-build-debug/.cmake/api/v1/reply/index-2024-05-29T12-28-03-0350.json +++ b/exercises-cpp/jimoh_yusuf/ex01_basics/cmake-build-debug/.cmake/api/v1/reply/index-2024-05-29T14-15-11-0280.json @@ -26,7 +26,7 @@ "objects" : [ { - "jsonFile" : "codemodel-v2-f34bfee0fe0b58026b8f.json", + "jsonFile" : "codemodel-v2-96976ee99bf3927d8850.json", "kind" : "codemodel", "version" : { @@ -44,7 +44,7 @@ } }, { - "jsonFile" : "cmakeFiles-v1-433e391d75207a7ab675.json", + "jsonFile" : "cmakeFiles-v1-62d1a7d1ad487487bb18.json", "kind" : "cmakeFiles", "version" : { @@ -76,7 +76,7 @@ }, "cmakeFiles-v1" : { - "jsonFile" : "cmakeFiles-v1-433e391d75207a7ab675.json", + "jsonFile" : "cmakeFiles-v1-62d1a7d1ad487487bb18.json", "kind" : "cmakeFiles", "version" : { @@ -86,7 +86,7 @@ }, "codemodel-v2" : { - "jsonFile" : "codemodel-v2-f34bfee0fe0b58026b8f.json", + "jsonFile" : "codemodel-v2-96976ee99bf3927d8850.json", "kind" : "codemodel", "version" : { diff --git a/exercises-cpp/jimoh_yusuf/ex01_basics/cmake-build-debug/.cmake/api/v1/reply/target-WordCounter-Debug-034c12d909577b73f735.json b/exercises-cpp/jimoh_yusuf/ex01_basics/cmake-build-debug/.cmake/api/v1/reply/target-WordCounter-Debug-38d7e9c602ffcde1e43c.json similarity index 51% rename from exercises-cpp/jimoh_yusuf/ex01_basics/cmake-build-debug/.cmake/api/v1/reply/target-WordCounter-Debug-034c12d909577b73f735.json rename to exercises-cpp/jimoh_yusuf/ex01_basics/cmake-build-debug/.cmake/api/v1/reply/target-WordCounter-Debug-38d7e9c602ffcde1e43c.json index aed2b1fb..44673706 100644 --- a/exercises-cpp/jimoh_yusuf/ex01_basics/cmake-build-debug/.cmake/api/v1/reply/target-WordCounter-Debug-034c12d909577b73f735.json +++ b/exercises-cpp/jimoh_yusuf/ex01_basics/cmake-build-debug/.cmake/api/v1/reply/target-WordCounter-Debug-38d7e9c602ffcde1e43c.json @@ -2,10 +2,10 @@ "artifacts" : [ { - "path" : "bin/WordCounter.exe" + "path" : "WordCounter.exe" }, { - "path" : "bin/WordCounter.pdb" + "path" : "WordCounter.pdb" } ], "backtrace" : 1, @@ -13,15 +13,11 @@ { "commands" : [ - "add_executable", - "add_compile_options", - "include", - "add_definitions" + "add_executable" ], "files" : [ - "CMakeLists.txt", - "C:/Users/gfl56326/Documents/newstarter/CMake/CommonSetup.cmake" + "CMakeLists.txt" ], "nodes" : [ @@ -31,30 +27,8 @@ { "command" : 0, "file" : 0, - "line" : 28, + "line" : 33, "parent" : 0 - }, - { - "command" : 2, - "file" : 0, - "line" : 13, - "parent" : 0 - }, - { - "file" : 1, - "parent" : 2 - }, - { - "command" : 1, - "file" : 1, - "line" : 23, - "parent" : 3 - }, - { - "command" : 3, - "file" : 1, - "line" : 27, - "parent" : 3 } ] }, @@ -64,44 +38,15 @@ "compileCommandFragments" : [ { - "fragment" : "-g -std=c++17 -fdiagnostics-color=always" - }, - { - "backtrace" : 4, - "fragment" : "-Wall" - }, - { - "backtrace" : 4, - "fragment" : "-Wextra" - }, - { - "backtrace" : 4, - "fragment" : "-pedantic" - }, - { - "backtrace" : 4, - "fragment" : "-Werror" - } - ], - "defines" : - [ - { - "backtrace" : 5, - "define" : "_USE_MATH_DEFINES" + "fragment" : "-g -fdiagnostics-color=always" } ], "language" : "CXX", - "languageStandard" : - { - "backtraces" : - [ - 1 - ], - "standard" : "17" - }, "sourceIndexes" : [ - 0 + 0, + 1, + 3 ] } ], @@ -138,7 +83,17 @@ "name" : "Source Files", "sourceIndexes" : [ - 0 + 0, + 1, + 3 + ] + }, + { + "name" : "Header Files", + "sourceIndexes" : + [ + 2, + 4 ] } ], @@ -149,6 +104,28 @@ "compileGroupIndex" : 0, "path" : "src/main.cpp", "sourceGroupIndex" : 0 + }, + { + "backtrace" : 1, + "compileGroupIndex" : 0, + "path" : "C:/Users/gfl56326/Documents/newstarter/exercises-cpp/jimoh_yusuf/ex02_oo_basics/src/Rectangle.cpp", + "sourceGroupIndex" : 0 + }, + { + "backtrace" : 1, + "path" : "C:/Users/gfl56326/Documents/newstarter/exercises-cpp/jimoh_yusuf/ex02_oo_basics/src/Rectangle.h", + "sourceGroupIndex" : 1 + }, + { + "backtrace" : 1, + "compileGroupIndex" : 0, + "path" : "C:/Users/gfl56326/Documents/newstarter/exercises-cpp/jimoh_yusuf/ex02_oo_basics/src/Circle.cpp", + "sourceGroupIndex" : 0 + }, + { + "backtrace" : 1, + "path" : "C:/Users/gfl56326/Documents/newstarter/exercises-cpp/jimoh_yusuf/ex02_oo_basics/src/Circle.h", + "sourceGroupIndex" : 1 } ], "type" : "EXECUTABLE" diff --git a/exercises-cpp/jimoh_yusuf/ex01_basics/cmake-build-debug/.ninja_deps b/exercises-cpp/jimoh_yusuf/ex01_basics/cmake-build-debug/.ninja_deps index 5a4a18753bc44974b69b2667993972194f1ff6ed..e7a661229479c3ce2dd747820e51525096860465 100644 GIT binary patch delta 1344 zcmeIxTTc@~6bJBa5z(r_`a%?;a%s5;yS8#EiYOAJ0r8rsJd|}i9d^g;joEDiDv2h3 z0GfUA(Py4W`~v#q4exiw#4q4CFsc9Tnyrw)C-C8yoa{MsW_C_y^-<)(&&cv{u6Akp z*VOfgqq)YK$h}g$IXWhn#!sd)vSrD6#bLye98RQ5l(>qi>Qp4QEn4{-*>bt8l}?>b zZdxe_!XOF@C~VreP!k49qZ3o>3odJlO+`)UM~4eh;m#9uyFa)1n~v-go+5q*&tV*D zU<=g3R;Ys=uoJqy+1&BTPDB%M7A7GDO>hnp&;jS+AoM^lh|mTS9D*36A>%DfJLx1M z9SktRf?+rYBVfZUaBv{&?UEB0TM)IvEw~K}5QS~99ri;r9DsJ{g2T`U{V)K7Fa$^7 zs5dk%d0F|)X5$-UoK$CrRec*xrCNz?F_pdRr}DQz%Xp7>vpQlZt|p|tc>R@_A7Wg% zDlZ*3V~$P9OwklIsZyykgSn1~6svc6T2d9mP(+syq1P)lu!R53U&0h!#xmkE%an^Q z(_9Lo~>> zug&R-TBMu@$u>WC)&Ez{sG*pqe3QDtRSK<`>muID3ygtZTdKU36~r&$|62*)%86IF ekJs=9-oiV04 +#include +#include + +class Circle : public Shape { +private: + double radius; + +public: + Circle(double radius); + + std::string getType() override; + double calculatePerimeter() override; + double calculateArea() override; + int getNumberOfSides() override; +}; + +#endif // CIRCLE_H + diff --git a/exercises-cpp/jimoh_yusuf/ex02_oo_basics/src/Rectangle.cpp b/exercises-cpp/jimoh_yusuf/ex02_oo_basics/src/Rectangle.cpp new file mode 100644 index 00000000..76738c84 --- /dev/null +++ b/exercises-cpp/jimoh_yusuf/ex02_oo_basics/src/Rectangle.cpp @@ -0,0 +1,30 @@ +// +// Created by gfl56326 on 29/05/2024. +// + +#include "Rectangle.h" + +Rectangle::Rectangle(double s1, double s2) : side1(s1), side2(s2) { + number_of_sides = 4; +} + +std::string Rectangle::getType() { + return "Rectangle"; +} + +double Rectangle::calculatePerimeter() { + double perimeter = 2 * (side1 + side2); + std::cout << "The perimeter of the rectangle is " << perimeter << std::endl; + return perimeter; +} + +double Rectangle::calculateArea() { + double area = side1 * side2; + std::cout << "The area of the rectangle is " << area << std::endl; + return area; +} + +int Rectangle::getNumberOfSides() { + return number_of_sides; +} + diff --git a/exercises-cpp/jimoh_yusuf/ex02_oo_basics/src/Rectangle.h b/exercises-cpp/jimoh_yusuf/ex02_oo_basics/src/Rectangle.h new file mode 100644 index 00000000..f03eae60 --- /dev/null +++ b/exercises-cpp/jimoh_yusuf/ex02_oo_basics/src/Rectangle.h @@ -0,0 +1,25 @@ +// +// Created by gfl56326 on 29/05/2024. +// + +#ifndef RECTANGLE_H +#define RECTANGLE_H + +#include "Shape.h" +#include +#include + +class Rectangle : public Shape { +private: + double side1, side2; + +public: + Rectangle(double side1, double side2); + + std::string getType() override; + double calculatePerimeter() override; + double calculateArea() override; + int getNumberOfSides() override; +}; + +#endif // RECTANGLE_H diff --git a/exercises-cpp/jimoh_yusuf/ex02_oo_basics/Shape.h b/exercises-cpp/jimoh_yusuf/ex02_oo_basics/src/Shape.h similarity index 100% rename from exercises-cpp/jimoh_yusuf/ex02_oo_basics/Shape.h rename to exercises-cpp/jimoh_yusuf/ex02_oo_basics/src/Shape.h diff --git a/exercises-cpp/jimoh_yusuf/ex02_oo_basics/src/ShapeSorter.cpp b/exercises-cpp/jimoh_yusuf/ex02_oo_basics/src/ShapeSorter.cpp new file mode 100644 index 00000000..6940dced --- /dev/null +++ b/exercises-cpp/jimoh_yusuf/ex02_oo_basics/src/ShapeSorter.cpp @@ -0,0 +1,42 @@ +// +// Created by gfl56326 on 28/05/2024. +// + +#include "ShapeSorter.h" + +void ShapeSorter::printShapesByType(const std::vector& shapes, const std::string& type) { + for (const auto& shape : shapes) { + if (shape->getType() == type) { + std::cout << shape->getType() << " with area: " << shape->calculateArea() << " and perimeter: " << shape->calculatePerimeter() << std::endl; + } + } +} + +void ShapeSorter::printShapesBySides(const std::vector& shapes, int numberOfSides) { + for (const auto& shape : shapes) { + if (shape->getNumberOfSides() == numberOfSides) { + std::cout << shape->getType() << " with area: " << shape->calculateArea() << " and perimeter: " << shape->calculatePerimeter() << std::endl; + } + } +} + +void ShapeSorter::printShapesByAreaDescending(std::vector& shapes) { + std::sort(shapes.begin(), shapes.end(), [](Shape* a, Shape* b) { + return a->calculateArea() > b->calculateArea(); + }); + + for (const auto& shape : shapes) { + std::cout << shape->getType() << " with area: " << shape->calculateArea() << " and perimeter: " << shape->calculatePerimeter() << std::endl; + } +} + +void ShapeSorter::printShapesByPerimeterDescending(std::vector& shapes) { + std::sort(shapes.begin(), shapes.end(), [](Shape* a, Shape* b) { + return a->calculatePerimeter() > b->calculatePerimeter(); + }); + + for (const auto& shape : shapes) { + std::cout << shape->getType() << " with area: " << shape->calculateArea() << " and perimeter: " << shape->calculatePerimeter() << std::endl; + } +} + diff --git a/exercises-cpp/jimoh_yusuf/ex02_oo_basics/src/ShapeSorter.h b/exercises-cpp/jimoh_yusuf/ex02_oo_basics/src/ShapeSorter.h new file mode 100644 index 00000000..f9c9c975 --- /dev/null +++ b/exercises-cpp/jimoh_yusuf/ex02_oo_basics/src/ShapeSorter.h @@ -0,0 +1,21 @@ +// +// Created by gfl56326 on 28/05/2024. +// + +#ifndef SHAPESORTER_H +#define SHAPESORTER_H + +#include "Shape.h" +#include +#include +#include + +class ShapeSorter { +public: + void printShapesByType(const std::vector& shapes, const std::string& type); + void printShapesBySides(const std::vector& shapes, int numberOfSides); + void printShapesByAreaDescending(std::vector& shapes); + void printShapesByPerimeterDescending(std::vector& shapes); +}; + +#endif // SHAPESORTER_H diff --git a/exercises-cpp/jimoh_yusuf/ex02_oo_basics/Square.cpp b/exercises-cpp/jimoh_yusuf/ex02_oo_basics/src/Square.cpp similarity index 94% rename from exercises-cpp/jimoh_yusuf/ex02_oo_basics/Square.cpp rename to exercises-cpp/jimoh_yusuf/ex02_oo_basics/src/Square.cpp index f0a617bf..66bb6f7b 100644 --- a/exercises-cpp/jimoh_yusuf/ex02_oo_basics/Square.cpp +++ b/exercises-cpp/jimoh_yusuf/ex02_oo_basics/src/Square.cpp @@ -18,7 +18,7 @@ double Square::calculatePerimeter() { return perimeter; } -double Square::calculateArea() { +double Square::calculateAreaa() { double area = side1 * side1; std::cout << "The area of the square is " << area << std::endl; return area; diff --git a/exercises-cpp/jimoh_yusuf/ex02_oo_basics/Square.h b/exercises-cpp/jimoh_yusuf/ex02_oo_basics/src/Square.h similarity index 100% rename from exercises-cpp/jimoh_yusuf/ex02_oo_basics/Square.h rename to exercises-cpp/jimoh_yusuf/ex02_oo_basics/src/Square.h diff --git a/exercises-cpp/jimoh_yusuf/ex02_oo_basics/Triangle.cpp b/exercises-cpp/jimoh_yusuf/ex02_oo_basics/src/Triangle.cpp similarity index 100% rename from exercises-cpp/jimoh_yusuf/ex02_oo_basics/Triangle.cpp rename to exercises-cpp/jimoh_yusuf/ex02_oo_basics/src/Triangle.cpp diff --git a/exercises-cpp/jimoh_yusuf/ex02_oo_basics/src/Triangle.h b/exercises-cpp/jimoh_yusuf/ex02_oo_basics/src/Triangle.h new file mode 100644 index 00000000..cab28640 --- /dev/null +++ b/exercises-cpp/jimoh_yusuf/ex02_oo_basics/src/Triangle.h @@ -0,0 +1,19 @@ +// +// Created by gfl56326 on 29/05/2024. +// + +#ifndef TRIANGLE_H +#define TRIANGLE_H + +class Triangle : public Shape { +private: + double side1; +public: + Triangle(double side); + + std::string getType() override; + double calculateArea() override; + int getNumberOfSides() override; +}; + +#endif //TRIANGLE_H diff --git a/exercises-cpp/jimoh_yusuf/ex02_oo_basics/src/main.cpp b/exercises-cpp/jimoh_yusuf/ex02_oo_basics/src/main.cpp index 27cd3b40..f7e819b8 100644 --- a/exercises-cpp/jimoh_yusuf/ex02_oo_basics/src/main.cpp +++ b/exercises-cpp/jimoh_yusuf/ex02_oo_basics/src/main.cpp @@ -4,27 +4,37 @@ #include using namespace std; -int main(int, char **) -{ - std::cout << "kolala" << std::endl; - //Square square(6); - //unique_ptr square = make_unique(6.0); - //shared_ptr square2 = make_shared(7.0); - //square->calculateArea(); - //square.calculatePerimeter(); +#include "Square.h" +#include "Rectangle.h" +#include "Circle.h" +#include "Triangle.h" +#include "ShapeSorter.h" +#include - //std::vector> shapes; - //shapes.push_back(square2); - //shapes.push_back(square2); +int main() { + // Create shapes + Square square(5.0); + Rectangle rectangle(4.0, 6.0); + Circle circle(3.0); + Triangle triangle(4.0, 6.0); - //v.push_back(10); + std::vector shapes = {&square, &rectangle, &circle, &triangle}; - //vector> shapes2; + ShapeSorter sorter; - // Creating a variety of shapes - //shapes2.push_back(make_shared(7.0)); - // - //std::cout << "kolala" << shapes2[1]->getType() << endl; + // Print shapes by type + std::cout << "Shapes of type 'Square':" << std::endl; + sorter.printShapesByType(shapes, "Square"); + // Print shapes by number of sides + std::cout << "\nShapes with 4 sides:" << std::endl; + sorter.printShapesBySides(shapes, 4); + + // Print shapes by area descending + std::cout << "\nShapes sorted by area (descending):" << std::endl; + sorter.printShapesByAreaDescending(shapes); + + // Print shapes by perimeter descending + std::cout << "\nShapes sorted by perimeter (descending): } \ No newline at end of file