Advertisement
ProToTN

MenuC

Nov 2nd, 2016
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.24 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3.  
  4.  
  5. typedef struct Participant part;
  6. struct Participant{
  7.     char nomPart[20],prenomPart[20];
  8.     int numCarte,dej,din,hotel,typehotel,fact;
  9. };
  10.  
  11.  
  12. int calcFact(int a,int b,int c){
  13.     int x=0;
  14.     if (a==1) x=x+15;
  15.     if (b==1) x=x+35;
  16.     if (c==1) x=x+75;
  17.     if (c==2) x=x+100;
  18.     return x;
  19. }
  20.  
  21.  
  22.  part ajoutPart(int i){
  23.     part E;
  24.     printf("\n--Entree de donnes--\n");
  25.     printf("Tapez le numero de ta carte d'identitee: ");
  26.     scanf("%d",&E.numCarte);
  27.     printf("Nom: ");
  28.     scanf(" %s",E.nomPart);
  29.     printf("Prenom: ");
  30.     scanf(" %s",E.prenomPart);
  31.     do{
  32.         printf("Do you want to reserve for lunch? (0. No 1. Yes): ");
  33.         scanf("%d",&E.dej);
  34.     }while((E.dej!=0)&&(E.dej!=1));
  35.     do{
  36.         printf("Do you want to reserve for dinner? (0. No 1. Yes): ");
  37.         scanf("%d",&E.din);
  38.     }while((E.din!=0)&&(E.din!=1));
  39.     do{
  40.         printf("Do you want to reserve for a hotel room? (0. No 1. Yes): ");
  41.         scanf("%d",&E.hotel);
  42.     }while((E.hotel!=0)&&(E.hotel!=1));
  43.     if (E.hotel==1){
  44.         do{
  45.             printf("Quel hotel? (1. 4 stars 2. 5 stars): ");
  46.             scanf("%d",&E.typehotel);
  47.         }while((E.typehotel!=1)&&(E.typehotel!=2));
  48.     }
  49.     E.fact=calcFact(E.dej,E.din,E.typehotel);
  50.     return E;
  51. }
  52.  
  53. void affiche(part PTAB[50],int n,int x){
  54.     int i;
  55.     part E;
  56.     for(i=0;i<=n;i++){
  57.         E=PTAB[i];
  58.         if(x==0){
  59.             printf("\n--Participant num %d --\n",i+1);
  60.             printf("Num CIN: %d\n",E.numCarte);
  61.             printf("Nom: %s\n",E.nomPart);
  62.             printf("Prenom: %s\n",E.prenomPart);
  63.             printf("Dej: %d\n",E.dej);
  64.             printf("Din: %d\n",E.din);
  65.             printf("Hotel: %d\n",E.hotel);
  66.             if (E.hotel==1) printf("Type hotel: %d\n",E.typehotel);
  67.             getch();
  68.             printf("Facture: %d\n",E.fact);
  69.         }
  70.         else{
  71.             if(x==E.typehotel){
  72.                  printf("\n--Participant num %d --\n",i+1);
  73.                  printf("Num CIN: %d\n",E.numCarte);
  74.                  printf("Nom: %s\n",E.nomPart);
  75.                  printf("Prenom: %s\n",E.prenomPart);
  76.                  printf("Dej: %d\n",E.dej);
  77.                  printf("Din: %d\n",E.din);
  78.                  printf("Hotel: %d\n",E.hotel);
  79.                  if (E.hotel==1) printf("Type hotel: %d\n",E.typehotel);
  80.                  getch();
  81.             }
  82.         }
  83.     }
  84.     printf("\n--Heading back to the main menu--\n");
  85. }
  86.  
  87.  
  88. void affichePart(part PTAB[50],int n){
  89.     int C;
  90.     do{
  91.         printf("Afficher quoi exactement? (1. Tous les participants sans aucun critere, 2. Les participants qui ont choisi de reserver un hotel 4 etoiles, 3. Les participants qui ont choisi de rΓ©server un hotel 5 etoiles, 0. Retourner au menu principal): ");
  92.         scanf("%d",&C);
  93.         switch (C){
  94.         case 1:{
  95.             affiche(PTAB,n,0);
  96.             break;
  97.         }
  98.         case 2:{
  99.             affiche(PTAB,n,1);
  100.             break;
  101.         }
  102.         case 3:{
  103.             affiche(PTAB,n,2);
  104.             break;
  105.         }
  106.         }
  107.     }while(C!=0);
  108.     printf("\n--Heading back to the menu--\n");
  109.     getch();
  110. }
  111.  
  112.  
  113.  
  114. part suppPart(part PTAB[50],int n){
  115.     int CIN,i,j;
  116.     part E;
  117.     printf("\n--Suppression d'un participant--\n");
  118.     printf("CIN de participant a supprimier: ");
  119.     scanf("%d",&CIN);
  120.     for(i=0;i<=n;i++){
  121.         E=PTAB[i];
  122.         if (CIN==E.numCarte) j=i;
  123.     }
  124.     for(i=j;i<=n;i++){
  125.         PTAB[i]=PTAB[i+1];
  126.     }
  127.     return;
  128. }
  129.  
  130.  
  131.  
  132. void main(){
  133.     int Choix,i=-1;
  134.     part Particip[50];
  135.     do{
  136.         printf("Choix: (1. Ajouter un participant 2. Liste d'affichages possibles 3. Supprimer un participant 0. Exit): \n");
  137.         scanf("%d",&Choix);
  138.         switch (Choix){
  139.             case 1:{
  140.                 i++;
  141.                 Particip[i]=ajoutPart(i);
  142.                 break;
  143.             }
  144.             case 2:{
  145.                 affichePart(Particip,i);
  146.                 break;
  147.             }
  148.             case 3:{
  149.                 suppPart(Particip,i);
  150.                 i--;
  151.                 break;
  152.             }
  153.             default: {
  154.                 printf("Bye!");
  155.                 getch();
  156.             }
  157.         }
  158.     }while(Choix!=0);
  159. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement