Inherit - public: Cat() BEGIN cout << "Cat...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
Sheet1 Page 1 // Inherit1.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include <iostream> using namespace std #define BEGIN { #define END } class Mammal BEGIN public: Mammal():itsAge(1) BEGIN cout << "Mammal constructor. ..\n" END virtual ~Mammal() BEGIN cout << "Mammal destructor. ..\n" END virtual void Speak() const BEGIN cout << "Mammal speak!\n" END virtual Mammal* Clone() BEGIN return new Mammal(*this) END int GetAge()const BEGIN return itsAge END protected: int itsAge END // end of Mammal class cout << "Mammal Copy Constructor. ..\n" END class Dog : public Mammal BEGIN public: Dog() BEGIN cout << "Dog constructor. ..\n" END virtual ~Dog() BEGIN cout << "Dog destructor. ..\n" END void Speak()const BEGIN cout << "Woof!\n" END virtual Mammal* Clone() BEGIN return new Dog(*this) END
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Sheet1 Page 2 END BEGIN cout << "Dog copy constructor. ..\n" END class Cat : public Mammal BEGIN
Background image of page 2
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 4
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 6
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: public: Cat() BEGIN cout << "Cat constructor. ..\n" END ~Cat() BEGIN cout << "Cat destructor. ..\n" END Cat (const Cat &) void Speak()const BEGIN cout << "Meow!\n" END virtual Mammal* Clone() BEGIN return new Cat(*this) END END Cat::Cat(const Cat & rhs): Mammal(rhs) BEGIN cout << "Cat copy constructor. ..\n" END enum ANIMALS {MAMMAL, DOG, CAT} const int NumAnimalTypes = 3 int _tmain(int argc, _TCHAR* argv)BEGIN Mammal *theArray[NumAnimalTypes] Mammal* ptr int choice, i for ( i = 0 i<NumAnimalTypes cout << "(1)dog (2)cat (3)Mammal: " cin >> choice switch (choice)BEGIN case DOG: ptr = new Dog break case CAT: ptr = new Cat break default: ptr = new Mammal break END theArray[i] = ptr END Mammal *OtherArray[NumAnimalTypes] Sheet1 Page 3 for (i=0 i<NumAnimalTypes theArray[i]->Speak() OtherArray[i] = theArray[i]->Clone() END for (i=0 i<NumAnimalTypes OtherArray[i]->Speak() return 0 END Sheet1 Page 4 Sheet1 Page 5 i++) BEGIN Sheet1 Page 6 i++) BEGIN i++)...
View Full Document

This note was uploaded on 03/19/2008 for the course CSE 122 taught by Professor Yoxheimer,ericch during the Fall '07 term at Pennsylvania State University, University Park.

Page1 / 6

Inherit - public: Cat() BEGIN cout << "Cat...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online