Sams Teach Yourself C++ in 21 Days

(singke) #1

458 Day 14


48: {
49: cout << “\n(1)Horse (2)Pegasus: “;
50: cin >> choice;
51: if (choice == 2)
52: pHorse = new Pegasus;
53: else
54: pHorse = new Horse;
55: Ranch[i] = pHorse;
56: }
57: for (i=0; i<MagicNumber; i++)
58: {
59: cout << “\n(1)Bird (2)Pegasus: “;
60: cin >> choice;
61: if (choice == 2)
62: pBird = new Pegasus;
63: else
64: pBird = new Bird;
65: Aviary[i] = pBird;
66: }
67:
68: cout << endl;
69: for (i=0; i<MagicNumber; i++)
70: {
71: cout << “\nRanch[“ << i << “]: “ ;
72: Ranch[i]->Whinny();
73: delete Ranch[i];
74: }
75:
76: for (i=0; i<MagicNumber; i++)
77: {
78: cout << “\nAviary[“ << i << “]: “ ;
79: Aviary[i]->Chirp();
80: Aviary[i]->Fly();
81: delete Aviary[i];
82: }
83: return 0;
84: }

(1)Horse (2)Pegasus: 1
Horse constructor...
(1)Horse (2)Pegasus: 2
Horse constructor... Bird constructor... Pegasus constructor...
(1)Bird (2)Pegasus: 1
Bird constructor...
(1)Bird (2)Pegasus: 2
Horse constructor... Bird constructor... Pegasus constructor...

OUTPUT


LISTING14.3 continued
Free download pdf