//----------------------------------------------------------------- // Author: Zhixiang Chen // Class: CSCI/CMPE 2380, Spring 2009 // Lab 6: Virtual methods vs. polymorphism // Date: January 14, 2009 // Comment: The code here is meant to be revised. // //----------------------------------------------------------------- // // This lab exercise is practice virtual methods vs. polymorphism // // Compile and run your program. When everything is fine, // print your .cpp and .h files and turn them to me or the TA. // ***************************************************************** #include < iostream > #include < fstream > #include < string > #include < cstring > #include < cmath > #include < cstdlib > #include < iomanip > #include < vector > #include "lab2380_6_head.h" using namespace std; int main() { /************************************************************ Part One: Watch the output. Try to understand: No virtual methods, no polymorphism. ************************************************************/ One dog; Two cat; Three rat; One * objPtr[3]; //base class pointer objPtr[0]=&dog; //normal binding to a base class object objPtr[1]=&cat; //dynamic binding to a derived class object objPtr[2]=&rat; //dynamic binding to a derived class object for(int i=0; i<3; i++) objPtr[i]->whoami(); //no virtual function, no polymorphism. cout<<" This is the end of Part one." <whoami(); //polymorphism is realized via virtual functions cout<<" This is the end of Part Two." <print() to invoke different definitions of print in MyWrite, YourWrite and TheirWrite. That is, use the same call p->print() to realize different functionalities -- polymorphisam. How to submit this lab? Turn in your code plus the written observations for option 3. *************************************************************************************/ //complete the program return 0; }