TP – 05 (C#) Le Projet : " Calcul de L’IMC"
1) L’interface graphique
1 7
2 8
9
3
4
5
6
2) Les contrôles
Contrôle Type Name Contrôle Type Name
1 --- 7 Nud_taille
NumericUpDown
2 --- 8 Nud_poids
3 Lbl_imc 9 Button ---
Label
4 Lbl_cat
5 Lbl_mois
6 Lbl_imc_ar
3) Les remarques :
IMC Catégorie
IMC = poids / taille2 (m)
? < 18,5 Insuffisance
18,5 <= ? < 25 Normal IMC (arondi) = IMC (sans virgule)
25 <= ? < 30 Surpoids Poids (après 30 jours) : chaque jour -0,1 Kg
30 <= ? Obésité
1 // voici le code du bouton calculer
2
3 // INPUTS : Entrées
4 double tailleCm = (double)Nud_taille.Value;
5 double poids = (double)(Nud_poids.Value);
6
7 // ===== 1. VARIABLES =====
8 double tailleM = tailleCm / 100.0;
9 double imc = poids / (tailleM * tailleM);
10
11 // 1.4 calcul/affichage d'IMC
12 Lbl_imc.Text = "IMC : " + [Link]("0.00");
13
14 // ===== 4. CONVERSION =====
15 int imcArrondi = (int)imc;
16 Lbl_imc_ar.Text = $"IMC (arrondi) : {imcArrondi}";
17 // Autre écriture possible : Lbl_imc_ar.Text = "IMC (arrondi) :" + imcArrondi;
18
19 // ===== 2. CONDITIONS =====
20 if (imc < 18.5)
21 Lbl_cat.Text = "Catégorie : Insuffisance";
22 else if (imc < 25)
23 Lbl_cat.Text = "Catégorie : Normal";
24 else if (imc < 30)
25 Lbl_cat.Text = "Catégorie : Surpoids";
26 else
27 Lbl_cat.Text = "Catégorie : Obésité";
28
29 // ===== 3. BOUCLE FOR =====
30 double poidsTemp = poids;
31
32 for (int jour = 1; jour <= 30; jour++)
33 {
34 poidsTemp -= 0.1;
35 }
36 Lbl_mois.Text = "Poids (après 30 jours : " + [Link]("0.00") + " kg)";