Yurttas/PL/OOL/Cplusplus/F/03/02/04/00/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
40operator+(const Complex& a,
41          const Complex& b) {
42  double re = a.re + b.re;
43  double im = a.im + b.im;
44
45  return Complex(re,im);
46}
47
48ostream&
49operator<<(ostream& os,
50           const Complex& c) {
51  os << c.re << endl;
52  os << c.im << endl;
53
54  return os;
55}