#include #include "Complx.h" /* * Written by Mike Rollins * rollins@alumni.wfu.edu * Copyright 2004. */ // Create a complex number Complx::Complx(float a, float b ) { this->a = a; this->b = b; complx_version = "Complx: Version 1.0"; } // Set the power to which this number // will be raised void Complx::set_power(double p) { this->p = p; } void Complx::raise_to_power() { // atan2 is necessary for the // correct sign of theta double theta = atan2(b,a); double r = sqrt(a*a + b*b); a = (float) (pow(r,p) * cos(p*theta)); b = (float) (pow(r,p) * sin(p*theta)); } void Complx::Set(Complx z) { a = z.get_real(); b = z.get_imaginary(); } void Complx::Add(Complx z) { a = a + z.get_real(); b = b + z.get_imaginary(); } float Complx::get_real() { return a; } float Complx::get_imaginary() { return b; } void Complx::Print() { printf("%f + %f i\n",(float)a,(float)b); }