Class to store and convert complex numbers

Struggling to create a class to store and convert complex numbers...
i am getting an error which says member function already defined or declared, and i am unsure how to fix it.

#include <iostream>
#include <cmath>
#include <string>

using namespace std;

class Complex
{
private:
double real, imag;
double mag, ang;
bool rectangular, polar;

void calculateRectangular ();
void calculatePolar ();

public:
Complex () {rectangular = false; polar = false;}
Complex (double r, double i)
{
real = r;
imag = i;
rectangular = true;
polar = false;
}
Complex (double m, double a) //WHERE ERROR OCCURS
{
mag = m;
ang = a;
rectangular = false;
polar = true;
}

void printRectangular ();
void printPolar ();

double getReal ();
double getImag ();
double getMag ();
double getAng ();

void setRectangular (double r, double i);
void setPolar (double m, double a);

};

int main(){

Complex num1;

return 0;
}


double Complex::getReal ()
{
if (rectangular == false) calculateRectangular ();
return real;
}

double Complex::getImag ()
{
if (rectangular == false) calculateRectangular ();
return imag;
}

void Complex::calculateRectangular ()
{
real = mag * cos (ang);
imag = mag *sin (ang);
rectangular = true;
}

double Complex::getMag ()
{
if (polar == false) calculatePolar ();
return mag;
}

double Complex::getAng ()
{
if (polar == false) calculatePolar ();
return ang;
}

void Complex::calculatePolar()
{
mag = sqrt( pow(real, 2)+(pow(imag, 2)) );
ang = atan( imag/real );
polar = true;
}

void Complex::printRectangular ()
{
cout << "r" << " " << getReal() << " " << getImag() << endl;
}

void Complex::printPolar ()
{
cout << "p" << " " <<getMag() << " " << getAng() << endl;
}

Line 19, 26: You have identical constructors.

PLEASE USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.


Topic archived. No new replies allowed.