1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct Voiture
{
char marque[40];
int id;
unsigned long int km;
int etat;
};
void remplirT(struct Voiture *ptr, int nb);
void afficherT(struct Voiture *ptr, int nb);
void louableT(struct Voiture T[], int nb);
int rechercheRecursive(struct Voiture T[], int nb);
void suppression(struct Voiture T[], int nb);
struct Voiture T[5000];
struct Voiture *ptr;
int nb;
int main()
{
printf("Indiquez le nombre de voitures a saisir : ");
scanf("%d", &nb);
ptr = (struct Voiture *)malloc(nb * sizeof(struct Voiture));
char choix;
do
{
system("cls");
printf("\t\t*** MENU ***\t\t\n\n");
printf("a : saisir des voitures\nb : afficher des voitures\nc : afficher des caracteristiques d'une voiture si possible\nd : rechercher une voiture\ne : supprimer des voitures\nf : fin du programme\n\n");
getchar();
scanf("%c", &choix);
switch (choix)
{
case 'a' :
case 'A' :
system("cls");
remplirT(ptr, nb);
getch();
break;
case 'b' :
case 'B' :
system("cls");
afficherT(ptr, nb);
getch();
break;
case 'c' :
case 'C' :
system("cls");
louableT(T, nb);
getch();
break;
case 'd' :
case 'D' :
system("cls");
rechercheRecursive(T, nb);
getch();
break;
case 'e' :
case 'E' :
system("cls");
suppression(T, nb);
getch();
break;
case 'f' :
case 'F' :
system("cls");
printf("Fin du programme\n");
getch();
break;
default :
system("cls");
printf("Mauvais choix\n");
getch();
break;
}
}
while (choix != 'f' && choix != 'F');
return (0);
}
void remplirT(struct Voiture *ptr, int nb)
{
int x;
for (x = 0; x < nb; x++)
{
printf("Saisir la marque %d : ", x + 1);
scanf("%s", (ptr + x)->marque); // marque represente deja une adresse cdc, donc pas de &
printf("Saisir le numero d'identification %d : ", x + 1);
scanf("%d", &(ptr + x)->id);
printf("Saisir le kilometrage %d : ", x + 1);
scanf("%lu", &(ptr + x)->km);
printf("Saisir l'etat %d (0 pour disponible et 1 sinon) : ", x + 1);
scanf("%d", &(ptr + x)->etat);
}
}
void afficherT(struct Voiture *ptr, int nb)
{
int x;
for (x = 0; x < nb; x++)
{
printf("%s\t%d\t%lu\t%d\n", (ptr + x)->marque, (ptr + x)->id, (ptr + x)->km, (ptr + x)->etat);
}
}
void louableT(struct Voiture T[], int nb)
{
int ID, a, x;
printf("Numero d'identification de la voiture a louer : ");
scanf("%d", &ID);
for (a = 0; a < nb; a++)
{
if (ID == T[a].id)
{
printf("Cette voiture est en location : ");
printf("Voici ces caracteristiques : \n");
for (x = 0; x < nb; x++)
printf("Numero d'identification : %d\t Kilometrage : %lu\t Etat : %d\n", T[x].id, T[x].km, T[x].etat);
}
else
{
printf("Erreur, cette voiture n'existe pas\n");
}
}
}
int rechercheRecursive(struct Voiture T[], int nb)
{
int ID, x;
printf("Donner un identifiant : ");
scanf("%d", &ID);
if (nb > x) return 0;
if (ID == T[x].id)
return printf("Marque : %s, %d i-eme element\n", T[x].marque, rechercheRecursive(++T, --nb));
}
void suppression(struct Voiture T[], int nb)
{
char marques[40];
char *pMarque = marques;
int x, y;
printf("Donnez une marque : ");
fgets(pMarque, 40, stdin);
/*
for (x = 0; x < nb; x++)
{
if (strcmp(pMarque, ptr[x].marque) == 0)
{
for (y = 0; y < nb; y++)
{
memset(T, 0, nb);
}
}
}
}
*/ |