PageRenderTime 24ms CodeModel.GetById 19ms app.highlight 4ms RepoModel.GetById 0ms app.codeStats 0ms

/tags/rel-1.3.35/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
 3#include "example.h"
 4
 5#include <stdio.h>
 6
 7#define M_PI 3.14159265358979323846
 8
 9// Static member initializer
10int Shape::nshapes = 0;
11
12// Constructor
13Shape::Shape() {
14  nshapes++;
15}
16
17// Move the shape to a new location
18void Shape::move(double dx, double dy) {
19  x += dx;
20  y += dy;
21}
22
23// Destructor
24Shape::~Shape() {
25  nshapes--;
26}
27
28// Circle area
29double Circle::area() const {
30  return M_PI*radius*radius;
31}
32
33// Circle perimeter
34double Circle::perimeter() const {
35  return 2*M_PI*radius;
36}
37
38// Square area
39double Square::area() const {
40  return width*width;
41}
42
43// Square perimeter
44double Square::perimeter() const {
45  return 4*width;
46}