/trunk/Examples/python/smartptr/example.cxx

# · C++ · 31 lines · 22 code · 7 blank · 2 comment · 0 complexity · ced69823d71d68c9039f00cbb32783be MD5 · raw file

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