/* Fichier Num1C.cpp Sujet du numéro C du TP1 explique+tape en classe Matière de cet exemple : - tableaux - méthodes statics - surcharge de fonction - transmission de résultats via pointeur À adapter + compléter pour le numéro C du TP1, IFT 1166 : 1) compter + afficher le nombre de femmes compter + afficher le nombre d'hommes 2) déterminer puis afficher : a) la taille minimale des hommes b) l'age minimal des femmes 3) déterminer + afficher : a) l'age maximal de tout le monde b) la consommation maximale de café de tout le monde 4) compter + afficher le nombre de femmes qui consomment plus que la consommation moyenne de café de tout le monde Critères de correction du numéro C du TP1 (sur 07 points) : - bon fonctionnement : 4 tâches x 1 point = 4 points - qualité du code : 3 points */ #include #include using namespace std; // pour consulter l'écran d'exécution void continuer() { char reponse ; cout << "\nAppuyez sur une lettre suivie de Entree " ; cin >> reponse ; } void afficher(char sexe[], int nbCafe[], int age[], float taille[], int nbPers, const char message[]) { cout << "Contenu de 4 tableaux " << message << " :\n"; cout << " indice age cafe taille sexe\n"; cout.setf(ios::fixed); cout.setf(ios::showpoint); for(int i = 0 ; i < nbPers; i++) cout << setw(5) << i << ") " << setw(9) << age[i] << setw(7) << nbCafe[i] << setw(10) << setprecision(2) << taille[i] << setw(15) << ( sexe[i] == 'F' ? "feminin":"masculin") << endl; cout << endl << endl; } int nombre(int tableau[], int nbElem, int borne) { int n = 0; for(int i = 0; i < nbElem; i++) if (tableau[i] > borne) n++; return n; } int nombre(float tableau[], int nbElem, float borne) { int n = 0; for(int i = 0; i < nbElem; i++) if (tableau[i] > borne) n++; return n; } void determiner(float taille[], int nbPers, float * ptrMin, float * ptrMax) { float mini = taille[0], maxi = taille[0]; for(int i = 1; i < nbPers; i++) { if (taille[i] < mini) mini = taille[i]; if (taille[i] > maxi) maxi = taille[i]; } *ptrMin = mini; *ptrMax = maxi; } int main() { int age[] = { 25, 19, 41, 37, 20, 37 }, nbCafe[] = { 3, 4, 0, 6, 3, 2 } ; char sexe[] = { 'F', 'M', 'F', 'F', 'M', 'F' }; float taille[] = { 1.72, 1.84, 1.65, 1.57, 1.93, 1.85 }; int nbPers = sizeof(nbCafe) / sizeof(int); afficher(sexe, nbCafe, age, taille, nbPers, "avant le tri"); cout << "Le nb de pers consommant plus de 2 tasses " << nombre(nbCafe, nbPers, 2) << endl; cout << "Le nb de pers ayant age > 26 ans " << nombre(age, nbPers, 26) << endl; cout << "Le nb de pers dont taille > 1.70 metre " << nombre(taille, nbPers, 1.70) << endl; float tailleMax , tailleMin; determiner(taille, nbPers, &tailleMin, &tailleMax); cout << "La taille maximale : " << setw(8) << setprecision(2) << tailleMax << " metre\n"; cout << "La taille minimale : " << setw(8) << setprecision(2) << tailleMin << " metre\n"; continuer(); return 0; } /* Execution : Contenu de 4 tableaux avant le tri : indice age cafe taille sexe 0) 25 3 1.72 feminin 1) 19 4 1.84 masculin 2) 41 0 1.65 feminin 3) 37 6 1.57 feminin 4) 20 3 1.93 masculin 5) 37 2 1.85 feminin Le nb de pers consommant plus de 2 tasses 4 Le nb de pers ayant age > 26 ans 3 Le nb de pers dont taille > 1.70 metre 4 La taille maximale : 1.93 metre La taille minimale : 1.57 metre Appuyez sur une lettre suivie de Entree */