diff --git a/README.md b/README.md index 2cded5b..f46c517 100644 --- a/README.md +++ b/README.md @@ -3,3 +3,9 @@ # Exercices POO ## Ex 1 - Namespace - [namespace.md](https://github.com/tony-maulaz/poo-exercices/blob/main/ex1-namespace.md) + +## Ex 10 - Reference +- [references.md](https://github.com/tony-maulaz/poo-exercices/blob/main/ex10-reference.md) + +## Ex 20 - Stdout +- [stdout.md](https://github.com/tony-maulaz/poo-exercices/blob/main/ex20-stdout.md) \ No newline at end of file diff --git a/reference.md b/ex10-reference.md similarity index 100% rename from reference.md rename to ex10-reference.md diff --git a/ex20-stdout.md b/ex20-stdout.md new file mode 100644 index 0000000..69278a7 --- /dev/null +++ b/ex20-stdout.md @@ -0,0 +1,55 @@ +# Ex 1 +Afficher le texte suivant dans la console. + +```console +Bonjour +Comment allez-vous ? +``` + +# Ex 2 +Écrire un programme qui affiche les valeurs des deux variables. + +Le résultat est affiché avec deux chiffres après la virgule. + +```CPP +double val_d = 12.34; +int cpt = 4; +``` + +L'affichage : +```console +Affichage : +Cpt : 4 / Val : 12.34 +``` + +# Solutions +## Ex 1 +```cpp +#include + +using namespace std; + +int main() +{ + cout<<"Bonjour" << endl << "Comment allez-vous ?"; + return 0; +} +``` + +## Ex 2 +```cpp +#include +#include + +using namespace std; + +int main() +{ + double val_d = 12.34; + int cpt = 4; + + cout << "Affichage" << endl; + cout << "Cpt : " << cpt << " / Val : " << fixed << setprecision(2) << val_d; + return 0; +} +``` \ No newline at end of file diff --git a/ex30-surcharge-fct.md b/ex30-surcharge-fct.md new file mode 100644 index 0000000..fee0cda --- /dev/null +++ b/ex30-surcharge-fct.md @@ -0,0 +1,70 @@ +# Ex 1 + +Écrire une fonction qui permet d'afficher le carré d'un `int` ou d'un `double`. + + +# Ex 2 +Quel est l'affichage du programme suivant ? + +```CPP +#include +#include + +using namespace std; + +void func(int a){ + cout << "Val_2 : " << a << endl; +} + +void func(double a){ + cout << "Val_3 : " << a << endl; +} + +void func1(int a){ + cout << "Val_1 : " << a << endl; + func( (double)a ); +} + +int main() +{ + double val_d = 2.0; + int val_i = 5; + + func(val_d); + + func(val_i); + + func1(val_d); + + return 0; +} +``` + + +# Solutions +## Ex 1 +```CPP +#include +#include + +using namespace std; + +void aff(int a){ + cout << "Res : " << a*a << endl; +} + +void aff(double a){ + cout << "Res : " << a*a << endl; +} + +int main() +{ + double val_d = 2.3; + int val_i = 5; + + aff(val_d); + aff(val_i); + + return 0; +} +``` \ No newline at end of file