DEV/DEV1.1/TP31/test.c

61 lines
1.4 KiB
C
Raw Normal View History

2025-01-07 15:07:12 +01:00
#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;
}