///File Complex.cc---not shown in the lecture notes.  By KWR for CSE250.
///Implementation of the two methods declared but not defined in Complex.h.

#include <cmath>    ///no harm including twice...
#include <iostream>
#include "Complex.h"

double Complex::norm() const {
   return sqrt(xx*xx + yy*yy);
}

Complex Complex::operator+(Complex y) const{
   return Complex(xx+y.xx, yy+y.yy);
}

/// Test-code driver file---but whereas every Java class can (and should!)
/// have a method "public static void main(String[] args)" with test code,
/// multiple "main"s floating in "file scope" would clash in C++.

int main() {
   //Complex a,b = Complex(1.0,1.0);  ///does not initialize a!
   Complex a(1.0,1.0);      ///a initialized to 1+i.
   Complex b = a;           ///uses automatic "Complex::operator="
   Complex* cp = new Complex(-2.0,1.0);  ///c is a pointer to i-2
   a = a + b + (*cp);
   cout << "The x-coordinate of the sum is: " << a.getxx() << endl;
}
