diff --git a/animals/animal.cpp b/animals/animal.cpp index 6745215..c6e4f47 100644 --- a/animals/animal.cpp +++ b/animals/animal.cpp @@ -1,7 +1,27 @@ #include "animal.h" +#include "mammal.h" +#include "bird.h" -using namespace std; +void printBirdInfo() { + Eagle sharpSightedEagle(12, 1.2, 0.9); + + Parrot niceGreenParrot(5570463, 0.1, 0.3); + + std::cout << sharpSightedEagle << std::endl << niceGreenParrot << std::endl; +} + +void printMammalInfo() { + Cat littleKitten(0.05, 60, 0.5); + + Dog bigScaryDog(Chauchau, 50, 10); + + std::cout << littleKitten << std::endl << bigScaryDog; +} int main() { + + printBirdInfo(); + printMammalInfo(); + return 0; } \ No newline at end of file diff --git a/animals/animal.h b/animals/animal.h index 83a1944..2be806f 100644 --- a/animals/animal.h +++ b/animals/animal.h @@ -3,16 +3,13 @@ #include class Animal { -public: - float weight; // kg -}; + private: + float weight; // kg -class Mammal : public Animal { -public: - float pregnancyDuration; // days -}; + public: + const float getWeight() const { return weight; } + void setWeight(const float v) { weight = v; } -class Cat : public Mammal { -public: - float vibrissaLength; // meters + protected: + Animal(const float w) { weight = w; } }; diff --git a/animals/bird.h b/animals/bird.h new file mode 100644 index 0000000..bd24c05 --- /dev/null +++ b/animals/bird.h @@ -0,0 +1,50 @@ +#pragma once + +#include "animal.h" + +class Bird : public Animal { + private: + float wingLength; // meters + public: + const float getWingLength() const { return wingLength; } + void setWingLength(const float v) { wingLength = v; } + protected: + Bird(const float wl, const float weight) : Animal(weight) { wingLength = wl;} +}; + +class Eagle : public Bird { + private: + float visionStrength; // between 0 and 1 + public: + Eagle(const float vs, const float wl, const float weight) : Bird(wl, weight) { + visionStrength = vs; + } + const float getVisionStrength() const { return visionStrength; } + void setVisionStrength(const float v) { visionStrength = v; } +}; + +class Parrot : public Bird { + private: + int plumageColor; // int in 16 base (5570463 -> #54ff9f) + public: + Parrot(const int pc, const float wl, const float weight) : Bird(wl, weight) { + plumageColor = pc; + } + const int getPlumageColor() const { return plumageColor; } + void setPlumageColor(const int v) { plumageColor = v; } + +}; + +std::ostream& operator << (std::ostream& os, const Parrot& p) { + os << "parrot's color: " << p.getPlumageColor() << std::endl; + os << "parrot's wing length: " << p.getWingLength() << std::endl; + os << "parrot's weight: " << p.getWeight() << std::endl; + return os; +} + +std::ostream& operator << (std::ostream& os, const Eagle& e) { + os << "eagle's vision strength: " << e.getVisionStrength() << std::endl; + os << "eagle's wing length: " << e.getWingLength() << std::endl; + os << "eagle's weight: " << e.getWeight() << std::endl; + return os; +} \ No newline at end of file diff --git a/animals/mammal.h b/animals/mammal.h new file mode 100644 index 0000000..c5dbe4d --- /dev/null +++ b/animals/mammal.h @@ -0,0 +1,66 @@ +#pragma once + +#include +#include "animal.h" + +class Mammal : public Animal { + private: + float pregnancyDuration; // days + public: + const float getPregnancyDuration() const { return pregnancyDuration; } + void setPregnancyDuration(const float d) { pregnancyDuration = d; } + protected: + Mammal(const float pd, const float weight) : Animal(weight) { + pregnancyDuration = pd; + } +}; + +class Cat : public Mammal { + private: + float vibrissaLength; // meters + public: + Cat(const float vl, const float pd, const float weight) : Mammal(pd, weight) { + vibrissaLength = vl; + } + const float getVibrissaLength() const { return vibrissaLength; } + void setVibrissaLength(const float v) { vibrissaLength = v; } +}; + +enum Breed { Sharpey, Terier, Chauchau }; + +class Dog : public Mammal { + private: + Breed breed; + public: + Dog(const Breed b, const float pd, const float weight) : Mammal(pd, weight) { + breed = b; + } + const Breed getBreed() const { return breed; } + void setBreed(const Breed b) { breed = b; } + + const std::string getBreedAsString() const { + std::string strBreed = ""; + switch (breed) { + case Sharpey: strBreed = "sharpey"; break; + case Terier: strBreed = "terier"; break; + case Chauchau: strBreed = "chau chau"; break; + } + + return strBreed; + } +}; + +std::ostream& operator << (std::ostream& os, const Cat& c) { + os << "cat's vibrissa length: " << c.getVibrissaLength() << std::endl; + os << "cat's pregnancy duration: " << c.getPregnancyDuration() << std::endl; + os << "cat's weight: " << c.getWeight() << std::endl; + return os; +} + +std::ostream& operator << (std::ostream& os, const Dog& d) { + + os << "dog's breed: " << d.getBreedAsString() << std::endl; + os << "dog's pregnancy duration: " << d.getPregnancyDuration() << std::endl; + os << "dog's weight: " << d.getWeight() << std::endl; + return os; +} \ No newline at end of file