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
152 changes: 149 additions & 3 deletions animals/animal.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,153 @@
#include "animal.h"

using namespace std;
Animal::Animal() : _massInKilos(20)
{
}

int main() {
return 0;
void Animal::setMass(const float& newMass)
{
_massInKilos = newMass;
}

float Animal::getMass() const
{
return _massInKilos;
}

std::string Animal::about() const
{
return "mass: " + std::to_string(_massInKilos) + "\n";
}

Mammal::Mammal() : Animal(), _amountOfTeeth(20)
{

}

void Mammal::setAmountOfTeeth(const float& newAmount)
{
_amountOfTeeth = newAmount;
}

float Mammal::getAmountOfTeeth() const
{
return _amountOfTeeth;
}

std::string Mammal::about() const
{
return Animal::about() + "amount of teeth: " + std::to_string(_amountOfTeeth) + "\n";
}

Insect::Insect() : Animal(), _amountOfWings(2)
{

}

void Insect::setAmountOfWings(const unsigned int& newAmount)
{
_amountOfWings = newAmount;
}

unsigned int Insect::getAmountOfWings() const
{
return _amountOfWings;
}

std::string Insect::about() const
{
return Animal::about() + "amount of wings: " + std::to_string(_amountOfWings) + "\n";
}

Cat::Cat() : Mammal(), _eyeColor(color::blue)
{

}

void Cat::setEyeColor(const Cat::color& newColor)
{
_eyeColor = newColor;
}

Cat::color Cat::getEyeColor() const
{
return _eyeColor;
}

std::string Cat::about() const
{
return Mammal::about() + "eye color: " + std::to_string((int) _eyeColor) + "\n";
}

Dog::Dog() : Mammal(), _barkVolume(50)
{

}

void Dog::setBarkVolume(const float& newVolume)
{
_barkVolume = newVolume;
}

float Dog::getBarkVolume() const
{
return _barkVolume;
}

std::string Dog::about() const
{
return Mammal::about() + "bark volume: " + std::to_string(_barkVolume) + "\n";
}

Ladybug::Ladybug() : Insect(), _amountOfDots(3)
{

}

void Ladybug::setAmountOfDots(const unsigned int& newAmount)
{
_amountOfDots = newAmount;
}

unsigned int Ladybug::getAmountOfDots() const
{
return _amountOfDots;
}

std::string Ladybug::about() const
{
return Insect::about() + "amount of dots: " + std::to_string(_amountOfDots) + "\n";
}

Bumblebee::Bumblebee() : Insect(), _amountOfLines(10)
{

}

void Bumblebee::setAmountOfLines(const unsigned int& newAmount)
{
_amountOfLines = newAmount;
}

unsigned int Bumblebee::getAmountOfDots() const
{
return _amountOfLines;
}

std::string Bumblebee::about() const
{
return Insect::about() + "amount of lines: " + std::to_string(_amountOfLines) + "\n";
}

std::ostream& operator<<(std::ostream& out, const Animal& animal)
{
return out << animal.about() << std::endl;
}


int main()
{
Bumblebee b;
std::cout << b;
return EXIT_SUCCESS;
}
113 changes: 107 additions & 6 deletions animals/animal.h
Original file line number Diff line number Diff line change
@@ -1,18 +1,119 @@
#pragma once

#include <string>
#include <iostream>

class Animal {
class Animal
{
public:
float weight; // kg
void setMass(const float& newMass);

float getMass() const;

virtual std::string about() const;

protected:
Animal();

float _massInKilos;
};

class Mammal : public Animal {
class Mammal : public Animal
{
public:
float pregnancyDuration; // days
void setAmountOfTeeth(const float& newAmount);

float getAmountOfTeeth() const;

virtual std::string about() const override;


protected:
Mammal();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Не сделано: конструкторы, сразу инициализирующие поля.


unsigned int _amountOfTeeth;
};

class Cat : public Mammal {
class Insect : public Animal
{
public:
float vibrissaLength; // meters

void setAmountOfWings(const unsigned int& newAmount);

unsigned int getAmountOfWings() const;

virtual std::string about() const override;

protected:
Insect();

unsigned int _amountOfWings;
};

class Cat : public Mammal
{
public:
enum class color
{
grey = 0, yellow, blue, magenta
};

Cat();

void setEyeColor(const color& newColor);

color getEyeColor() const;

std::string about() const override;

private:
color _eyeColor;
};

class Dog : public Mammal
{
public:
Dog();

void setBarkVolume(const float& newVolume);

float getBarkVolume() const;

std::string about() const override;

private:

float _barkVolume;
};

class Ladybug : public Insect
{
public:
Ladybug();

void setAmountOfDots(const unsigned int& newAmount);

unsigned int getAmountOfDots() const;

std::string about() const override;

private:
unsigned int _amountOfDots;
};

class Bumblebee : public Insect
{
public:
Bumblebee();

void setAmountOfLines(const unsigned int& newAmount);

unsigned int getAmountOfDots() const;

std::string about() const override;

private:
unsigned int _amountOfLines;
};

std::ostream& operator<<(std::ostream& out, const Animal& animal);
Loading