PageRenderTime 36ms CodeModel.GetById 26ms app.highlight 6ms RepoModel.GetById 2ms app.codeStats 0ms

/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
 3#define M_PI 3.14159265358979323846
 4
 5/* Move the shape to a new location */
 6void Shape::move(double dx, double dy) {
 7  x += dx;
 8  y += dy;
 9}
10
11int Shape::nshapes = 0;
12
13double Circle::area(void) {
14  /* return -1 is to test post-assertion */
15  if (radius == 1)
16    return -1;
17  return M_PI*radius*radius;
18}
19
20double Circle::perimeter(void) {
21  return 2*M_PI*radius;
22}
23
24double Square::area(void) {
25  return width*width;
26}
27
28double Square::perimeter(void) {
29  return 4*width;
30}