Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion animals/animal.cpp
Original file line number Diff line number Diff line change
@@ -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;
}
17 changes: 7 additions & 10 deletions animals/animal.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,13 @@
#include <iostream>

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; }
};
50 changes: 50 additions & 0 deletions animals/bird.h
Original file line number Diff line number Diff line change
@@ -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;
}
66 changes: 66 additions & 0 deletions animals/mammal.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#pragma once

#include <iostream>
#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;
}