#include <iostream>
#include <cmath>
#include <cstdlib>
using namespace std;


// This class is simply a Struct having two member values
class Complex1
{
 public:
    double real;
    double imaginary;


    // But we can also add some new functionalities
    double module(){
	return sqrt(real*real+imaginary*imaginary);
    }

    double argument(){
	return 0;
    }

};


class Complex2
{
public:
    // But we can also add some new functionalities
    double module(){
	return sqrt(real*real+imaginary*imaginary);
    }

    double argument(){
	return 0;
    }

private:
    double real;
    double imaginary;



};

// This function does not change anything in the original value
void eraseRealPartCopy(Complex1 c){
    c.real = 0;
}


// This function erases the real part of original value
void eraseRealPartReference(Complex1& c){
    c.real = 0;
}



int main(int argc,char *argv[])
{
   cout << "First Test with a complex type" << endl;

   // a class is like a struct, it can contain some information

   Complex1 c1;
   c1.real = 10;
   c1.imaginary = 20;

   cout << "print content of real part " << c1.real; 
   cout << " imaginary part " << c1.imaginary << endl;

   // But the main difference is that an object can execute functions
   cout << "Module of C1 is " << c1.module() << endl;
   cout << "and its argument is " << c1.argument() << endl;



   Complex2 c2;
   // Illegal since real and imaginary are private members
   // c2.real = 10;
   // c2.imaginary = 20;

   // cout << "print content of real part " << c2.real; 
   // cout << " imaginary part " << c2.imaginary << endl;

   // Legal, since the two methods are public
   // Result is totaly random since the value has not been initialized!
   cout << "Module of C2 is " << c2.module() << endl;
   cout << "and its argument is " << c2.argument() << endl;



   // We create a new variable c and try to erase its real part

   Complex1 c3;
   c3.real = 10;
   c3.imaginary = 20;

   // The first function does not change anything
   eraseRealPartCopy(c3);
   cout << "Value of real part of c3 is the same :" << c3.real << endl;

   // The second function changes the real value
   eraseRealPartReference(c3);
   cout << "Value of real part of c3 has been changed :" << c3.real << endl;
   
   Complex1* pointeurC1;
   
   pointeurC1 = &c3;
   cout << "Value of pointeurC1 is the same as c3 :" << pointeurC1->real << endl;
   pointeurC1 = new Complex1();
   pointeurC1->real = 5;
   pointeurC1->imaginary = 10;
   cout << "Value of pointeurC1 is:" << pointeurC1->real << endl;


   return 1;

}

