Java
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
----- TP31 : Concepts en vrac -----
|
||||
|
||||
1.
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
typedef struct {
|
||||
unsigned int durabilite : 10;
|
||||
unsigned int deplacement : 4;
|
||||
unsigned int defense : 7;
|
||||
unsigned int degats : 7;
|
||||
unsigned int distance : 4;
|
||||
} unite;
|
||||
|
||||
int main(void) {
|
||||
unite test;
|
||||
test.durabilite = 7;
|
||||
test.defense = 7;
|
||||
test.degats = 7;
|
||||
test.deplacement = 7;
|
||||
test.distance = 7;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
2.
|
||||
|
||||
#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++) {
|
||||
if (filtre(catalogue[i])) {
|
||||
printf("| %6s | %6s | %9s | %14d |\n", catalogue[i].marque, catalogue[i].modele, catalogue[i].categorie, catalogue[i].sous_categorie);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int filtre(club article) {
|
||||
return article.categorie == "Fer" && article.sous_categorie <= 4;
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
int i;
|
||||
club catalogue[100];
|
||||
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 != 100; 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(100, catalogue);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
3.
|
||||
|
||||
|
@@ -1,61 +1,29 @@
|
||||
#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
|
||||
};
|
||||
void afficherTableau(unsigned short tab[], size_t taille) {
|
||||
if (taille == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (taille == sizeof(tab) / sizeof(tab[0])) {
|
||||
printf("{");
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
char* marque;
|
||||
char* modele;
|
||||
char* categorie;
|
||||
unsigned int sous_categorie : 4;
|
||||
} club;
|
||||
printf("%d", tab[0]);
|
||||
|
||||
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);
|
||||
}
|
||||
if (taille > 1) {
|
||||
printf(", ");
|
||||
afficherTableau(tab + 1, taille - 1);
|
||||
} else {
|
||||
printf("}");
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
int main(void) {
|
||||
unsigned short int tab[4] = {1,2,3,4};
|
||||
afficherTableau(tab, 4);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
Reference in New Issue
Block a user