#include "StdAfx.h"
#include ".\complexe.h"
#include <stdio.h>


ostream& operator<<(ostream& out,Complexe & z)
{
	out << "(" << z.a << "," << z.b << ")" << endl;
	return out;
}

Complexe Complexe::operator *(double d)
{
	Complexe r(*this);
	r.a=r.a*d;
	r.b=r.b*d;
	return r;
}

Complexe Complexe::operator *(Complexe & a)
{
	Complexe r(*this);
	r.mul(a);
	return r;
}

Complexe Complexe::operator -(Complexe & o)
{
	Complexe resultat(*this);
	resultat.sub(o);
	return resultat;
}

Complexe Complexe::operator +(Complexe & y)
{
	Complexe resultat(*this);	// resultat=x
	resultat.add(y);			// resultat=resultat+y

	return resultat;
}

Complexe::~Complexe()
{
	printf("destruction\n");
	fflush(stdout);
}

Complexe::Complexe(void)
{
	a=b=0;
}

Complexe::Complexe(double a,double b)
{
	this->a=a;	// this pointeur
	this->b=b;
}

Complexe::Complexe(Complexe & c)
{
	a=c.a;
	b=c.b;
}

void Complexe::afficher()
{
	printf("(%f,%f)\t",a,b);
}

void Complexe::add(Complexe & c)
{
	a=a+c.a;
	b=b+c.b;
}

void Complexe::sub(Complexe & c)
{
	a-=c.a;	// a=a-c.a 
	b-=c.b;
}

void Complexe::mul(Complexe & c)
{
	double nouveau_a,nouveau_b;

	nouveau_a=a*c.a-b*c.b;
	nouveau_b=a*c.b+b*c.a;
	
	a=nouveau_a;
	b=nouveau_b;
}