Skip to content

Commit

Permalink
Add exercices
Browse files Browse the repository at this point in the history
  • Loading branch information
tony-maulaz committed Feb 7, 2022
1 parent 3421c6f commit cb7c4d2
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 0 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
File renamed without changes.
55 changes: 55 additions & 0 deletions ex20-stdout.md
Original file line number Diff line number Diff line change
@@ -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 <iostream>

using namespace std;

int main()
{
cout<<"Bonjour" << endl << "Comment allez-vous ?";
return 0;
}
```

## Ex 2
```cpp
#include <iostream>
#include <iomanip>

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;
}
```
70 changes: 70 additions & 0 deletions ex30-surcharge-fct.md
Original file line number Diff line number Diff line change
@@ -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 <iostream>
#include <iomanip>

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 <iostream>
#include <iomanip>
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;
}
```

0 comments on commit cb7c4d2

Please sign in to comment.