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

/trunk/Examples/tcl/operator/example.h

#
C++ Header | 36 lines | 28 code | 7 blank | 1 comment | 0 complexity | 61c61e3db6a1c5379ed98540e5b11d84 MD5 | raw file
 1/* File : example.h */
 2#include <math.h>
 3
 4class Complex {
 5private:
 6  double rpart, ipart;
 7public:
 8  Complex(double r = 0, double i = 0) : rpart(r), ipart(i) { }
 9  Complex(const Complex &c) : rpart(c.rpart), ipart(c.ipart) { }
10  Complex &operator=(const Complex &c) {
11    rpart = c.rpart;
12    ipart = c.ipart;
13    return *this;
14  }
15  Complex operator+(const Complex &c) const {
16    return Complex(rpart+c.rpart, ipart+c.ipart);
17  }
18  Complex operator-(const Complex &c) const {
19    return Complex(rpart-c.rpart, ipart-c.ipart);
20  }
21  Complex operator*(const Complex &c) const {
22    return Complex(rpart*c.rpart - ipart*c.ipart,
23		   rpart*c.ipart + c.rpart*ipart);
24  }
25  Complex operator-() const {
26    return Complex(-rpart, -ipart);
27  }
28  
29  double re() const { return rpart; }
30  double im() const { return ipart; }
31};
32
33
34
35
36