A
This commit is contained in:
0
DEV1.1/TP31/TP31_reponses.txt
Normal file
0
DEV1.1/TP31/TP31_reponses.txt
Normal file
61
DEV1.1/TP31/test.c
Normal file
61
DEV1.1/TP31/test.c
Normal file
@@ -0,0 +1,61 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
enum wedge {
|
||||
PITCHING = 1,
|
||||
GAP = 2,
|
||||
SAND = 3,
|
||||
LOP = 4,
|
||||
FLIP = 5
|
||||
};
|
||||
|
||||
enum putter {
|
||||
REGULAR = 1,
|
||||
BELLY = 2,
|
||||
LONG = 3
|
||||
};
|
||||
|
||||
|
||||
typedef struct {
|
||||
char* marque;
|
||||
char* modele;
|
||||
char* categorie;
|
||||
unsigned int sous_categorie : 4;
|
||||
} club;
|
||||
|
||||
void affiche_catalogue(int taille_catalogue, club* catalogue) {
|
||||
int i;
|
||||
char* wedge[5] = {"Pitching", "Gap", "Sand", "Lop", "Flip"};
|
||||
char* putter[3] = {"Regular", "Belly", "Long"};
|
||||
printf("| Marque | Modèle | Catégorie | Sous-catégorie |\n");
|
||||
printf("------------------------------------------------\n");
|
||||
for (i = 0; i != taille_catalogue; i++) {
|
||||
printf("| %6s | %6s | %9s | %14d |\n", catalogue[i].marque, catalogue[i].modele, catalogue[i].categorie, catalogue[i].sous_categorie);
|
||||
}
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
int i;
|
||||
club catalogue[10];
|
||||
char* marques[4] = {"A", "B", "C", "D"};
|
||||
char* modeles[4] = {"M", "N", "O", "P"};
|
||||
char* categories[4] = {"Bois", "Fer", "Wedge", "Putter"};
|
||||
srand(time(NULL));
|
||||
for(i = 0; i != 10; i++) {
|
||||
catalogue[i].marque = marques[rand() % 4];
|
||||
catalogue[i].modele = modeles[rand() % 4];
|
||||
catalogue[i].categorie = categories[rand() % 4];
|
||||
if (catalogue[i].categorie == "Wedge") {
|
||||
catalogue[i].sous_categorie = rand() % 5;
|
||||
}
|
||||
else if (catalogue[i].categorie == "Putter") {
|
||||
catalogue[i].sous_categorie = rand() % 3;
|
||||
}
|
||||
else {
|
||||
catalogue[i].sous_categorie = rand() % 9 + 1;
|
||||
}
|
||||
}
|
||||
affiche_catalogue(10, catalogue);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
Reference in New Issue
Block a user