From ec65932144d859d5c543363b593092d0fc677223 Mon Sep 17 00:00:00 2001 From: Tin Serdar Date: Thu, 15 Nov 2018 09:05:16 +0100 Subject: [PATCH] Rijesenje zadatka 3 --- exercise/01/animal.cpp | 1 + exercise/01/animal.h | 13 +++++++ exercise/01/animal_factory.h | 20 +++++++++++ exercise/01/animals.sln | 25 +++++++++++++ exercise/01/animals.vcxproj | 15 ++++++++ exercise/01/animals.vcxproj.filters | 54 +++++++++++++++++++++++++++++ exercise/01/bird.cpp | 17 +++++++++ exercise/01/bird.h | 13 +++++++ exercise/01/cockroach.cpp | 17 +++++++++ exercise/01/cockroach.h | 16 +++++++++ exercise/01/insect.cpp | 17 +++++++++ exercise/01/insect.h | 13 +++++++ exercise/01/leg_counter.cpp | 27 +++++++++++++++ exercise/01/leg_counter.h | 15 ++++++++ exercise/01/sparrow.cpp | 17 +++++++++ exercise/01/sparrow.h | 14 ++++++++ exercise/01/spider.cpp | 17 +++++++++ exercise/01/spider.h | 14 ++++++++ exercise/01/tarantula.cpp | 17 +++++++++ exercise/01/tarantula.h | 14 ++++++++ exercise/01/test.cpp | 5 +++ 21 files changed, 361 insertions(+) create mode 100644 exercise/01/animal.cpp create mode 100644 exercise/01/animal.h create mode 100644 exercise/01/animal_factory.h create mode 100644 exercise/01/animals.sln create mode 100644 exercise/01/bird.cpp create mode 100644 exercise/01/bird.h create mode 100644 exercise/01/cockroach.cpp create mode 100644 exercise/01/cockroach.h create mode 100644 exercise/01/insect.cpp create mode 100644 exercise/01/insect.h create mode 100644 exercise/01/leg_counter.cpp create mode 100644 exercise/01/leg_counter.h create mode 100644 exercise/01/sparrow.cpp create mode 100644 exercise/01/sparrow.h create mode 100644 exercise/01/spider.cpp create mode 100644 exercise/01/spider.h create mode 100644 exercise/01/tarantula.cpp create mode 100644 exercise/01/tarantula.h diff --git a/exercise/01/animal.cpp b/exercise/01/animal.cpp new file mode 100644 index 0000000..77fa638 --- /dev/null +++ b/exercise/01/animal.cpp @@ -0,0 +1 @@ +#include "animal.h" diff --git a/exercise/01/animal.h b/exercise/01/animal.h new file mode 100644 index 0000000..9740b09 --- /dev/null +++ b/exercise/01/animal.h @@ -0,0 +1,13 @@ +#pragma once + +#include + +class animal +{ +public: + virtual ~animal() = default; + + virtual std::wstring species() = 0; + virtual unsigned int legs() = 0; +}; + diff --git a/exercise/01/animal_factory.h b/exercise/01/animal_factory.h new file mode 100644 index 0000000..6d920dc --- /dev/null +++ b/exercise/01/animal_factory.h @@ -0,0 +1,20 @@ +#pragma once + +#include "cockroach.h" +#include "sparrow.h" +#include "tarantula.h" + +animal* animal_factory(unsigned int type) +{ + switch (type) + { + case 1: + return new cockroach; + case 2: + return new sparrow; + case 3: + return new tarantula; + default: + return nullptr; + } +} diff --git a/exercise/01/animals.sln b/exercise/01/animals.sln new file mode 100644 index 0000000..fa74491 --- /dev/null +++ b/exercise/01/animals.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.28010.2050 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "animals", "animals.vcxproj", "{BB15329E-10D8-4740-94BC-64C50BA4EE12}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x86 = Debug|x86 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {BB15329E-10D8-4740-94BC-64C50BA4EE12}.Debug|x86.ActiveCfg = Debug|Win32 + {BB15329E-10D8-4740-94BC-64C50BA4EE12}.Debug|x86.Build.0 = Debug|Win32 + {BB15329E-10D8-4740-94BC-64C50BA4EE12}.Release|x86.ActiveCfg = Release|Win32 + {BB15329E-10D8-4740-94BC-64C50BA4EE12}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {D129E7D0-15C2-47FA-860B-F3A56F576424} + EndGlobalSection +EndGlobal diff --git a/exercise/01/animals.vcxproj b/exercise/01/animals.vcxproj index 0c14cbf..8c443d2 100644 --- a/exercise/01/animals.vcxproj +++ b/exercise/01/animals.vcxproj @@ -84,9 +84,24 @@ + + + + + + + + + + + + + + + diff --git a/exercise/01/animals.vcxproj.filters b/exercise/01/animals.vcxproj.filters index ad4d9ab..0fc296b 100644 --- a/exercise/01/animals.vcxproj.filters +++ b/exercise/01/animals.vcxproj.filters @@ -7,6 +7,15 @@ {3cc0fd48-6585-4969-94bd-406daa5f786b} + + {86b04c11-d90c-49df-b0c7-c75f1c188abc} + + + {4440da7f-201a-4e94-b132-3fbf2265aaf7} + + + {f21d6caf-1229-4633-85c6-66427a707c9d} + @@ -15,10 +24,55 @@ src + + src + + + src\birds + + + src\birds + + + src\insects + + + src\insects + + + src\spiders + + + src\spiders + src + + src + + + src + + + src\birds + + + src\birds + + + src\insects + + + src\insects + + + src\spiders + + + src\spiders + \ No newline at end of file diff --git a/exercise/01/bird.cpp b/exercise/01/bird.cpp new file mode 100644 index 0000000..d554162 --- /dev/null +++ b/exercise/01/bird.cpp @@ -0,0 +1,17 @@ +#include "bird.h" + +const unsigned int bird::numberOfLegs = 2; + +bird::bird() +{ +} + + +bird::~bird() +{ +} + +unsigned int bird::legs() +{ + return numberOfLegs; +} diff --git a/exercise/01/bird.h b/exercise/01/bird.h new file mode 100644 index 0000000..ffdf4ad --- /dev/null +++ b/exercise/01/bird.h @@ -0,0 +1,13 @@ +#pragma once +#include "animal.h" + +class bird : + public animal +{ +public: + bird(); + ~bird(); + static const unsigned int numberOfLegs; + unsigned int legs(); +}; + diff --git a/exercise/01/cockroach.cpp b/exercise/01/cockroach.cpp new file mode 100644 index 0000000..21124ba --- /dev/null +++ b/exercise/01/cockroach.cpp @@ -0,0 +1,17 @@ +#include "cockroach.h" + +const std::wstring cockroach::name = L"cockroach"; + +cockroach::cockroach() +{ +} + + +cockroach::~cockroach() +{ +} + +std::wstring cockroach::species() +{ + return name; +} diff --git a/exercise/01/cockroach.h b/exercise/01/cockroach.h new file mode 100644 index 0000000..513b084 --- /dev/null +++ b/exercise/01/cockroach.h @@ -0,0 +1,16 @@ +#pragma once +#include "insect.h" + + +class cockroach : + public insect +{ +public: + cockroach(); + ~cockroach(); + std::wstring species(); + +private: + static const std::wstring name; +}; + diff --git a/exercise/01/insect.cpp b/exercise/01/insect.cpp new file mode 100644 index 0000000..bf0275a --- /dev/null +++ b/exercise/01/insect.cpp @@ -0,0 +1,17 @@ +#include "insect.h" + +const unsigned int insect::numberOfLegs = 6; + +insect::insect() +{ +} + + +insect::~insect() +{ +} + +unsigned int insect::legs() +{ + return numberOfLegs; +} \ No newline at end of file diff --git a/exercise/01/insect.h b/exercise/01/insect.h new file mode 100644 index 0000000..35a2702 --- /dev/null +++ b/exercise/01/insect.h @@ -0,0 +1,13 @@ +#pragma once +#include "animal.h" + +class insect : + public animal +{ +public: + insect(); + ~insect(); + unsigned int legs(); + static const unsigned int numberOfLegs; +}; + diff --git a/exercise/01/leg_counter.cpp b/exercise/01/leg_counter.cpp new file mode 100644 index 0000000..a31906e --- /dev/null +++ b/exercise/01/leg_counter.cpp @@ -0,0 +1,27 @@ +#include "leg_counter.h" + + + +leg_counter::leg_counter() : + legCount(0) +{ +} + + +leg_counter::~leg_counter() +{ +} + +std::wstring leg_counter::add_animal(animal* animal) +{ + legCount += animal->legs(); + std::wstring species = animal->species(); + delete animal; + animal = nullptr; + return species; +} + +unsigned int leg_counter::legs() +{ + return legCount; +} diff --git a/exercise/01/leg_counter.h b/exercise/01/leg_counter.h new file mode 100644 index 0000000..d97f7d9 --- /dev/null +++ b/exercise/01/leg_counter.h @@ -0,0 +1,15 @@ +#pragma once +#include +#include "animal.h" + +class leg_counter +{ +private: + int legCount; +public: + leg_counter(); + ~leg_counter(); + std::wstring add_animal(animal*); + unsigned int legs(); +}; + diff --git a/exercise/01/sparrow.cpp b/exercise/01/sparrow.cpp new file mode 100644 index 0000000..80bcd9d --- /dev/null +++ b/exercise/01/sparrow.cpp @@ -0,0 +1,17 @@ +#include "sparrow.h" + +const std::wstring sparrow::name = L"sparrow"; + +sparrow::sparrow() +{ +} + + +sparrow::~sparrow() +{ +} + +std::wstring sparrow::species() +{ + return name; +} \ No newline at end of file diff --git a/exercise/01/sparrow.h b/exercise/01/sparrow.h new file mode 100644 index 0000000..43e477c --- /dev/null +++ b/exercise/01/sparrow.h @@ -0,0 +1,14 @@ +#pragma once +#include "bird.h" + +class sparrow : + public bird +{ +private: + static const std::wstring name; +public: + sparrow(); + ~sparrow(); + std::wstring species(); +}; + diff --git a/exercise/01/spider.cpp b/exercise/01/spider.cpp new file mode 100644 index 0000000..25f9be2 --- /dev/null +++ b/exercise/01/spider.cpp @@ -0,0 +1,17 @@ +#include "spider.h" + +const unsigned int spider::numberOfLegs = 8; + +spider::spider() +{ +} + + +spider::~spider() +{ +} + +unsigned int spider::legs() +{ + return numberOfLegs; +} \ No newline at end of file diff --git a/exercise/01/spider.h b/exercise/01/spider.h new file mode 100644 index 0000000..5ada574 --- /dev/null +++ b/exercise/01/spider.h @@ -0,0 +1,14 @@ +#pragma once +#include "animal.h" + +class spider : + public animal +{ +private: + static const unsigned int numberOfLegs; +public: + spider(); + ~spider(); + unsigned int legs(); +}; + diff --git a/exercise/01/tarantula.cpp b/exercise/01/tarantula.cpp new file mode 100644 index 0000000..0b7d304 --- /dev/null +++ b/exercise/01/tarantula.cpp @@ -0,0 +1,17 @@ +#include "tarantula.h" + +const std::wstring tarantula::name = L"tarantula"; + +tarantula::tarantula() +{ +} + + +tarantula::~tarantula() +{ +} + +std::wstring tarantula::species() +{ + return name; +} \ No newline at end of file diff --git a/exercise/01/tarantula.h b/exercise/01/tarantula.h new file mode 100644 index 0000000..e5702fb --- /dev/null +++ b/exercise/01/tarantula.h @@ -0,0 +1,14 @@ +#pragma once +#include "spider.h" + +class tarantula : + public spider +{ +private: + static const std::wstring name; +public: + tarantula(); + ~tarantula(); + std::wstring species(); +}; + diff --git a/exercise/01/test.cpp b/exercise/01/test.cpp index f7f2c1f..7ee2a53 100644 --- a/exercise/01/test.cpp +++ b/exercise/01/test.cpp @@ -2,6 +2,11 @@ using namespace Microsoft::VisualStudio::CppUnitTestFramework; #include "animal.h" +#include "cockroach.h" +#include "sparrow.h" +#include "tarantula.h" +#include "leg_counter.h" +#include "animal_factory.h" TEST_CLASS(test_animal_hierarchy) {