PageRenderTime 40ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/Examples/php/disown/example.cxx

#
C++ | 51 lines | 38 code | 11 blank | 2 comment | 2 complexity | 545b8d08b5edaa5df806449c7fd65bc4 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 <math.h>
  4. #ifndef M_PI
  5. # define M_PI 3.14159265358979323846
  6. #endif
  7. int Shape::get_nshapes() {
  8. return nshapes;
  9. }
  10. /* Move the shape to a new location */
  11. void Shape::move(double dx, double dy) {
  12. x += dx;
  13. y += dy;
  14. }
  15. int Shape::nshapes = 0;
  16. void Circle::set_radius( double r ) {
  17. radius = r;
  18. }
  19. double Circle::area(void) {
  20. return M_PI*radius*radius;
  21. }
  22. double Circle::perimeter(void) {
  23. return 2*M_PI*radius;
  24. }
  25. double Square::area(void) {
  26. return width*width;
  27. }
  28. double Square::perimeter(void) {
  29. return 4*width;
  30. }
  31. ShapeContainer::~ShapeContainer() {
  32. iterator i=shapes.begin();
  33. for( iterator i = shapes.begin(); i != shapes.end(); ++i ) {
  34. delete *i;
  35. }
  36. }
  37. void
  38. ShapeContainer::addShape( Shape *s ) {
  39. shapes.push_back( s );
  40. }