complex

complex - } ostream&...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
/** @file complex.cpp @author William Duncan @date 2005-10-01 Description: implementation for the complex class Course: CS1254.02 Logon ID: cs1254xx Lab #: 2 Instructor: William Duncan */ #include <cmath> #include <cstdlib> #include "complex.h" /* SOME FUNCTION HAVE BEEN IMPLEMENTED FOR YOU. IMPLEMENT ALL OTHER FUNCTIONS DESCRIBED ON THE LAB HANDOUT. */ Complex::Complex() { real = 0.0; imag = 0.0; } double Complex::getReal() const { return real; } Complex Complex::conjugate() const { Complex z; z.real = real; z.imag = -imag; return z; } { return Complex(z1.getReal()+z2.getReal(),z1.getImag()+z2.getImag());
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: } ostream&amp; operator&lt;&lt;(ostream&amp; out, const Complex&amp; z) { if (z.getReal() == 0 &amp;&amp; z.getImag() == 0) { cout&lt;&lt;&quot;0&quot;; return out; } if (z.getReal() == 0) { if (z.getImag() &lt; 0) { if (z.getImag() != -1) cout&lt;&lt;z.getImag()&lt;&lt;&quot;i&quot;; else cout&lt;&lt;&quot;-i&quot;; } else { if (z.getImag() != 1) cout&lt;&lt;z.getImag()&lt;&lt;&quot;i&quot;; else cout&lt;&lt;&quot;i&quot;; } return out; } if (z.getImag() == 0) { cout&lt;&lt;z.getReal(); return out; } cout &lt;&lt;z.getReal(); if (z.getImag() &lt; 0) { if (z.getImag() != -1) cout&lt;&lt;z.getImag()&lt;&lt;&quot;i&quot;; else cout&lt;&lt;&quot;-i&quot;; } else { if (z.getImag() != 1) cout&lt;&lt;&quot;+&quot;&lt;&lt;z.getImag()&lt;&lt;&quot;i&quot;; else cout&lt;&lt;&quot;+i&quot;; } return out; }...
View Full Document

This note was uploaded on 01/17/2012 for the course CSC 1254 taught by Professor Blanks,l during the Fall '08 term at LSU.

Page1 / 2

complex - } ostream&amp;amp;amp;...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online