First commit
This commit is contained in:
83
IUT/Info1/TD/Exercices/13.1_complexes/complexes.cpp
Normal file
83
IUT/Info1/TD/Exercices/13.1_complexes/complexes.cpp
Normal file
@@ -0,0 +1,83 @@
|
||||
#include <iostream>
|
||||
#include <math.h>
|
||||
|
||||
#include "complexes.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
struct complexe saisir_complexe() {
|
||||
struct complexe z;
|
||||
|
||||
cout << "Saisir la partie réele" << endl;
|
||||
cin >> z.Re;
|
||||
|
||||
cout << "Saisir la partie imaginaire" << endl;
|
||||
cin >> z.Im;
|
||||
|
||||
return z;
|
||||
}
|
||||
|
||||
void affiche_complexe(struct complexe z) {
|
||||
cout << z.Re << " + (" << z.Im << ")i" << endl;
|
||||
}
|
||||
|
||||
struct complexe conjuge(struct complexe z) {
|
||||
return {z.Re, -z.Im};
|
||||
}
|
||||
|
||||
struct complexe oppose(struct complexe z) {
|
||||
return {-z.Re, -z.Im};
|
||||
}
|
||||
|
||||
struct complexe inverse(struct complexe z) {
|
||||
struct complexe z_inv;
|
||||
if (z.Im == 0) {
|
||||
z_inv.Im = -z.Im/(z.Re*z.Re + z.Im*z.Im);
|
||||
}
|
||||
if (z.Re == 0) {
|
||||
z_inv.Re = z.Re/(z.Re*z.Re + z.Im*z.Im);
|
||||
}
|
||||
|
||||
return z_inv;
|
||||
}
|
||||
|
||||
float module(struct complexe z) {
|
||||
float mod = sqrt(pow(z.Re, 2)+pow(z.Im, 2));
|
||||
return mod;
|
||||
}
|
||||
|
||||
float argument(struct complexe z) {
|
||||
float mod = module(z);
|
||||
float arg_abs;
|
||||
float arg_sign;
|
||||
|
||||
arg_abs = acos(z.Re/mod);
|
||||
arg_sign = asin(z.Im/mod);
|
||||
|
||||
if (arg_sign < 0) {
|
||||
return -arg_abs;
|
||||
}
|
||||
return arg_abs;
|
||||
}
|
||||
|
||||
struct complexe add_complexe(
|
||||
struct complexe z,
|
||||
struct complexe zp
|
||||
) {
|
||||
return {z.Re + zp.Re, z.Im + zp.Im};
|
||||
}
|
||||
|
||||
struct complexe mult_complexe(
|
||||
struct complexe z,
|
||||
struct complexe zp
|
||||
) {
|
||||
return {z.Re * zp.Re - z.Im * zp.Im, z.Re * zp.Im + z.Im * zp.Re};
|
||||
}
|
||||
|
||||
struct complexe div_complexe(
|
||||
struct complexe z,
|
||||
struct complexe zp
|
||||
) {
|
||||
return mult_complexe(z, inverse(zp));
|
||||
}
|
||||
|
||||
33
IUT/Info1/TD/Exercices/13.1_complexes/complexes.h
Normal file
33
IUT/Info1/TD/Exercices/13.1_complexes/complexes.h
Normal file
@@ -0,0 +1,33 @@
|
||||
struct complexe {
|
||||
float Re;
|
||||
float Im;
|
||||
};
|
||||
|
||||
struct complexe saisir_complexe();
|
||||
|
||||
void affiche_complexe(struct complexe);
|
||||
|
||||
struct complexe conjuge(struct complexe);
|
||||
|
||||
struct complexe oppose(struct complexe);
|
||||
|
||||
struct complexe inverse(struct complexe);
|
||||
|
||||
float module(struct complexe);
|
||||
|
||||
float argument(struct complexe);
|
||||
|
||||
struct complexe add_complexe(
|
||||
struct complexe,
|
||||
struct complexe
|
||||
);
|
||||
|
||||
struct complexe mult_complexe(
|
||||
struct complexe,
|
||||
struct complexe
|
||||
);
|
||||
|
||||
struct complexe div_complexe(
|
||||
struct complexe,
|
||||
struct complexe
|
||||
);
|
||||
32
IUT/Info1/TD/Exercices/13.1_complexes/main.cpp
Normal file
32
IUT/Info1/TD/Exercices/13.1_complexes/main.cpp
Normal file
@@ -0,0 +1,32 @@
|
||||
#include <iostream>
|
||||
|
||||
#include "complexes.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main() {
|
||||
struct complexe _ = saisir_complexe();
|
||||
|
||||
struct complexe z = {5, 7};
|
||||
struct complexe zp = {1, 2};
|
||||
|
||||
affiche_complexe(z);
|
||||
|
||||
affiche_complexe(conjuge(z));
|
||||
|
||||
affiche_complexe(oppose(z));
|
||||
|
||||
affiche_complexe(inverse(z));
|
||||
|
||||
cout << module(z) << endl;
|
||||
|
||||
cout << argument(z) << endl;
|
||||
|
||||
affiche_complexe(add_complexe(z, zp));
|
||||
|
||||
affiche_complexe(mult_complexe(z, zp));
|
||||
|
||||
affiche_complexe(div_complexe(z, zp));
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user