// inheritance1.cpp // Developer: Diep Thi Hoang // Note: Modified from Day 12 'Sams Teach Yourself C++ in 21 Days' #include using namespace std; enum BREED {YORKIE, CAIRN, DANDIE, SHETLAND, DOBERMAN, LAB}; // Lop Mammal mo phong dong vat co vu class Mammal{ public: // ham kien tao, ham huy Mammal(): itsAge(2), itsWeight(6){} ~Mammal(){} // ham truy cap bien thanh vien int getAge()const { return itsAge; } void setAge(int age) { itsAge = age; } int getWeight() const { return itsWeight; } void setWeight(int weight) { itsWeight = weight; } // ham khac void speak()const { cout << "Mammal sound!\n"; } void sleep()const { cout << "shhh. I'm sleeping.\n"; } protected: int itsAge; int itsWeight; }; // Lop Dog mo phong cho class Dog: public Mammal{ public: // ham kien tao, ham huy Dog(): itsBreed(YORKIE){} ~Dog(){} // ham truy cap bien thanh vien BREED getBreed() const { return itsBreed; } void setBreed(BREED breed) { itsBreed = breed; } // ham khac void speak()const { cout << "Ruff ruff woof woof!\n"; } void wagTail()const { cout << "Tail wagging...\n"; } void begForFood()const { cout << "Begging for food...\n"; } private: BREED itsBreed; }; // Lop Cat mo phong meo class Cat: protected Mammal{ public: void speak()const { cout << "Meow meow meow!\n"; } }; // Lop Horse mo phong ngua class Horse: private Mammal{ public: void speak()const { cout << "Winnie!\n"; } }; // Chuong trinh chinh int main(){ Dog laika; laika.speak(); laika.wagTail(); cout << "Laika is " << laika.getAge() << " years old\n"; cin.get(); return 0; }