#include "figfamil.h"

//Figure class methods

void Figure::Init()
//Initializes figure with blank Name fields.
{
  strset(Name, ' ');
  Area = 0.0;
  Perimeter = 0.0;
}

void Figure::Display()
//Displays attributes of Figure class instance.
//Pre : All data members are defined.
//Post: The value of each data member has been displayed.
{
  int Equal;

  //Check for blank string as Name value
  Equal = strncmp(Name," ", 1);

  if (!Equal)
    cout << "Figure kind is not defined\n";
  else
  {
    cout << "Figure kind is " << Name << "\n";
    cout << "Area is " << Area << "\n";
    cout << "Perimeter is " << Perimeter << "\n";
  }
}

char *Figure::GetName()
//Returns value of data member Name.
{
  char* FigName = new char[Size + 1];
  strcpy(FigName, Name);
  return(FigName);
}

float Figure::GetArea()
//Returns value data member Area.
{
  return(Area);
}

float Figure::GetPerim()
//Returns value of data member Perimeter.
{
  return(Perimeter);
}

//Rectangle class methods

void Rectangle::Init(float LengthVal, float WidthVal)
//Initializes Rectangle class instance.
//Pre : None.
//Post: Rectangle instance initialized, with data members Name,
//      Length, and Width defined.
{
  strcpy(Name, "Rectangle");
  Length = LengthVal;
  Width = WidthVal;
}

void Rectangle::ComputePerim()
//Computes Perimter for Rectangle object.
//Pre : Object initialized.
//Post: Data member Perimeter defined.
{
  Perimeter = 2 * (Width + Length);
}

void Rectangle::ComputeArea ()
//Computes Area for Rectangle object.
//Pre : Object initialized.
//Post: Data member Area defined.
{
  Area = Length * Width;
}

void Rectangle::Display()
//Displays attributes of Rectangle class instance.
//Pre : All data members are defined.
//Post: The value of each data member has been displayed.
{
  Figure::Display();
  cout << "Width is "<< Width << "\n";
  cout << "Length is "<< Length << "\n";
}

//Square class methods

void Square::Init(float SideVal)
//Initializes Square class instance.
//Pre : None.
//Post: Square instance initialized, with data members Name,
//      Length, and Width defined.
{
  strcpy(Name, "Square");
  Width = SideVal;
  Length = SideVal;
}

void Square::Display()
//Displays attributes of Square class instance.
//Pre : All data members are defined.
//Post: The value of each data member has been displayed.
{
  Figure::Display();
  cout << "Side is " << Width << "\n";
}
