/*********************************************************************/

 

// File: figuresTest.cpp

 

// main() :Main program to illustrate the use of figure class

 

/********************************************************************/

 

 

#include <iostream>

 

using namespace std;

 

 

#include "figure.h"

 

#include "circle.h"

 

#include "square.h"

 

#include "rectangle.h"

 

 

#include <vector>

 

// Functions called  . . .

 

// Get the type of figure

 

figure* getFigure( );                  // create and return a pointer to a figure object

 

 

 

// Process one figure

 

void processFigure (figure * ptrFigure);    // fig:  figure to be processed

 

 

 

int main ( )

{

     vector <figure*> figureVector;

 

     bool isInservice = true;

 

     while (isInservice)

     {

          figure* myFig;      // a pointer to a figure

          cout << endl

               << "*************************************" << endl

               << " a: Add one figure " << endl

               << " d: display all figures " << endl

               << "*************************************" << endl;

          char option;

          cin >> option;

 

          if (option == 'a' )

          {

              myFig = getFigure ( );

              processFigure (myFig) ;

              figureVector.push_back(myFig);

          }

          else if (option == 'd' )

          {

              for (int i=0; i < figureVector.size(); i++)

              {

                   cout << "*************************************" << endl;

                   figureVector[i]->displayFig() ;

              }

              cout << "*************************************" << endl;

 

 

          }

          else

              cout << "??? Unkown option " << endl;

 

     }

 

     return 0 ;

 

}

 

 

 

/*********************************************************************/

 

// Also in File: figuresTest.cpp

 

// void processFigure(figures fig): Process one figure

 

/********************************************************************/

 

void processFigure(figure * fig)  // fig: The figure to be processed

{

 

     cout << "read Figure: " << endl;

     fig->readFigure( );           // get characteristics of figure

 

     cout << "Computer area: " << endl;

     fig->computeArea( );        // compute its area

 

     cout << "Computer perimeter: " << endl;

     fig->computePerim( );        // compute its perimeter

 

     cout << "Display: " << endl;

     fig->displayFig( );                        // display characteristics

 

  }

 

 

 

 

 

/*********************************************************************/

 

// Also in File: figuresTest.cpp

 

// figure* getFigure ( ): Process one figure

 

/********************************************************************/

 

figure* getFigure ( )

 

{

 

     // local data

 

     char figChar;   // character indicating figure type

 

     cout << "Enter the kind. of object" << endl;

 

     cout << "Enter C(Circle), R(Rectangle), or S(Square)" << endl;

 

     cin >> figChar;

 

     switch (figChar)

     {

          case 'C' : case 'c' :

 

              return new circle;

 

          case 'R': case 'r':

 

              return new rectangle;

 

          case 'S': case 's':

 

              return new square;

 

          case 'X' : case 'x' :

 

              return 0;

 

     } // end switch

 

 

}// end getFigure