GeometricObject.h
#ifndef GEOMETRICOBJECT_H
#define GEOMETRICOBJECT_H
#include <string>
using namespace std;
class GeometricObject
{
public:
GeometricObject();
GeometricObject(string color, bool filled);
string getColor();
void setColor(string color);
bool isFilled();
void setFilled(bool filled);
string toString();
private:
string color_;
bool filled_;
}; // Must place semicolon here
#endif
GeometricObject.cpp
#include "GeometricObject.h"
GeometricObject::GeometricObject()
{
color_ = "white";
filled_ = false;
}
GeometricObject::GeometricObject(string color, bool filled)
{
color_ = color;
filled_ = filled;
}
string GeometricObject::getColor()
{
return color_;
}
void GeometricObject::setColor(string color)
{
color_ = color;
}
bool GeometricObject::isFilled()
{
return filled_;
}
void GeometricObject::setFilled(bool filled)
{
filled_ = filled;
}
string GeometricObject::toString()
{
return "Geometric object | color: " + color_ +
" | filled: " + ((filled_) ? "true" : "false");
}
DerivedCircle.h
#ifndef DERIVEDCIRCLE_H
#define DERIVEDCIRCLE_H
#include "GeometricObject.h"
class Circle: public GeometricObject
{
public:
Circle();
Circle(double);
Circle(double radius, string color, bool filled);
double getRadius();
void setRadius(double);
double getArea();
double getPerimeter();
double getDiameter();
private:
double radius_;
}; // Must place semicolon here
#endif
DerivedCircle.cpp
#include "DerivedCircle.h"
// Construct a default circle object
Circle::Circle()
{
radius_ = 1;
}
// Construct a circle object with specified radius
Circle::Circle(double radius)
{
radius_ = radius;
}
// Return the radius of this circle
double Circle::getRadius()
{
return radius_;
}
// Set a new radius
void Circle::setRadius(double radius)
{
radius_ = (radius >= 0) ? radius : 0;
}
// Return the area of this circle
double Circle::getArea()
{
return radius_ * radius_ * 3.14159;
}
// Return the perimeter of this circle
double Circle::getPerimeter()
{
return 2 * radius_ * 3.14159;
}
// Return the diameter of this circle
double Circle::getDiameter()
{
return 2 * radius_;
}
Rectangle.h
#ifndef RECTANGLE_H
#define RECTANGLE_H
#include "GeometricObject.h"
class Rectangle: