Untitled

mail@pastecode.io avatar
unknown
c_cpp
3 days ago
1.1 kB
2
Indexable
Never
#include <iostream>

class Animal {
private:
    int legs;
public:
    
    Animal (int legs) : legs(legs) {};
    void setLegs(int Legs) {
        Legs = legs;
    }
    int getLegs() {
        return legs;
    }
    virtual void print() const = 0 {};
};


class Dog : public Animal {

    
public:
    Dog(int legs) : Animal(legs) {};

    void print () const override {
        std::cout << "gav gav\n";
    }
    void loseLeg() {
        setLegs(getLegs() - 1); // сетер позволяет изменять значения, гетер их возвращает!!!
        std::cout << "minus noga, cobaka lox, ostalos" << getLegs;    
    }

};
class Human : public Animal {
    
public:
    Human(int legs) : Animal(legs) {};

    void print() const override {
        std::cout << " hello world\n";
    }
};


int main()
{
    
        Dog myDog(4);
        std::cout << "nogi sobaki" << myDog.getLegs() << std::endl;

        myDog.loseLeg();
        myDog.print();

        Human human(2);
        std::cout << "nogi Humana " << human.getLegs() << std::endl;
        human.print();

        return 0;
    
}
Leave a Comment