// inherit4.cpp By: Aiman Hanna - ©1993-2002 Aiman Hanna // This program fixes the problem that inherit3.cpp has. Verify the difference // between inherit4.h & inherit3.h // Key Points: 1) 'protected' access rights. #include "inherit4.h" // Define the base class Geometric::Geometric( void ) { cout << " Gm...Executing the default constructor of the base class. " << "\n"; top = left = bottom = right = 0; } Geometric::Geometric( int lf , int tp, int bt, int rt ) { cout << " Gm...Executing the 'parameterized' constructor of the base class. " << "\n"; left = lf; top = tp; bottom = bt; right = rt; cout << " Gm...Left is: " << left << " , top: is " << top << " , bottom is: " << bottom << " and right is: " << right << "\n"; } void Geometric::Draw( void ) { cout << " Gm...Function Draw in the base class is executing." << "\n"; cout << " Gm...This function will execute for all the derived classes!" << " unless it is redefined!! " << "\n"; } void Geometric::Erase( void ) { cout << " Gm...Function Erase in the base class is executing." << "\n"; cout << " Gm...This function will execute for all the derived classes!" << " unless it is redefined!! " << "\n"; } void Geometric::Move( void ) { cout << " Gm...Function Erase in the base class is executing." << "\n"; cout << " Gm...This function will execute for all the derived classes!" << " unless it is redefined!! " << "\n"; } // define the TwoDimension class TwoDimension::TwoDimension( void ) { cout << " TD...Executing the default constructor of the TwoDimension class. " << "\n"; fillpattern = 0; } TwoDimension::TwoDimension( int lf, int tp, int bt, int rt, int fill ): Geometric( lf, tp, bt, rt ) { cout << " TD...Executing the 'parameterized' constructor of the" << " TwoDimension class. " << "\n"; fillpattern = fill; cout << " TD...Left is: " << left << " , top: is " << top << " , bottom is: " << bottom << " and right is: " << right << "\n"; } void TwoDimension::Draw( void ) { cout << " TD...Function Draw in the TwoDimension class is executing." << "\n"; cout << " TD...This function redefines the function Draw in the base class" << "\n"; } // define the Rectangle class Rectangle::Rectangle( void ) { cout << " Rec...Executing the default constructor of the Rectangle class. " << "\n"; boardershape = bolddashed; } Rectangle::Rectangle( int lf , int tp, int bt, int rt, int fill ): TwoDimension( lf, tp, bt, rt, fill ) { cout << " Rec...Executing the 'parameterized' constructor of the" << " Rectangle class. " << "\n"; boardershape = bolddashed; cout << " Rec...Left is: " << left << " , top: is " << top << " , bottom is: " << bottom << " and right is: " << right << "\n"; } void Rectangle::SetBoarderShape( boarder brd ) { boardershape = brd; } int main( void ) { Geometric Gm( 2, 5, 8, 10 ); cout << " Gm...Now the draw function of the Geometric class will start. " << "\n"; Gm.Draw( ); cout << "*************************************************\n\n"; TwoDimension TD( 4, 7, 9, 12, 1 ); cout << " TD...Now the draw function of the TwoDimension class will start. " << "\n"; TD.Draw( ); TD.Erase( ); cout << "*************************************************\n\n"; Rectangle Rec( 5, 11, 16, 20, 2 ); cout << " Rec...Now the draw function of the Rectangle class will start. " << "\n"; Rec.Draw( ); Rec.Move( ); cout << "*************************************************\n\n"; return 0; } /// The output progarm: /* Gm...Executing the 'parameterized' constructor of the base class. Gm...Left is: 2 , top: is 5 , bottom is: 8 and right is: 10 Gm...Now the draw function of the Geometric class will start. Gm...Function Draw in the base class is executing. Gm...This function will execute for all the derived classes! unless it is redefined!! ************************************************* Gm...Executing the 'parameterized' constructor of the base class. Gm...Left is: 4 , top: is 7 , bottom is: 9 and right is: 12 TD...Executing the 'parameterized' constructor of the TwoDimension class. TD...Left is: 4 , top: is 7 , bottom is: 9 and right is: 12 TD...Now the draw function of the TwoDimension class will start. TD...Function Draw in the TwoDimension class is executing. TD...This function redefines the function Draw in the base class Gm...Function Erase in the base class is executing. Gm...This function will execute for all the derived classes! unless it is redefined!! ************************************************* Gm...Executing the 'parameterized' constructor of the base class. Gm...Left is: 5 , top: is 11 , bottom is: 16 and right is: 20 TD...Executing the 'parameterized' constructor of the TwoDimension class. TD...Left is: 5 , top: is 11 , bottom is: 16 and right is: 20 Rec...Executing the 'parameterized' constructor of the Rectangle class. Rec...Left is: 5 , top: is 11 , bottom is: 16 and right is: 20 Rec...Now the draw function of the Rectangle class will start. TD...Function Draw in the TwoDimension class is executing. TD...This function redefines the function Draw in the base class Gm...Function Erase in the base class is executing. Gm...This function will execute for all the derived classes! unless it is redefined!! ************************************************* */