#include <iostream>
#include <math.h>
#include <ctime>
#include <cstdlib>
using namespace std;
class NbComplexe {
public:
double re,im;
void saisir (){
cin >> re >> im;
}
void afficher (){
cout << re;
if (im>=0){
cout << '+' << im << "i" << endl;
}
else {
cout << im << "i" << endl;
}
}
NbComplexe (){
re=0.0;
im=0.0;
}
NbComplexe (double r,double m){
re=r;
im=m;
}
NbComplexe (const NbComplexe & c){
re= c.re;
im=c.im;
}
~NbComplexe(){ }
void multiplier (const NbComplexe & c){
re= re * c.re - im * c.im ;
im= im * c.re + c.im * re;
}
double module ()const {
return sqrt(pow(re,2)+pow(im,2));
}
bool estPlusPetit (const NbComplexe & c ){
return (*this).module()<c.module();
}
};
void trierParSelection (NbComplexe tab[],int taille){
for (int i=0; i<taille-1;i++){
int indice = i;
NbComplexe min;
for (int j=i+1;j<taille;j++){
if (tab[j].module()<tab[indice].module()){
indice=j;
}
}
min=tab[indice];
tab[indice]=tab[i];
tab[i]=min;
}
}
void trierParInsertion (NbComplexe tab[],int taille){
for (int i=1;i<taille;i++){
int j=i-1;
NbComplexe e=tab[i];
while(j>=0 && tab[j].module()>e.module()){
tab[j+1]=tab[j];
j-=1;
}
tab[j+1]=e;
}
}
int main() {
srand((unsigned int) time(NULL));
NbComplexe c;
c.saisir ();
c.afficher();
NbComplexe x (c);
NbComplexe * v=new NbComplexe (2,3);
x.multiplier(*v);
x.afficher();
int taille ;
cin >> taille;
NbComplexe * b= new NbComplexe [taille];
for (int i=0; i< taille ; i++){
b[i].re=((rand()%201)/10.0)-10.0;
b[i].im=((rand()%201)/10.0)-10.0;
b[i].afficher();
cout << b[i].module() << endl;
}
trierParInsertion(b,taille);
for (int i=0; i< taille ; i++){
b[i].afficher();
}
delete v;
delete [] b;
return 0;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: