Mini projet en langage C pour la gestion de location voiture
Cet article propose en détaille un mini projet en langage C pour la gestion de location voiture.
Cette application vise à gérer une agence de location de voiture. Il manipule les données tel que les clients (locataires), les voitures, les contrats de locations avec la durée le cout...,
Il enregistre les données dans des fichiers.
Les charges au lancement et les sauvegarder à volanté.
Il veille à la synchronisation des données.
Vous pourrez télécharger le fichier au format zip il contient le code source complet.
Extrait du code source :
#include<stdio.h>
#include<string.h>
#include<conio.h>
#include<stdlib.h>
#include<time.h>
#include<windows.h>
#include"structure.h"
#include"prototype.h"
//#define int supcond 20
//#define int bebe 15
//#define int livraison 20
//************************************************************
//** Fonction : Condition de location **
//** Parametre : La structure client **
//** Traitement: elle compare l'age du client à 25 et **
//** verifie si la difference entre date de **
//** permis et la dte actuelle est superieur**
//** à 2 ans **
//** Retourne : 0 si la condition de loction est verifié**
//** et 1 sinon **
//** Utilise : convertDate **
//************************************************************
int ConditionLocation(client cl)
{
int tmp;
int aa,mm,jj;
if(cl.age>=25)
{
tmp=cl.date_permi;
jj=tmp/1000000;
mm=((tmp%1000000)/10000);
aa=((tmp%1000000)%10000);
if((convertDate().aa+2000)-aa>=2)
return 0;
}
return 1;
}
//********************************************************
//** Fonction : Saisie d'un contrat **
//** Parametre : liste de client,liste de matricule **
//** Traitement: Saisie des champs du contrat **
//** Retourne : la cellule contrat sinon retourne NULL **
//********************************************************
ListeContrat saisieContrat(cellule_client *person,listeMatricul l)
{
CelluleContrat *cel;
Matricul *mat;
int verif=0;
char typ[5];
if(ConditionLocation(person->person)!=0)
return NULL;
EnTete();
mat=(Matricul *)malloc(sizeof Matricul);
cel=(CelluleContrat *)malloc(sizeof CelluleContrat);
strcpy(cel->cont.nom,person->person.nom);
strcpy(cel->cont.pnom,person->person.prenom);
cel->cont.num=generationCode();
printf("\n\tNumero contrat : %.0f",cel->cont.num);
do
{
if(verif==3)
goto END_SAISIE;
printf("\n\n\tType Voiture louee : ");
scanf("%s",&typ);
mat=RechercheVoitureLibre(l,typ);
if(mat==NULL)
{
printf("\n\t\tPas de voiture disponible");
verif++;
}
}while(mat==NULL);
printf("\n\tVoiture disponible : %i TUN %i",mat->mat.matricule/10000,mat->mat.matricule%10000);
cel->cont.voit_loue=mat->mat.matricule;
do
{
printf("\n\tType de location (km/jr) : ");
scanf("%s",&cel->cont.type);
} while((strcmp(cel->cont.type,"km")!=0)&&(strcmp(cel->cont.type,"jr")!=0));
if(strcmp(cel->cont.type,"km")==0)
{
cel->cont.debu=mat->mat.kilometrage;
printf("\n\t\tKilometrage actuel du vehicule : %d",cel->cont.debu);
cel->cont.fin=0;
}
else
{
printf("\n\tDate du debut : ");
scanf("%d",&cel->cont.debu);
printf("\n\tDate retour : ");
scanf("%d",&cel->cont.fin);
}
printf("\n\tAgence de location : ");
scanf("%s",&cel->cont.agencDepar);
printf("\n\t\tLes options......");
do
{
printf("\n\t2eme conducteur (o/n) :");
scanf("%s",&cel->cont.supcond);
} while((cel->cont.supcond!='o')&&(cel->cont.supcond!='n'));
do
{
printf("\n\tLivraison (o/n) : ");
scanf("%s",&cel->cont.liv);
}while((cel->cont.liv!='o')&&(cel->cont.liv!='n'));
do
{
printf("\n\tSiege bebe (o/n) : ");
scanf("%s",&cel->cont.bebe);
} while((cel->cont.bebe!='o')&&(cel->cont.bebe!='n'));
do
{
printf("\n\n\t\tValider location oui(o) / non(n)");
verif=getch();
}while((verif!=111)&&(verif!=110));
if(verif==110)
return NULL;
strcpy(cel->cont.agencRetour,"TMP");
cel->cont.cout=0;
person->person.ctr=cel->cont.num;
mat->mat.stats='l'; //----->>>>>**********POUR DECLARER LA VOITURE LOUEE********
return cel;
END_SAISIE : //----->>>>>**********ETIQUETTE D'ANNULATION***************
MessageUrgence("Contrat Annule");
return NULL;
}
//************************************************************
//** Fonction : Recherche d'un contrat **
//** Parametre : liste de contrat **
//** Traitement: elle cherche un contrat celon le **
//** matricule,le nom et le prénom du client **
//** **
//** Retourne : la cellule contrat si elle est trouvée **
//** et NULL sinon **
//** **
//** Utilise : strcmp pour comparer les champs **
//************************************************************
ListeContrat RechercheContrat(ListeContrat l)
{
ListeContrat parc;
int mat;
char nom[20],pnom[20];
parc=(ListeContrat)malloc(sizeof ListeContrat);
printf("\n\tMatricul voiture louee : ");
scanf("%d",&mat);
printf("\n\tNom : ");
scanf("%s",&nom);
printf("\n\tPrenom : ");
scanf("%s",&pnom);
parc=l;
while(parc!=NULL)
{
if(parc->cont.voit_loue==mat)
if(strcmp(parc->cont.nom,nom)==0)
if(strcmp(parc->cont.pnom,pnom)==0)
return parc;
parc=parc->suivant;
}
return NULL;}
//************************************************************
//** Procedure : Retour d'une voiture **
//** Parametre : liste de contrat, liste de matricule, **
//** et liste de client **
//** Traitement: permet de completer les champs d'un **
//** contrat lors du retour de la véhicule **
//** louée(calcul du prix total de location) **
//** **
//** Utilise : les fonctions de recherche: **
//** RechercheContrat,RechercheTypeVoiture **
//** RechercheMatricule ** **
//************************************************************
void RetourContrat(ListeContrat lcr,listeMatricul lm,liste l)
{
ListeContrat crt;
listeMatricul mat;
liste typ;
int supcond=20;
int bebe =15;
int livraison =20;
crt=(ListeContrat)malloc(sizeof ListeContrat);
mat=(listeMatricul)malloc(sizeof listeMatricul);
typ=(liste)malloc(sizeof liste);
EnTete();
crt=RechercheContrat(lcr);
if(crt==NULL)
MessageUrgence("Contrat non-trouve");
else
{
crt->cont.cout=0;
mat=rechecherMatricul(lm,crt->cont.voit_loue);
typ=RechercheTypeVoiture(l,mat->mat.type);
printf("\n\tContrat numero : %.0f",crt->cont.num);
printf("\n\tAgence de retour : ");
scanf("%s",&crt->cont.agencRetour);
if(strcmp(crt->cont.type,"km")==0)
{
printf("\n\tKilometrage retour : ");
scanf("%d",&crt->cont.fin);
mat->mat.kilometrage=crt->cont.fin;
}
else
{
printf("\n\tDuree (jour) : ");
scanf("%d",&crt->cont.fin);
printf("\n\tKilometrage retour : ");
scanf("%d",&mat->mat.kilometrage);
}
if(crt->cont.bebe=='o')
crt->cont.cout+=bebe;
if(crt->cont.liv=='o')
crt->cont.cout+=livraison;
if(crt->cont.supcond=='o')
crt->cont.cout+=supcond;
if(strcmp(crt->cont.type,"km")==0)
crt->cont.cout+=(crt->cont.fin-crt->cont.debu)*typ->voit.prixKilo;
else
crt->cont.cout+=crt->cont.fin*typ->voit.prixJour;
printf("\n\tCout : %d\n\n",crt->cont.cout);
strcpy(&mat->mat.stats,"n");
}
system("pause");
}