Cours:PooTD1 qtcreatorCorrection

De troyesGEII
Aller à : navigation, rechercher


#include <iostream>
#include <math.h>

using namespace std;

class Complexe
{
public :
    double re;
    double im;

    Complexe(double r, double i)
    {
        re = r;
        im = i;
    }

    Complexe()
    {
        re = 0;
        im = 0;
    }

    void affiche()
    {
        cout << re;
        if (im >=0)
        {
             cout << "+";
        }
        cout << im << ".i"  <<endl;
     }

};


int main()
{
    Complexe z1(1,1);
    double mod;
    mod=z1.module();
    cout <<"||z1||="<<mod<<endl;
    Complexe z2;
    Complexe z3(-4,5);
    z3.affiche();
    z3.conjugue();
    z3.affiche();
    Complexe zr;
    zr=z3.add(z2);
    return 0;
}