PageRenderTime 16ms CodeModel.GetById 2ms app.highlight 10ms 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
 1/* File : example.c */
 2
 3#include "example.h"
 4#include <math.h>
 5#ifndef M_PI
 6#  define M_PI 3.14159265358979323846
 7#endif
 8
 9int Shape::get_nshapes() {
10  return nshapes;
11}
12
13/* Move the shape to a new location */
14void Shape::move(double dx, double dy) {
15  x += dx;
16  y += dy;
17}
18
19int Shape::nshapes = 0;
20
21void Circle::set_radius( double r ) {
22  radius = r;
23}
24
25double Circle::area(void) {
26  return M_PI*radius*radius;
27}
28
29double Circle::perimeter(void) {
30  return 2*M_PI*radius;
31}
32
33double Square::area(void) {
34  return width*width;
35}
36
37double Square::perimeter(void) {
38  return 4*width;
39}
40
41ShapeContainer::~ShapeContainer() {
42  iterator i=shapes.begin();
43  for( iterator i = shapes.begin(); i != shapes.end(); ++i ) {
44    delete *i;
45  }
46}
47
48void
49ShapeContainer::addShape( Shape *s ) {
50  shapes.push_back( s );
51}