2004-04-30 12:17:06 -04:00
|
|
|
/* File : example.c */
|
|
|
|
|
|
|
|
#include "example.h"
|
|
|
|
#define M_PI 3.14159265358979323846
|
|
|
|
|
|
|
|
/* Move the shape to a new location */
|
2016-05-16 10:34:04 -04:00
|
|
|
void Shape::move(double dx, double dy)
|
|
|
|
{
|
2004-04-30 12:17:06 -04:00
|
|
|
x += dx;
|
|
|
|
y += dy;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Shape::nshapes = 0;
|
|
|
|
|
2016-05-16 10:34:04 -04:00
|
|
|
double Circle::area(void)
|
|
|
|
{
|
|
|
|
return M_PI * radius * radius;
|
2004-04-30 12:17:06 -04:00
|
|
|
}
|
|
|
|
|
2016-05-16 10:34:04 -04:00
|
|
|
double Circle::perimeter(void)
|
|
|
|
{
|
|
|
|
return 2 * M_PI * radius;
|
2004-04-30 12:17:06 -04:00
|
|
|
}
|
|
|
|
|
2016-05-16 10:34:04 -04:00
|
|
|
double Square::area(void)
|
|
|
|
{
|
|
|
|
return width * width;
|
2004-04-30 12:17:06 -04:00
|
|
|
}
|
|
|
|
|
2016-05-16 10:34:04 -04:00
|
|
|
double Square::perimeter(void)
|
|
|
|
{
|
|
|
|
return 4 * width;
|
2004-04-30 12:17:06 -04:00
|
|
|
}
|