1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
class Animal { public: Animal() { strcpy(m_animalName, "none"); } virtual void move()=0; //declared by children class protected: char m_animalName[100]; }; // Write classes Bird and Horse // so that the move method shows that a horse run, // and a bird can fly. // You can just use cout to describe it. class Birds : public Animal { public: Birds() { strcpy(m_animalName, "bird"); } void move() { cout << "nA " << m_animalName << " move by FLYING" << endl; } }; class Horse : public Animal { public: Horse() { strcpy(m_animalName, "horse"); } void move() { cout << "nA " << m_animalName << " move by RUNNING" << endl; } }; #import "Horse.h" #import "Birds.h" void showHowAnimalsMove(Animal ** arrayOfPtrs) { Animal ** tmp = arrayOfPtrs; while(*tmp!=NULL) { (*tmp)->move(); tmp++; } } int main() { Horse * horse1 = new Horse(); Birds * bird1 = new Birds(); Animal * animals[10] = {}; //nulls out everyone animals[0] = horse1; animals[1] = bird1; showHowAnimalsMove(animals); } |