This file provides a simple set of Shape classes. */
\author Bob
*/
class Shape {
public:
Shape() {
nshapes++;
}
virtual ~Shape() {
nshapes--;
}
double x;
double y;
void move(double dx, double dy);
\param dx x co-ordinate
\param dy y co-ordinate */
virtual double area() = 0;
virtual double perimeter() = 0;
static int nshapes;
};
\author Jack
*/
class Circle : public Shape {
private:
double radius;
public:
* \param r radius of the circle */
Circle(double r);
* \return calculated area */
virtual double area();
* \return calculated perimeter of the circle */
virtual double perimeter();
};
class Square : public Shape {
private:
double width;
public:
* \param w width of the square */
Square(double w);
* \return calculated area */
virtual double area();
* \return calculated perimeter of the square */
virtual double perimeter();
};
template<typename T>
class Rectangle : public Shape {
private:
T height;
T width;
public:
* \param h height of the rectangle
* \param w width of the rectangle */
Rectangle(T h, T w) : height(h), width(w) {}
* \return calculated area */
virtual double area() { return width*height; }
* \return calculated perimeter of the rectangle */
virtual double perimeter() { return 2*height + 2*width; }
};
* \param r width of the square
* \return a fully constructed square */
Square MakeSquare(double r);
* \param w radius of the circle
* \return a fully constructed circle */
Circle MakeCircle(double w);
* \param h height of the rectangle
* \param w width of the rectangle
* \return a fully constructed rectangle */
template<typename T>
Rectangle<T> MakeRectangle(T h, T w) {
return Rectangle<T>(h, w);
}
extern int NumCircles;
extern int NumSquares;