example.cxx 450 B

123456789101112131415161718192021222324252627282930313233
  1. /* File : example.c */
  2. #include "example.h"
  3. #define M_PI 3.14159265358979323846
  4. /* Move the shape to a new location */
  5. void Shape::move(double dx, double dy)
  6. {
  7. x += dx;
  8. y += dy;
  9. }
  10. int Shape::nshapes = 0;
  11. double Circle::area(void)
  12. {
  13. return M_PI * radius * radius;
  14. }
  15. double Circle::perimeter(void)
  16. {
  17. return 2 * M_PI * radius;
  18. }
  19. double Square::area(void)
  20. {
  21. return width * width;
  22. }
  23. double Square::perimeter(void)
  24. {
  25. return 4 * width;
  26. }