#include #include #include #include #include #include #include #include #include #ifdef __cplusplus #include #include #include #include #include #include #include #endif #define COINFLIP() (rand() % 2) using namespace std; class Animal { public: void act() { cout << "pant" << endl; } }; class Cat : public Animal { public: void act() { if (COINFLIP()) { cout << "meow" << endl; } else { cout << "purr" << endl; } } }; class Dog : public Animal { public: void act() { if (COINFLIP()) { cout << "bark" << endl; } else { cout << "woof" << endl; } } }; int main(int argc, char const *argv[]) { Cat c; Dog d; Animal *a = nullptr; if (COINFLIP()) { a = new Cat(); } else { a = new Dog(); } c.act(); d.act(); a->act(); return 0; }