Last active
January 8, 2026 12:54
-
-
Save m1irka/0ba958b91bf91ef3d30826bad2bde9e4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| using namespace std; | |
| class Pet { | |
| protected: | |
| const char* name; | |
| const char* ch; | |
| public: | |
| Pet(const char* n, const char* c) : name(n), ch(c) {} | |
| void showInfo() { | |
| cout << "Name: " << name << " Characteristic: " << ch << endl; | |
| } | |
| }; | |
| class Dog : public Pet { | |
| public: | |
| Dog(const char* n, const char* c) : Pet(n, c) {} | |
| void showInfo() { | |
| cout << "Dog Name: " << name << " Characteristic: " << ch << endl; | |
| } | |
| }; | |
| class Cat : public Pet { | |
| public: | |
| Cat(const char* n, const char* c) : Pet(n, c) {} | |
| void showInfo() { | |
| cout << "Cat Name: " << name << " Characteristic: " << ch << endl; | |
| } | |
| }; | |
| class Parrot : public Pet { | |
| public: | |
| Parrot(const char* n, const char* c) : Pet(n, c) {} | |
| void showInfo() { | |
| cout << "Parrot Name: " << name << " Characteristic: " << ch << endl; | |
| } | |
| }; | |
| int main() { | |
| Dog d("Buddy", "Loyal and playful"); | |
| Cat c("Murka", "Independent and curious"); | |
| Parrot p("Kesha", "Talkative and colorful"); | |
| d.showInfo(); | |
| c.showInfo(); | |
| p.showInfo(); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment