//
//  The member functions for the class hierarchy defined in
//  figure.h. 
//


#include <iostream>
#include "figure.h"

const float PI = 3.14159265f;


///////////////////////////////////////////////////////
/////////   "Rectangle" Member Functions   ////////////
///////////////////////////////////////////////////////

Rectangle::Rectangle( float height_in, float width_in ) 
{
	height = height_in;
	width = width_in;
}

float 
Rectangle::Area( )
{
	return height*width;
}

void
Rectangle::Output_Info( )
{
	std::cout << "Rectangle:   height " << height
		  << "  width " << width << std::endl;
}


////////////////////////////////////////////////////
/////////   "Square" Member Functions   ////////////
////////////////////////////////////////////////////

Square::Square( float side ) : Rectangle( side, side )
{
}

void
Square::Output_Info( )
{
	std::cout << "Square:  side " << width << std::endl;
}


///////////////////////////////////////////////////////
///////////   "Circle" Member Functions   /////////////
///////////////////////////////////////////////////////

Circle::Circle( float radius_in ) 
{
	radius = radius_in;
}

void
Circle::Output_Info( )
{
	std::cout << "Circle:   radius " <<  std::endl;
}

float 
Circle::Area( )
{
	return PI * radius * radius; 
}



//////////////////////////////////////////////////////
///////////   "Cylinder" Member Functions   ///////////
///////////////////////////////////////////////////////

Cylinder::Cylinder( float radius_in, float height_in) 
	: height(height_in), base(radius_in)
{
}

// Note that several functions here needed direct access to the radius
// of the base circle.  Hence, a member function was added to the 
// circle class object.  Several alternatives were possible.  One was
// to make Cylinder a friend of Circle.  Another was to add a perimeter 
// calculation function to Circle.

void
Cylinder::Output_Info( )
{
	std::cout << "Cylinder:  height " << height 
			  << ", base circle radius " << base.GetRadius()
			  << std::endl;
}

//  Note the use of the Area member function from circle.  Also,
//  this function needs access to the r
//
float 
Cylinder::Area( )
{
	return PI * 2 * base.GetRadius() * height + 2 * base.Area();
}

//  Note the use of the Area member function from circle.
//
float 
Cylinder::Volume( )
{
	return height * base.Area();
}

///////////////////////////////////////////////////////
///////////   "Sphere" Member Functions   /////////////
///////////////////////////////////////////////////////

Sphere::Sphere( float radius_in ) : radius(radius_in)
{ } 

float 
Sphere::Area( )
{
	return 4 * PI * radius * radius;
}

float 
Sphere::Volume( )
{
	return 4.0 / 3.0 * PI * radius * radius * radius;
}

void
Sphere::Output_Info( )
{
	std::cout << "Sphere:   radius " << radius << std::endl;
}

  
