Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdio.h"
- // affichage des menus selon le choix de l'utilisateur
- void afficherMenu(int choix)
- {
- switch (choix)
- {
- case 1:
- printf("Gestion des voitures: \n\n");
- printf("1. Ajouter une nouvelle voiture \n");
- printf("2. Ajouter un ensemble de voitures \n");
- printf("3. Afficher l’ensemble des voitures enregistrées triés par ordre croissant \n");
- printf("4. Rechercher une voiture \n");
- printf("5. Supprimer une voiture \n");
- printf("6. Retourner au menu principal \n");
- printf("7. Quitter \n\n");
- break;
- case 2:
- printf("Gestion des Agences \n\n");
- printf("1. Ajouter une nouvelle agence \n");
- printf("2. Afficher l’ensemble des agences enregistrées triés par ordre croissant \n");
- printf("3. Rechercher une agence \n");
- printf("4. Modifier l’indice d’une agence \n");
- printf("5. Supprimer une agence \n");
- printf("6. Retourner au menu principal \n");
- printf("7. Quitter \n\n");
- break;
- default:
- printf("Gestion des affectations \n\n");
- printf("1. Affecter une voiture à une agence \n");
- printf("2. Afficher l’ensemble des voitures disponibles \n");
- printf("3. Afficher l’affectation d’une voiture \n");
- printf("4. Afficher l’affectation d’une\n");
- printf("5. Afficher le nombre de voitures par agence \n");
- printf("6. Afficher l’agence ayant le maximum de voitures \n");
- printf("7. Libérer une voiture \n");
- printf("8. Afficher le taux d’occupation des voitures \n");
- printf("9. Quitter \n\n");
- }
- }
- // affichage du tableau
- void afficherTab(int t[50], int n)
- {
- printf("\n");
- for (int i = 0; i < n; i++)
- {
- printf("** element %d: %d\n", i+1, t[i]);
- }
- }
- // affichage du tableau triee
- void afficherTabTriee(int t[50], int n)
- {
- int d, c, swap;
- for (c = 0; c < n - 1; c++)
- {
- for (d = 0; d < n - c - 1; d++)
- {
- if (t[d] > t[d + 1])
- {
- swap = t[d];
- t[d] = t[d + 1];
- t[d + 1] = swap;
- }
- }
- }
- // appel d'affichage normal apres le tri
- afficherTab(t, n);
- }
- void afficherTabTrieeAgence(int t[50], int n)
- {
- int d, c;
- char swap;
- for (c = 0; c < n - 1; c++)
- {
- for (d = 0; d < n - c - 1; d++)
- {
- if (t[d] > t[d + 1])
- {
- swap = t[d];
- t[d] = t[d + 1];
- t[d + 1] = swap;
- }
- }
- }
- // appel d'affichage normal apres le tri
- afficherTab(t, n);
- }
- // recherche du voiture dans le tableau
- int rechercherVoiture(int t[50], int n, int voiture)
- {
- for (int i = 0; i < n; i++)
- {
- if (t[i] == voiture)
- {
- return 1;
- }
- }
- return 0;
- }
- // recherche d'agence dans le tableau
- int rechercherAgence(char t[50], int n, char agence)
- {
- for (int i = 0; i < n; i++)
- {
- if (t[i] == agence)
- {
- return 1;
- }
- }
- return 0;
- }
- void ajoutSequenceVoiture(int t[50], int n, int x)
- {
- int i = x, a;
- while (1)
- {
- int ajout;
- printf("ahouter ? (1 pour oui et 0 pour non)");
- scanf("%d", &a);
- if (a != 0)
- {
- printf("t[%d]:", i);
- scanf("%d", t[i]);
- i++;
- }
- else
- {
- break;
- }
- }
- // le role de cette boucle est de se debuter de l'indexe du dernier ajout fait dans le tableau et dire a l'utilisateur d'entrer une valeur si non quitter
- }
- void ajoutVoiture(int *t[50], int n){
- printf("\n");
- for (int i = 0; i < n; i++){
- printf("Voiture N° %d => ",i+1);
- scanf("%d", &t[i]);
- }
- }
- void ajoutAgence(char *t[50], int n){
- for (int i = 0; i < n; i++){
- printf("Agence N° %d",i);
- scanf("%c", &t[i]);
- }
- }
- void supprimerElement(int *t[50], int n, int position){
- for (int i = position - 1; i < n - 1; i++){
- t[i] = t[i+1];
- }
- }
- void changerIndiceAgence(char *t[50],int n,int oldPos,int newPos){
- char temp = t[oldPos];
- t[oldPos] = t[newPos];
- t[newPos] = temp;
- }
- // main
- void main()
- {
- // declaration des tableaux
- int tv[50], tf[50][50];
- int choix = 0;
- int nv, na;
- char ta[50];
- debut:
- printf("---------------------------------------\n");
- printf("1 => Gestion des voitures\n");
- printf("2 => Gestion des Agences\n");
- printf("3 => Gestion des affectations\n\n");
- printf("\n\n");
- do
- {
- printf("\nton choix: ");
- scanf("%d", &choix);
- } while ((choix < 1) || (choix > 3));
- printf("\n\n");
- afficherMenu(choix);
- int choix2 = 0;
- switch (choix){
- case 1:
- do
- {
- printf("choix du premiere menu: ");
- scanf("%d", &choix2);
- } while ((choix < 1) || (choix > 7));
- break;
- default:
- do
- {
- printf("choix du premiere menu: ");
- scanf("%d", &choix2);
- } while ((choix < 1) || (choix > 9));
- break;
- }
- if (choix == 1){
- switch (choix2){
- case 1:
- ajoutVoiture(tv,1);
- break;
- case 2:
- printf("Nombre de voitures a ajouter: ");
- scanf("%d", &nv);
- ajoutVoiture(tv,nv);
- break;
- case 3:
- afficherTabTriee(tv,nv);
- break;
- case 4:
- int voit;
- printf("\n Voiture a rechercher: ");
- scanf("%d", &voit);
- if (rechercherVoiture(tv, nv, voit) == 0)
- {
- printf("Voiture introuvable");
- }
- else{
- printf("Voiture trouvee");
- }
- break;
- case 5:
- int i;
- printf("Indice pour supprimer: ");
- scanf("%d",&i);
- if (i>nv){
- printf("indice > au taille du tableau");
- }
- else{
- supprimerElement(tv,nv,i);
- }
- break;
- case 6:
- goto debut;
- break;
- case 7:
- return;
- }
- printf("\n\n\n");
- goto debut;
- }
- if (choix == 2){
- switch (choix2){
- case 1:
- printf("Nombre d'agences a ajouter: ");
- scanf("%d", &na);
- ajoutAgence(ta,na);
- break;
- case 2:
- afficherTabTrieeAgence(ta,na);
- break;
- case 3:
- char agence;
- printf("\n Voiture a rechercher: ");
- scanf("%d", &agence);
- if (rechercherVoiture(ta, na, agence) == 0){
- printf("agence introuvable");
- }
- else{
- printf("agence trouvee");
- }
- break;
- case 4:
- int old, new;
- printf("\n indice a changer: ");
- scanf("%d", &old);
- printf("\n Nouveau indice: ");
- scanf("%d", &new);
- changerIndiceAgence(ta, na, old, new);
- break;
- case 5:
- int i;
- printf("Indice pour supprimer: ");
- scanf("%d",&i);
- if (i>nv){
- printf("indice > au taille du tableau");
- }
- else{
- supprimerElement(tv,nv,i);
- }
- break;
- case 6:
- goto debut;
- break;
- case 7:
- return;
- }
- printf("\n\n\n");
- goto debut;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement