Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- typedef struct {
- int jj;
- int mm;
- int aa;
- }date;
- typedef struct {
- char dest[16];
- date d;
- }voy;
- typedef struct {
- int ident;
- char nom [16];
- char pre [16];
- int nbrv;
- voy v[16];
- }client;
- void menu (){
- printf ("1. Remplir un tableau de n clients");
- printf ("\n2. Afficher le tableau des clients");
- printf ("\n3. Trier les voyages des clients selon l'orde décroissant de la date");
- printf ("\n4. Afficher le voyageur le plus fidèle");
- printf ("\n5. Afficher la destination la plus demandée pour un voyageur sachant son identifiant");
- printf ("\n6. Afficher le mois l'année avec le plus grand nombre de réservations\n");
- }
- void tri_bulle(client t[15],int i)
- {
- int passage = 0;
- int j,permut;
- client temp [15];
- do {
- permut = 0;
- passage ++;
- for (j=1;j<t[i].nbrv;j++) {
- printf ("%d",t[i].v[j].d.aa);
- if (
- (t[i].v[j].d.aa<t[i].v[j+1].d.aa)||
- ((t[i].v[j].d.aa==t[i].v[j+1].d.aa) && (t[i].v[j].d.mm<t[i].v[j+1].d.mm))||
- ((t[i].v[j].d.aa==t[i].v[j+1].d.aa) && (t[i].v[j].d.mm==t[i].v[j+1].d.mm) && (t[i].v[j].d.jj<t[i].v[j+1].d.jj))
- )
- {
- printf ("ahlaaaaaaaaaaaaaaaaaaa");
- permut = 1;
- temp[1].v[1] = t[i].v[j];
- t[i].v[j] = t[i].v[j+1];
- t[i].v[j+1] = temp[1].v[1];
- }
- }
- }while (permut==1);
- }
- void affiche (int n1,client t[15])
- {
- int i,j;
- for (i=1;i<=n1;i++)
- {
- printf ("\n\n*****Cleint %d*****",i);
- printf ("\nId: %d",t[i].ident);
- printf ("\nNom: %s",t[i].nom);
- printf ("\nPrenom: %s",t[i].pre);
- printf ("\nNombre de voyages: %d",t[i].nbrv);
- for (j=1;j<=t[i].nbrv;j++)
- {
- printf ("\n-Voyage %d",j);
- printf ("\nDestination: %s",t[i].v[j].dest);
- printf ("\nJour/Mois/Année: %d/%d/%d",t[i].v[j].d.jj,t[i].v[j].d.mm,t[i].v[j].d.aa);
- }
- }
- }
- int main ()
- {
- int n,n1,i,j,posmax,ide,r,rmax,pos,k;
- client t[15];
- int t1[30];
- n1=0;
- do{
- printf ("\n\n *****************************************\n");
- menu ();
- scanf ("%d",&n);
- switch (n)
- {
- case 1:
- system("cls");
- printf ("Combien de clients voulez vous enregistrer?\n");
- scanf ("%d",&n1);
- for (i=1;i<=n1;i++)
- {
- printf ("\nDonner l'id du client %d",n);
- scanf ("%d",&t[i].ident);
- printf ("\nDonner le nom du client %d",n);
- fflush(stdin);
- gets (t[i].nom);
- printf ("\nDonner le prénom du client %d",n);
- fflush(stdin);
- gets (t[i].pre);
- printf ("\nDonner le nombre de voyages du client %d",n);
- scanf ("%d",&t[i].nbrv);
- for (j=1;j<=t[i].nbrv;j++)
- {
- printf ("\nDonner une destination pour le voyage n°%d",j);
- fflush(stdin);
- gets (t[i].v[j].dest);
- printf ("\nDonner le jour du voyage n°%d",j);
- scanf ("%d",&t[i].v[j].d.jj);
- printf ("\nDonner le mois du voyage n°%d",j);
- scanf ("%d",&t[i].v[j].d.mm);
- printf ("\nDonner l'année du voyage n°%d",j);
- scanf ("%d",&t[i].v[j].d.aa);
- }
- }
- break;
- case 2:
- system ("cls");
- if (n1==0)
- {
- printf ("Remplir d'abords le tableau ");
- break;
- }else
- {
- affiche (n1,t);
- }
- break;
- case 3:
- system ("cls");
- if (n1==0)
- {
- printf ("Remplir d'abords le tableau ");
- break;
- }else
- {
- for (i=1;i<=n1;i++)
- {
- tri_bulle(t,i);
- }
- }
- break;
- case 4:
- system ("cls");
- if (n1==0)
- {
- printf ("Remplir d'abords le tableau ");
- break;
- }else
- {
- posmax=1;
- for (i=2;i<=n1;i++)
- if (t[posmax].nbrv<t[i].nbrv)
- {
- posmax=i;
- }
- printf ("Le client le plus fidèle est le client %d",posmax);
- }
- break;
- case 5:
- if (n1==0)
- {
- printf ("Remplir d'abords le tableau ");
- break;
- }else
- {
- printf ("Donner un identifiant");
- scanf ("%d",&ide);
- for (i=1;i<=n1 && t[i].ident != i;i++)
- if (t[i].ident==ide)
- break;
- posmax=1;
- rmax=1;
- for (j=1;j<=t[i].nbrv;j++)
- {
- r=0;
- for (k=j;k<=t[i].nbrv;k++)
- {
- if(strcmp(t[i].v[j].dest,t[i].v[k].dest)==0)
- {
- r++;
- }
- }
- if (r>rmax)
- {
- rmax=r;
- posmax=j;
- }
- }
- printf ("La position la plus demandé est %s",t[i].v[posmax].dest);
- }
- break;
- case 6:
- system ("cls");
- if (n1==0)
- {
- printf ("Remplir d'abords le tableau ");
- break;
- }else
- {
- for (i=1;i<=12;i++)
- {
- t1[i]=0;
- }
- for (i=1;i<=n1;i++)
- {
- for (j=1;j<=t[i].nbrv;j++)
- {
- t1[t[i].v[j].d.mm]++;
- }
- }
- posmax=1;
- for (i=1;i<=12;i++)
- {
- if (t1[posmax]<t1[i])
- {
- posmax=i;
- }
- }
- printf ("Le mois le plus demandée de l'année est le mois %d",posmax);
- }
- break;
- }
- }while (n>=1 && n<=6);
- }
- /*t[1].ident=1111; t[2].ident=2222;
- strcpy(t[1].nom,"Momo"); strcpy(t[2].nom,"Yasmine");
- strcpy(t[1].pre,"ahla"); strcpy(t[2].pre,"test");
- t[1].nbrv=3; t[2].nbrv=2;
- strcpy( t[1].v[1].dest,"Toulouse"); strcpy(t[2].v[1].dest,"Lyon");
- strcpy( t[1].v[2].dest,"Marseille"); strcpy( t[2].v[2].dest,"Toulouse");
- strcpy( t[1].v[3].dest,"Marseille");
- t[1].v[1].d.jj=23; t[2].v[1].d.jj=23;
- t[1].v[1].d.mm=12; t[2].v[1].d.mm=5;
- t[1].v[1].d.aa=2020; t[2].v[1].d.aa=2021;
- t[1].v[2].d.jj=24; t[2].v[2].d.jj=24;
- t[1].v[2].d.mm=5; t[2].v[2].d.mm=5;
- t[1].v[2].d.aa=2020; t[2].v[2].d.aa=2020;
- t[1].v[3].d.jj=23;
- t[1].v[3].d.mm=12;
- t[1].v[3].d.aa=2021;
- t[2].v[3].d.jj=23;
- t[2].v[3].d.mm=12;
- t[2].v[3].d.aa=2021;*/
Add Comment
Please, Sign In to add comment