Yurttas/PL/OOL/Cplusplus/F/03/02/04/01/complex.cpp

From ZCubes Wiki
Jump to navigation Jump to search
 1/*
 2   Copyright(C) 1998
 3   All Rights Reserved. Salih Yurttas, ZCubes, BitsOfCode Software Systems, Inc..
 4
 5   Permission to use, copy, modify, and distribute this
 6   software and its documentation for EDUCATIONAL purposes
 7   and without fee is hereby granted provided that this
 8   copyright notice appears in all copies.
 9
10   date   : January 1, 1998.
11   author : Salih Yurttas.
12
13   complex.cpp
14*/
15
16
17#include "complex.h"
18
19complex::
20complex(const double r,
21        const double i) : re(r),
22                          im(i) {
23}
24
25complex::
26complex(const complex& c) : re(c.re),
27                            im(c.im) {
28}
29
30complex&
31complex::
32operator=(const complex& a) {
33  re = a.re;
34  im = a.im;
35
36  return *this;
37}
38
39complex&
40complex::
41operator+=(const complex& a) {
42  re += a.re;
43  im += a.im;
44
45  return *this;
46}
47
48complex
49operator+(const complex& a,
50          const complex& b) {
51  return complex(a.re + b.re,
52                 a.im + b.im);
53}
54
55ostream&
56operator<<(ostream& os,
57           const complex& c) {
58  os << c.re << endl;
59  os << c.im << endl;
60
61  return os;
62}