PageRenderTime 50ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/Examples/pike/class/example.cxx

#
C++ | 46 lines | 26 code | 11 blank | 9 comment | 0 complexity | 5a39920e87bac30ba358e7ea2cc185d7 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. /* File : example.c */
  2. #include "example.h"
  3. #include <stdio.h>
  4. #define M_PI 3.14159265358979323846
  5. // Static member initializer
  6. int Shape::nshapes = 0;
  7. // Constructor
  8. Shape::Shape() {
  9. nshapes++;
  10. }
  11. // Move the shape to a new location
  12. void Shape::move(double dx, double dy) {
  13. x += dx;
  14. y += dy;
  15. }
  16. // Destructor
  17. Shape::~Shape() {
  18. nshapes--;
  19. }
  20. // Circle area
  21. double Circle::area() const {
  22. return M_PI*radius*radius;
  23. }
  24. // Circle perimeter
  25. double Circle::perimeter() const {
  26. return 2*M_PI*radius;
  27. }
  28. // Square area
  29. double Square::area() const {
  30. return width*width;
  31. }
  32. // Square perimeter
  33. double Square::perimeter() const {
  34. return 4*width;
  35. }