PageRenderTime 67ms CodeModel.GetById 56ms app.highlight 6ms RepoModel.GetById 2ms app.codeStats 0ms

/trunk/Examples/pike/class/example.cxx

#
C++ | 46 lines | 26 code | 11 blank | 9 comment | 0 complexity | 5a39920e87bac30ba358e7ea2cc185d7 MD5 | raw file
 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}