#include <iostream>
#include <string>
class Animal {
public:
Animal()
{ //std::cout << "tworze obiekt klasy Animal\n";
age = 0;
ilosc++; }
~Animal() {
ilosc--; }
int getAge() {
return age; }
virtual void sound() {
std::cout << "zwierzeta wydaja rozne glosy... " << std::endl; }
static int ile() { return ilosc; }
protected:
int age;
std::string name;
private:
static int ilosc;
};
int Animal::ilosc = 2;
class Lion : public Animal
{
public:
Lion(int age) { std::cout<< "tworze obiekt klasy Lion\n";
this->age = age; }
void sound() {
std::cout << "Lew robi mrau!\n"; }
};
class Pet : public Animal {
public:
Pet() {
std::cout << "tworze obiekt klasy Pet" << std::endl;
name = ""; }
void sound() {
std::cout << "Pecik mowi kizia mizia\n"; }
std::string getName() {
return name; }
protected:
std::string name;
};
class Dog : public Animal {
public:
Dog(int age, std::string name) { std::cout << "tworze obiekt klasy Dog\n";
this->age = age;
this->name = name; }
int getHumanAge() {
int x;
x = this->getAge() *4;
return x; }
void sound() {
std::cout << "Pies robi hau hau!\n"; }
protected:
std::string name;
};
int main() {
std::cout << "ilosc animalsow na moment obecny to: " << Animal::ile << std::endl;
Animal *animal = new Pet();
std::cout << "a teraz zwierzakow jest: " << Animal::ile << std::endl;
Animal *toska = new Dog(12, "toska");
std::cout << "a teraz zwierzakow jest: " << Animal::ile << std::endl;
Animal *marchewka = new Lion(6);
std::cout << "a teraz zwierzakow jest: " << Animal::ile << std::endl;
return 0;
}