Untitled
unknown
c_cpp
a year ago
1.1 kB
5
Indexable
#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; }
Editor is loading...
Leave a Comment