< previous page page_270 next page >

Page 270
LISTING 17.2 continued
d5ef64f4d3250b96ba5c07ca5bbc2f56.gif
9:         ~Mammal() { }
10:        virtual void Speak() const { cout << Mammal speak!\n; }
11:    protected:
12:        int itsAge;
13:    };
14:
15:    class Dog : public Mammal
16:    {
17:    public:
18:        void Speak()const { cout << Woof!\n; }
19:    };
20:
21:
22:    class Cat : public Mammal
23:    {
24:    public:
25:        void Speak()const { cout << Meow!\n; }
26:    };
27:
28:
29:    class Horse : public Mammal
30:    {
31:    public:
32:        void Speak()const { cout << Winnie!\n; }
33:    };
34:
35:    class Pig : public Mammal
36:    {
37:    public:
38:        void Speak()const { cout << Oink!\n; }
39:    };
40:
41:    int main()
42:    {
43:        Mammal* theArray[5];
44:        Mammal* ptr;
45:        int choice, i;
46:        for ( i = 0; i<5; i++)
47:        {
48:          cout << (1)dog (2)cat (3)horse (4)pig: ;
49:          cin >> choice;
50:          switch (choice)
51:          {
52:             case 1: ptr = new Dog;
53:             break;
54:             case 2: ptr = new Cat;
55:             break;
56:             case 3: ptr = new Horse;
d5ef64f4d3250b96ba5c07ca5bbc2f56.gif
continues

 
< previous page page_270 next page >

If you like this book, buy it!