/trunk/Examples/contract/simple_cxx/example.cxx

# · C++ · 30 lines · 21 code · 7 blank · 2 comment · 2 complexity · 7eb75f4b525bcbf3d56f16b6bc7a72ec MD5 · raw file

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