Gestion de la réservation des billets d'une salle de théatre

Signaler
Messages postés
3
Date d'inscription
lundi 14 décembre 2009
Statut
Membre
Dernière intervention
6 mai 2010
-
Messages postés
286
Date d'inscription
vendredi 5 décembre 2003
Statut
Membre
Dernière intervention
22 avril 2012
-
#include <cstdlib>
#include
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <windows.h>

using namespace std;

struct info_reserv
{
char nom[50];
int rang;
int p_place;
int d_place;
info_reserv *suiv;
};info_reserv *tete;


struct info_att
{
char nom[50];
int rang;
int place;
info_att *suiv;
};info_att *deb;

typedef int tableau [50][50];

void color(int couleurDuTexte,int couleurDuFond);

void deco()
{
time_t now;
time(&now);/* Fontion time avec la variable now comme parametre*/
color(15,15);printf(" ");color(0,15);printf("Nous sommes le : ");color(12,15);printf("%s",asctime(localtime(&now)));
color(15,15);printf(" ");color(0,0);printf(" \n");
color(15,15);printf(" ");color(7,7);printf(" ");color(11,0);printf(" Kotni Hakim Groupe 5 Section 2 \n");
color(15,15);printf(" ");color(7,7);printf(" ");color(0,0);printf(" \n");
color(15,15);printf(" ");color(7,7);printf(" \n");color(1,15);
color(15,15);printf("\n ");color(1,1);printf("*****");color(15,15);printf(" ");color(1,1);printf("*");color(15,15);printf(" ");color(1,1);printf("*");color(15,15);printf(" ");color(1,1);printf("*****");color(15,15);printf(" ");color(1,1);printf("*****");color(15,15);printf(" ");color(1,1);printf("*****");color(15,15);printf(" ");color(1,1);printf("****");color(15,15);printf(" ");color(1,1);printf("*****\n");
color(15,15);printf(" ");color(1,1);printf("*");color(15,15);printf(" ");color(1,1);printf("*");color(15,15);printf(" ");color(1,1);printf("*");color(15,15);printf(" ");color(1,1);printf("*");color(15,15);printf(" ");color(1,1);printf("*");color(15,15);printf(" ");color(1,1);printf("*");color(15,15);printf(" ");color(1,1);printf("*");color(15,15);printf(" ");color(1,1);printf("*");color(15,15);printf(" ");color(1,1);printf("*");color(15,15);printf(" ");color(1,1);printf("*\n");
color(15,15);printf(" ");color(1,1);printf("*");color(15,15);printf(" ");color(1,1);printf("*****");color(15,15);printf(" ");color(1,1);printf("*****");color(15,15);printf(" ");color(1,1);printf("*****");color(15,15);printf(" ");color(1,1);printf("*");color(15,15);printf(" ");color(1,1);printf("****");color(15,15);printf(" ");color(1,1);printf("*****\n");
color(15,15);printf(" ");color(1,1);printf("*");color(15,15);printf(" ");color(1,1);printf("*");color(15,15);printf(" ");color(1,1);printf("*");color(15,15);printf(" ");color(1,1);printf("*");color(15,15);printf(" ");color(1,1);printf("*");color(15,15);printf(" ");color(1,1);printf("*");color(15,15);printf(" ");color(1,1);printf("*");color(15,15);printf(" ");color(1,1);printf("*");color(15,15);printf(" ");color(1,1);printf("*");color(15,15);printf(" ");color(1,1);printf("*\n");
color(15,15);printf(" ");color(1,1);printf("*");color(15,15);printf(" ");color(1,1);printf("*");color(15,15);printf(" ");color(1,1);printf("*");color(15,15);printf(" ");color(1,1);printf("*****");color(15,15);printf(" ");color(1,1);printf("*");color(15,15);printf(" ");color(1,1);printf("*");color(15,15);printf(" ");color(1,1);printf("*");color(15,15);printf(" ");color(1,1);printf("*");color(15,15);printf(" ");color(1,1);printf("*");color(15,15);printf(" ");color(1,1);printf("*****\n\n");
color(15,15);printf(" ");color(1,1);printf("*");color(15,15);;printf(" ");color(1,1);printf("*");color(15,15);printf(" ");color(1,1);printf("*");color(1,1);printf("****");color(15,15);printf(" ");color(1,1);printf("*****");color(15,15);printf(" ");color(1,1);printf("*****\n");
color(15,15);printf(" ");color(1,1);printf("*");color(15,15);printf(" ");color(1,1);printf("*");color(15,15);printf(" ");color(1,1);printf("*");color(15,15);printf(" ");color(1,1);printf("*");color(15,15);printf(" ");color(1,1);printf("*");color(15,15);printf(" ");color(1,1);printf("*\n");
color(15,15);printf(" ");color(1,1);printf("*");color(15,15);printf(" ");color(1,1);printf("*");color(15,15);printf(" ");color(1,1);printf("*****");color(15,15);printf(" ");color(1,1);printf("*");color(15,15);printf(" ");color(1,1);printf("*");color(15,15);printf(" ");color(1,1);printf("*\n");
color(15,15);printf(" ");color(1,1);printf("*");color(15,15);printf(" ");color(1,1);printf("*");color(15,15);printf(" ");color(1,1);printf("*");color(15,15);printf(" ");color(1,1);printf("*");color(15,15);printf(" ");color(1,1);printf("*");color(15,15);printf(" ");color(1,1);printf("*\n");
color(15,15);printf(" ");color(1,1);printf("*****");color(15,15);printf(" ");color(1,1);printf("*");color(15,15);printf(" ");color(1,1);printf("*****");color(15,15);printf(" ");color(1,1);printf("*");color(15,15);printf(" ");color(1,1);printf("*");color(15,15);printf(" ");color(1,1);printf("*");color(15,15);printf(" ");color(1,1);printf("*****\n\n\n");color(1,15);
}


void liste_att (info_att *&att,char nom[50], int place, int rang, int &na)
{
if (na==0)
{
deb=new info_att;
att=deb;
}
else
{
att=deb;
while (att->suiv!=NULL)
{ att=att->suiv; }
att->suiv=new info_att;
att=att->suiv;
}
strcpy(att->nom,nom);
att->place=place;
att->rang=rang;
att->suiv=NULL;
na++;
color(15,15);printf("\n\n ");color(0,0);printf("_________________________________________\n");
color(15,15);printf(" ");color(0,0);printf("||");color(0,0);printf(" ");color(0,0);printf("||");color(7,7);printf(" \n");
color(15,15);printf(" ");color(0,0);printf("||");color(12,0);printf(" Mise en attente ");color(0,0);printf("||");color(7,7);printf(" \n");
color(15,15);printf(" ");color(0,0);printf("||");color(0,0);printf(" ");color(0,0);printf("||");color(7,7);printf(" \n");
color(15,15);printf(" ");color(0,0);printf("_________________________________________");color(15,15);color(7,7);printf(" \n");
color(15,15);printf(" ");color(7,7);printf("_________________________________________\n\n\n");color(15,15);
}

void reservation(tableau &tab, info_reserv *&res, info_att *att, int place, int nbrs_rang, int rang, int nbrs_place, char nom[50], int &nr, int na)
{
int p_place,d_place,pl=0,j=1,i,c;
bool vide =false;
time_t now;
while (vide==false && j<=place)
{
if (tab[rang][j]==0) pl++;
else if (pl<nbrs_place) pl=0;
else if (pl>=nbrs_place) vide=true;
j++;
}
if (vide==true || pl>=nbrs_place)
{
p_place=j - pl;
d_place=p_place + nbrs_place - 1;
for (j=p_place;j<=d_place;j++) tab[rang][j]=1;
{
if (nr==0)
{
tete=new info_reserv;
res=tete;
strcpy(res->nom,nom);
}
else
{
res=tete;
while (res->suiv!=NULL)
{ res=res->suiv; }
res->suiv=new info_reserv;
res=res->suiv;
strcpy(res->nom,nom);
}
res->rang=rang;
res->p_place=p_place;
res->d_place=d_place;
res->suiv=NULL;
nr++;
system("CLS");
deco();
color(15,15);printf("\n\n ");color(0,0);printf("__________________________________________\n");
color(15,15);printf(" ");color(0,0);printf("||");color(0,0);printf(" ");color(0,0);printf("||");color(7,7);printf(" \n");
color(15,15);printf(" ");color(0,0);printf("||");color(12,0);printf(" Merci pour votre reservation ");color(0,0);printf("||");color(7,7);printf(" \n");
color(15,15);printf(" ");color(0,0);printf("||");color(0,0);printf(" ");color(0,0);printf("||");color(7,7);printf(" \n");
color(15,15);printf(" ");color(0,0);printf("__________________________________________");color(15,15);color(7,7);printf(" \n");
color(15,15);printf(" ");color(7,7);printf("__________________________________________\n\n\n");color(1,15);
}
}
else
{
system("CLS");
deco();
color(15,15);printf("\n\n ");color(7,7);printf("__________________________________________________\n");
color(15,15);printf(" ");color(7,7);printf(" ");color(0,0);printf("__________________________________________________\n");
color(15,15);printf(" ");color(7,7);printf(" ");color(0,0);printf("||");color(0,0);printf(" ");color(0,0);printf("||\n");
color(15,15);printf(" ");color(7,7);printf(" ");color(0,0);printf("||");color(12,0);printf(" Rangee pleine, plus de places libres ");color(0,0);printf("||\n");
color(15,15);printf(" ");color(7,7);printf(" ");color(0,0);printf("||");color(0,0);printf(" ");color(0,0);printf("||\n");
color(15,15);printf(" ");color(7,7);color(0,0);printf("__________________________________________________\n\n\n");color(1,15);
color(1,15);
cout<<" Dans les rangees suivantes se trouve des places libres : ";cout<<"\n\n ";

for (i=1;i<=nbrs_rang;i++)
{
cout< Reservation d'une place ");color(0,0);printf("||\n");
color(15,15);printf(" ");color(0,0);printf("||");color(9,7);printf(" 2 ==> Liste d'attente ");color(0,0);printf("||\n");
color(15,15);printf(" ");color(0,0);printf("||");color(7,7);printf(" ");color(0,0);printf("||\n");
color(15,15);printf(" ");color(0,0);printf(" ");color(1,15);printf(" \n\n");
while (c!=1 && c!=2)
{
{
cout<<" Votre Choix : ";
color(12,15);cin>>c;color(1,15);
}
switch(c)
{
case 1 : system("CLS");
deco();
do
{
cout<<" Entrer le numero de la rangee : ";
color(12,15);cin>>rang;color(1,15);
cout<<" Entrer le nombres de places : ";
color(12,15);cin>>nbrs_place;color(1,15);
}
while (rang>nbrs_rang);
reservation(tab,res,att,place,nbrs_rang,rang,nbrs_place,nom,nr,na);
break ;

case 2 : system("CLS");
deco();
liste_att (att,nom,nbrs_place,rang,na);
break ;
}
}
}
}

void relever (info_reserv *res,info_att *att)
{
color(11,15);printf("_______________________________________________________________________________\n");
color(0,0);printf(" \n");
color(11,0);printf(" Liste des reservations \n");
color(11,0);printf("_______________________________________________________________________________\n\n");color(1,15);
res=tete;
if (res==NULL)
{
color(0,15);cout<<" Vide "<<endl<<endl;
}
while (res!=NULL)
{
color(0,15);printf(" Client : ");color(12,15);cout<<res->nom;cout<<" ";color(0,15);printf(" Num Rangee : ");color(12,15);cout<<res->rang;cout<<" ";color(0,15);printf(" Nombres de places : ");color(12,15);cout<<((res->d_place - res->p_place) + 1); cout<<endl;
res=res->suiv;
}
color(11,15);printf("_______________________________________________________________________________\n");
color(0,0);printf(" \n");
color(11,0);printf(" Liste des clients en attente \n");
color(11,0);printf("_______________________________________________________________________________\n\n");color(1,15);
att=deb;
if (att==NULL)
{
color(0,15);cout<<" Vide "<<endl<<endl;
color(0,15);cout<<"_______________________________________________________________________________"<<endl;
}
while (att!=NULL)
{
color(0,15);printf(" Client : ");color(12,15);cout<nom;cout<<" ";color(0,15);printf(" Num Rangee : ");color(12,15);cout<rang;cout<<" ";color(0,15);printf(" Nombres de places : ");color(12,15);cout<place; cout<<endl<<endl;color(1,15);
color(0,15);cout<<"_______________________________________________________________________________"<<endl;
att=att->suiv;
}
}

void affi(tableau &t)
{
int i,j;
color(0,15);printf(" ");color(7,7);printf(" \n");
for (i=20;i>=1;i--)
{
color(0,15);printf(" ");color(7,7);printf(" ");color(0,7);
for (j=1;j<=50;j++)
{
cout<<t[i][j];
}
color(7,7);printf(" ");
cout<<endl;
}

color(0,15);printf(" ");color(7,7);printf(" \n\n"); color(1,15);
color(12,15);printf(" Remarque : \n");
color(0,15);printf( " 1 : Places reserves \n");
printf(" 0 : Places vides \n\n\n");color(1,15);
}

void annul_att (info_att *&att,int &na,char nom[50])
{
info_att *s, *sp;
att=deb;
bool delatt=false;
if (strcmp(att->nom,nom)==0)
{
att=deb;
deb=deb->suiv;
delete att;
na--;
delatt=true;
}
if (na>0 && delatt==false)
{
s=deb;
sp=deb;
while (!(strcmp(s->nom,nom)==0) && s!=NULL)
{
sp=s;
s=s->suiv;
}
if (strcmp(s->nom,nom)==0)
{
att=s;
sp->suiv=s->suiv;
delete att;
na--;
}
}
cout<<" Le client ";cout<<sp->nom;cout<<" vient d'etre ajouter a la liste des reservation";
}

void suppression(tableau tab)
{
bool del=false,delatt=false,vide=false;
int i,j,l,p_place,d_place,place,rang,nr,na;
info_reserv *res,*p,*pp;
info_att *att,*s,*sp;
char nom[50];
relever (res,att);
cout<<endl<<" Entrez le nom du client a suprrimer : ";
color(12,15);cin>>nom;color(1,15);
color(0,15);cout<<"_______________________________________________________________________________"<<endl;
if (tete==NULL)
{
color(15,15);printf("\n\n ");color(7,7);printf(" \n");
color(15,15);printf(" ");color(0,0);printf(" ");color(7,7);printf(" \n");
color(15,15);printf(" ");color(0,0);printf("||");color(0,0);printf(" ");color(0,0);printf("||");color(7,7);printf(" \n");
color(15,15);printf(" ");color(0,0);printf("||");color(12,0);printf(" Liste des reservations vide ");color(0,0);printf("||");color(7,7);printf(" \n");
color(15,15);printf(" ");color(0,0);printf("||");color(0,0);printf(" ");color(0,0);printf("||");color(7,7);printf(" \n");
color(15,15);printf(" ");color(0,0);printf(" \n\n\n");color(1,15);
}
else
{
p=tete;
if(strcmp(p->nom,nom)==0)
{
i=p->rang;
p_place=p->p_place;
d_place=p->d_place;
for(j=p->p_place;j<=p->d_place;j++) tab[i][j]=0;
l=p->d_place-p->p_place+1;
tete=tete->suiv;
delete p;
del=true;
}
else
{
while(!(strcmp(p->nom,nom)==0)&&(p->suiv!=NULL))
{
pp=p;
p=p->suiv;
}
if(strcmp(p->nom,nom)==0)
{
i=p->rang;
p_place=p->p_place;
d_place=p->d_place;
for(j=p->p_place;j<=p->d_place;j++) tab[i][j]=0;
l=p->d_place-p->d_place+1;
pp->suiv=p->suiv;
delete p;
del=true;
}
}
if(del==true)
{
color(0,15);printf("\n le client ");color(12,15);cout<<nom;color(0,15);printf(" vient d'etre supprime de la liste des reservations \n");
color(0,15);cout<<"_______________________________________________________________________________"<<endl;

if (deb!=NULL)
{
att=deb;
if((att->place)<=l)
{
if (tete!=NULL)
{
res=tete;
while(res->suiv!=NULL) res=res->suiv;
res->suiv=new info_reserv;
res=res->suiv;
}
else
{
tete=new info_reserv;
res=tete;

}
strcpy(res->nom,att->nom);
res->rang=i;
att->place=place;
res->suiv=NULL;
for(j=p_place;j<=d_place;j++) tab[i][j]=1;
annul_att(att,na,att->nom);
}
}

}
else if (del!=true)
{
color(0,15);cout<<endl<<" Le client ";color(12,15);cout<<nom;color(0,15);cout<<" n'existe pas dans la liste des reservations \n\n";
}
}
if(deb==NULL)
{
color(15,15);printf("\n\n ");color(7,7);printf(" \n");
color(15,15);printf(" ");color(7,7);printf(" ");color(0,0);printf(" \n");
color(15,15);printf(" ");color(7,7);printf(" ");color(0,0);printf("||");color(0,0);printf(" ");color(0,0);printf("||\n");
color(15,15);printf(" ");color(7,7);printf(" ");color(0,0);printf("||");color(12,0);printf(" Liste d'attente vide ");color(0,0);printf("||\n");
color(15,15);printf(" ");color(7,7);printf(" ");color(0,0);printf("||");color(0,0);printf(" ");color(0,0);printf("||\n");
color(15,15);printf(" ");color(0,0);printf(" \n\n\n");color(15,15);
}
else
{
s=deb;
if(strcmp(s->nom,nom)==0)
{
deb=deb->suiv;
delete s;
delatt=true;
}
else
{
while(!(strcmp(s->nom,nom)==0)&&(s->suiv!=NULL))
{
sp=s;
s=s->suiv;
}
if(strcmp(s->nom,nom)==0)
{
sp->suiv=s->suiv;
delete s;
delatt=true;
}
}
if(delatt!=false)

{
color(0,15);printf("\n Le client ");color(12,15);cout<<nom;color(0,15);printf(" vient d'etre supprime de la liste des attentes \n\n");color(15,15);
}
}


}




int main(int argc, char *argv[] )
{
tableau tab;
info_reserv *res;
info_att *att;
int nbrs_rang, place, c=0, rang, nbrs_place, nr=0, na=0, i, j;
char nom[50];
system("COLOR f1");
time_t now;
deco();
nbrs_rang=20;
place=50;
for (i=1;i<=nbrs_rang;i++);
for (j=1;j<=place;j++);
tab[i][j]=0;
while (c!=5)
{
{
printf("\n ");color(0,0);printf("__________________________________________________________________\n");color(15,15);
color(15,15);printf(" ");color(0,0);printf("||");color(7,7);printf(" ");color(0,0);printf("||\n");color(15,15);
color(15,15);printf(" ");color(0,0);printf("||");color(9,7);printf(" 1 ==> Reservation d'une place ");color(0,0);printf("||\n");color(15,15);
color(15,15);printf(" ");color(0,0);printf("||");color(9,7);printf(" 2 ==> Afficher les places reserve et la liste d'attente ");color(0,0);printf("||\n");color(15,15);
color(15,15);printf(" ");color(0,0);printf("||");color(9,7);printf(" 3 ==> Aficher la salle ");color(0,0);printf("||\n");color(15,15);
color(15,15);printf(" ");color(0,0);printf("||");color(9,7);printf(" 4 ==> Anuller une reservation ");color(0,0);printf("||\n");color(15,15);
color(15,15);printf(" ");color(0,0);printf("||");color(9,7);printf(" 5 ==> Quitter ");color(0,0);printf("||\n");color(15,15);
color(15,15);printf(" ");color(0,0);printf("||");color(7,7);printf(" ");color(0,0);printf("||\n");color(15,15);
color(15,15);printf(" ");color(0,0);printf("__________________________________________________________________\n");color(1,15);
cout<<"\n Votre choix : ";
color(12,15);cin>>c;color(1,15);

}

switch(c)
{
case 1 : system("CLS");
deco();

cout<<" Entrer le nom : ";
color(12,15);cin>>nom;color(1,15);
do
{
cout<<" Entrer le numero de la rangee : ";
color(12,15);cin>>rang;color(1,15);
}
while (rang>nbrs_rang);
do
{
cout<<" Entrer le nombres de places : ";
color(12,15);cin>>nbrs_place;color(1,15);
}
while (nbrs_place>place);
reservation(tab,res,att,place,nbrs_rang,rang,nbrs_place,nom,nr,na);
break;

case 2 : system("CLS");
time_t now;
deco();
relever (res,att);
break;

case 3 : system("CLS");
deco();
affi(tab);
break;

case 4 : system("CLS");
deco();
suppression (tab);
break ;


case 5 : system("CLS");
deco();
color(15,15);printf("\n\n ");color(0,0);printf(" \n");
color(15,15);printf(" ");color(0,0);printf(" ");color(7,7);printf(" \n");
color(15,15);printf(" ");color(12,0);printf(" Fin du programme ");color(7,7);printf(" \n");
color(15,15);printf(" ");color(0,0);printf(" ");color(7,7);printf(" \n");
color(15,15);printf(" ");color(0,0);printf(" ");color(7,7);printf(" \n");
color(15,15);printf(" ");color(7,7);printf(" \n\n\n");color(15,15);
break;


}
}
system("PAUSE");
return EXIT_SUCCESS;
}
void color(int couleurDuTexte,int couleurDeFond) // fonction d'affichage de couleurs
{
HANDLE H=GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(H,couleurDeFond*16+couleurDuTexte);
}

1 réponse

Messages postés
286
Date d'inscription
vendredi 5 décembre 2003
Statut
Membre
Dernière intervention
22 avril 2012
1
Oui, et ?